forked from joseph/gitea_CICD
giteaHook service
This commit is contained in:
parent
9d2f4f33a0
commit
bc9d14cbe8
|
|
@ -1,4 +1,9 @@
|
||||||
FROM node:16.3.0-alpine
|
FROM node:16.3.0-alpine
|
||||||
RUN apk update
|
RUN apk update
|
||||||
|
RUN apk add --no-cache --upgrade bash
|
||||||
|
#RUN addgroup -S admin && adduser -S admin -G admin
|
||||||
WORKDIR /data
|
WORKDIR /data
|
||||||
|
#RUN chown -R admin:admin /data
|
||||||
|
#RUN chmod 755 /data
|
||||||
|
#USER admin
|
||||||
CMD npm install; npm run start
|
CMD npm install; npm run start
|
||||||
|
|
@ -7,4 +7,4 @@ services:
|
||||||
- ".:/data"
|
- ".:/data"
|
||||||
tty: true
|
tty: true
|
||||||
ports:
|
ports:
|
||||||
- '7777:8000'
|
- '8000:8001'
|
||||||
|
|
|
||||||
22
index.js
22
index.js
|
|
@ -3,17 +3,17 @@ const app = express();
|
||||||
const { exec } = require("child_process");
|
const { exec } = require("child_process");
|
||||||
|
|
||||||
app.post("/git/gitea-webhook", (req, res) => {
|
app.post("/git/gitea-webhook", (req, res) => {
|
||||||
// exec(
|
exec(
|
||||||
// "/home/giteaHook/giteaHook.sh",
|
"./service/giteaHook.sh",
|
||||||
// (error, stdout, stderr) => {
|
(error, stdout, stderr) => {
|
||||||
// if (error) {
|
if (error) {
|
||||||
// console.log(`Error executing command: ${error}`);
|
console.log(`Error executing command: ${error}`);
|
||||||
// res.status(500).send("PULL ERROR")
|
res.status(500).send("PULL ERROR")
|
||||||
// }
|
}
|
||||||
// res.status(200).send({mess: "PULL SUCCESS!", data: stdout})
|
res.status(200).send({mess: "PULL SUCCESS!", data: stdout})
|
||||||
// console.log(`Command output:\n${stdout}`);
|
console.log(`Command output:\n${stdout}`);
|
||||||
// }
|
}
|
||||||
// );
|
);
|
||||||
console.log("PULL2 EE333!!");
|
console.log("PULL2 EE333!!");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
"start": "nodemon index.js"
|
"start": "node index.js"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
[Unit]
|
||||||
|
Description=Gitea Hook Service
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStart=/home/gitea_CICD/service/giteaService.sh
|
||||||
|
Restart=always
|
||||||
|
WorkingDirectory=/home/gitea_CICD/service
|
||||||
|
User=root
|
||||||
|
Group=root
|
||||||
|
EnvironmentFile=/home/gitea_CICD/service/giteaService
|
||||||
|
|
@ -1,10 +1,13 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
#File chua bien moi truong
|
||||||
|
source /home/gitea_CICD/service/giteaService
|
||||||
|
|
||||||
#URL project
|
#URL project
|
||||||
project="/home/Log_service"
|
project=$PROJECT_PATH
|
||||||
|
|
||||||
#URL folder FE
|
#URL folder FE
|
||||||
fe_path="manage-view/"
|
fe_path=$FE_PROJECT_PATH
|
||||||
|
|
||||||
#URL folder BE
|
#URL folder BE
|
||||||
#be_path="netmiko_Api/"
|
#be_path="netmiko_Api/"
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
#Duong dan thu muc, index.js file de chay dich vu giteaHook
|
||||||
|
|
||||||
|
INDEXJS_HOOK_PATH=/home/gitea_CICD/index.js
|
||||||
|
HOOK_PATH=/home/gitea_CICD
|
||||||
|
|
||||||
|
#Duong dan cac thu muc trong project chinh
|
||||||
|
#Co the khai bao nhieu bien hon de cau hinh giteaHook.sh
|
||||||
|
|
||||||
|
PROJECT_PATH=/home/Log_service
|
||||||
|
FE_PROJECT_PATH=manage-view/
|
||||||
|
BE_PROJECT_PATH=/home/Log_service
|
||||||
|
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Đường dẫn tới tệp index.js
|
||||||
|
indexjs_path=$INDEXJS_HOOK_PATH
|
||||||
|
project_path=$HOOK_PATH
|
||||||
|
|
||||||
|
# Kiểm tra xem Node.js đã cài đặt chưa
|
||||||
|
if ! command -v node &> /dev/null; then
|
||||||
|
echo "Node.js chưa được cài đặt. Đang cài đặt Node.js..."
|
||||||
|
curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
|
||||||
|
sudo apt-get install -y nodejs
|
||||||
|
else
|
||||||
|
echo "Nodejs da duoc cai dat!" &&
|
||||||
|
node -v
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Kiểm tra xem npm đã cài đặt chưa
|
||||||
|
if ! command -v npm &> /dev/null; then
|
||||||
|
echo "npm chưa được cài đặt. Đang cài đặt npm..."
|
||||||
|
sudo apt-get install -y npm
|
||||||
|
else
|
||||||
|
echo "npm da duoc cai dat!" &&
|
||||||
|
npm -v
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Kiểm tra xem tệp index.js có tồn tại không
|
||||||
|
if [ -f "$indexjs_path" ]; then
|
||||||
|
echo "Chạy tệp $indexjs_path..."
|
||||||
|
cd "$project_path" &&
|
||||||
|
node "$indexjs_path"
|
||||||
|
else
|
||||||
|
echo "Tệp $indexjs_path không tồn tại."
|
||||||
|
fi
|
||||||
Loading…
Reference in New Issue