update command, auto fill, folder_temp, .gitignore

This commit is contained in:
Joseph Le 2023-10-11 15:37:55 +11:00
parent 7490da1969
commit 7f892158e1
16 changed files with 659 additions and 210 deletions

View File

@ -1,33 +1,43 @@
const fs = require("fs");
const express = require("express");
const app = express();
const { exec } = require("child_process");
const nodeMailer = require("nodemailer");
const fs = require("fs");
const express = require("express");
const app = express();
const { exec } = require("child_process");
const nodeMailer = require("nodemailer");
app.use(express.json());
app.use(express.json());
app.post("/git/gitea-webhook", async(req, res) => {
const contentFile = await fs.readFileSync("./service/giteaService", "utf8");
const checkSendMail = contentFile.split("\n").filter((i)=>i.includes("SEND_EMAIL"))[0]?.split("=")[1].trim()
const emailAddress = contentFile.split("\n").filter((i)=>i.includes("EMAIL_ADDRESS"))[0]?.split("=")[1].trim()
app.post("/git/gitea-webhook", async (req, res) => {
const contentFile = await fs.readFileSync(
"./service_temp/giteaService.conf",
"utf8"
);
const checkSendMail = contentFile
.split("\n")
.filter((i) => i.includes("SEND_EMAIL"))[0]
?.split("=")[1]
.trim();
const emailAddress = contentFile
.split("\n")
.filter((i) => i.includes("EMAIL_ADDRESS"))[0]
?.split("=")[1]
.trim();
const giteaEvent = req.headers["x-gitea-event"];
console.log("New event: "+giteaEvent)
const body = req.body
console.log("New event: " + giteaEvent);
const body = req.body;
//console.log(body)
res.status(200).send({mess: "The event has been received!", data:req.body})
res
.status(200)
.send({ mess: "The event has been received!", data: req.body });
exec(
"./service/giteaHook.sh",
(error, stdout, stderr) => {
exec("./service_temp/giteaHook.sh", (error, stdout, stderr) => {
if (error) {
console.log(`Error executing command: ${error}`);
// res.status(500).send("PULL ERROR")
// res.status(500).send("PULL ERROR")
}
console.log(stdout)
console.log(stdout);
if(checkSendMail==="True"){
if (checkSendMail === "True") {
const transporter = nodeMailer.createTransport({
pool: true,
host: "mail.ipsupply.com.au",
port: 465,
@ -41,19 +51,31 @@
const options = {
from: "admin@apactech.io",
to: emailAddress,
subject: "New Git envent: "+giteaEvent ,
html: "<h1>*** "+giteaEvent+" event ***</h1><h4>Committer: "+req.body.commits[0]?.committer.name+"</h4><h4>Message: "+req.body.commits[0]?.message+"</h4><h4>Branch: "+req.body.ref+"</h4><a href='"+req.body.commits[0]?.url+"'>Link: "+req.body.commits[0]?.url+"</a><h4>Process output:</h4><textarea style='wordWrap:break-word; display: block; width:100%; height:70vh;border:solid 2px orange'>" +
subject: "New Git envent: " + giteaEvent,
html:
"<h1>*** " +
giteaEvent +
" event ***</h1><h4>Committer: " +
req.body.commits[0]?.committer.name +
"</h4><h4>Message: " +
req.body.commits[0]?.message +
"</h4><h4>Branch: " +
req.body.ref +
"</h4><a href='" +
req.body.commits[0]?.url +
"'>Link: " +
req.body.commits[0]?.url +
"</a><h4>Process output:</h4><textarea style='wordWrap:break-word; display: block; width:100%; height:70vh;border:solid 2px orange'>" +
stdout +
"</textarea>"
"</textarea>",
};
return transporter.sendMail(options);
}
});
});
});
const PORT = 5000;
app.listen(PORT, () => {
const PORT = 5000;
app.listen(PORT, () => {
console.log("Server is running on port ", PORT);
});
});

View File

@ -1,53 +1,46 @@
#!/bin/bash
if [ -d "/etc/systemd/system" ]; then
echo "|---------------------------|"
echo -e "|***** \e[33mINSTALL SERVICE\e[0m *****|"
echo "|---------------------------|"
sleep 2 &&
pwd_install=$(pwd) &&
escaped_pwd_install=$(printf '%s\n' "$pwd_install" | sed -e 's/[\/&]/\\&/g') &&
echo ""
echo "|------------------------------|"
echo -e "|***** \e[33mUPDATE ENVIRONMENT\e[0m *****|"
echo "|------------------------------|"
echo ""
sleep 2 &&
cp -rf service service_temp &&
sudo sed -i "s#ExecStart=.*#ExecStart=$escaped_pwd_install/service/giteaService.sh#" $pwd_install/service/giteaHook.service &&
sleep 2 &&
sudo sed -i "s#ExecStart=.*#ExecStart=$escaped_pwd_install/service_temp/giteaService.sh#" $pwd_install/service_temp/giteaHook.service &&
echo -e "* \e[32mExecStart\e[0m *" &&
sleep 1 &&
sudo sed -i "s#WorkingDirectory=.*#WorkingDirectory=$escaped_pwd_install/service#" $pwd_install/service/giteaHook.service &&
sudo sed -i "s#WorkingDirectory=.*#WorkingDirectory=$escaped_pwd_install/service_temp#" $pwd_install/service_temp/giteaHook.service &&
echo -e "* \e[32mWorkingDirectory\e[0m *" &&
sleep 1 &&
sudo sed -i "s#EnvironmentFile=.*#EnvironmentFile=$escaped_pwd_install/service/giteaService#" $pwd_install/service/giteaHook.service &&
sudo sed -i "s#EnvironmentFile=.*#EnvironmentFile=$escaped_pwd_install/service_temp/giteaService.conf#" $pwd_install/service_temp/giteaHook.service &&
echo -e "* \e[32mEnvironmentFile\e[0m *" &&
sleep 1 &&
sudo sed -i "s#HOOK_PATH=.*#HOOK_PATH=$escaped_pwd_install#" $pwd_install/service/giteaService &&
sudo sed -i "s#HOOK_PATH=.*#HOOK_PATH=$escaped_pwd_install#" $pwd_install/service_temp/giteaService.conf &&
echo -e "* \e[32mHOOK_PATH\e[0m *" &&
sleep 1 &&
sudo sed -i "s#source .*#source $escaped_pwd_install/service/giteaService#" $pwd_install/service/giteaHook.sh &&
sudo sed -i "s#source .*#source $escaped_pwd_install/service_temp/giteaService.conf#" $pwd_install/service_temp/giteaHook.sh &&
echo -e "* \e[32mEXEC_FILE\e[0m *" &&
echo ""
sleep 1 &&
systemctl stop giteaHook.service
input_file="$pwd_install/service/giteaService" &&
input_file="$pwd_install/service_temp/giteaService.conf" &&
#Doc va xu ly tung dong
while IFS= read -r line; do
# Kiem tra xem d?ng có ch?a "_PATH" không
if [[ $line == *"_PATH"* ]]; then
# Kiem tra xem dong c<> chua "_PATH" kh<6B>ng
if [[ $line == *"_PATH"* && $line != "#"* && $line != *"_COMMAND"* ]]; then
# Lay string sau dau "="
path="${line#*=}"
# Loai bo khoang trong trong duong dan
@ -57,51 +50,39 @@ if [ -d "/etc/systemd/system" ]; then
echo ""
echo -e "\e[41mError: $path not exists.\e[0m"
echo ""
exit 1 # D?ng chýõng tr?nh
exit 1 # Dung chuong trinh
else
echo -e "\e[32mOK: $path exists\e[0m"
sleep 1
fi
fi
done < "$input_file" &&
cp $pwd_install/service/giteaHook.service /etc/systemd/system/giteaHook.service &&
done <"$input_file" &&
cp $pwd_install/service_temp/giteaHook.service /etc/systemd/system/giteaHook.service &&
echo "" &&
echo -e "* \e[32mCopy service file\e[0m *" &&
systemctl daemon-reload &&
echo "" &&
echo "|----------------------|" &&
echo -e "|*** \e[33mENABLE SERVICE\e[0m ***|" &&
echo "|----------------------|" &&
echo "" &&
systemctl enable giteaHook &&
sleep 2 &&
echo "|---------------------|" &&
echo -e "|*** \e[33mSTART SERVICE\e[0m ***|" &&
echo "|---------------------|" &&
echo "" &&
systemctl start giteaHook &&
sleep 2 &&
echo "|------------|" &&
echo -e "|*** \e[33mDONE\e[0m ***|" &&
echo "|------------|" &&
echo "" &&
sleep 1 &&
echo "|--------------|" &&
echo -e "|** \e[33mGOODLUCK\e[0m **|" &&
echo "|--------------|" &&
echo "" &&
journalctl -u giteaHook -f
else

2
node_modules/.package-lock.json generated vendored
View File

@ -1,7 +1,7 @@
{
"name": "gitea_cicd",
"version": "1.0.0",
"lockfileVersion": 2,
"lockfileVersion": 3,
"requires": true,
"packages": {
"node_modules/abbrev": {

View File

@ -3,13 +3,11 @@ Description=Gitea Hook Service
After=network.target
[Service]
ExecStart=/home/joseph/gitea_CICD/service/giteaService.sh
ExecStart=/home/gitea_CICD/service/giteaService.sh
Restart=always
WorkingDirectory=/home/joseph/gitea_CICD/service
User=root
Group=root
WorkingDirectory=/home/gitea_CICD/service
Restart=on-failure
EnvironmentFile=/home/joseph/gitea_CICD/service/giteaService
EnvironmentFile=/home/gitea_CICD/service/giteaService.conf
[Install]
WantedBy=multi-user.target

View File

@ -1,7 +1,7 @@
#!/bin/bash
#File chua bien moi truong
source /home/joseph/gitea_CICD/service/giteaService
source /home/gitea_CICD/service/giteaService.conf
#URL project
project=$PROJECT_PATH
@ -10,10 +10,7 @@ project=$PROJECT_PATH
fe_path=$(basename "$FE_PROJECT_PATH")
#URL folder BE
be_path=$BE_PROJECT_PATH
#URL other folder
#other="..."
be_path=$BE_PROCESS_PATH
#Username git
username=$GIT_USERNAME
@ -26,6 +23,21 @@ branch=$GIT_BRANCH
cd $project
function run_commands() {
local name_path_folder="$1"
local command_name=$(echo "${name_path_folder}_COMMAND")
#echo $command_name &&
# Tìm command line
command_line=$(grep "$command_name" "$input_file") &&
command="${command_line#*=}" &&
echo "" &&
echo "$command" &&
echo "" &&
cd $path &&
echo -e $(eval "$command")
echo ""
}
result=$(expect -c "
set timeout 10
spawn git pull origin $GIT_BRANCH
@ -44,10 +56,8 @@ result=$(expect -c "
catch wait result
exit [lindex \$result 3]
") &&
echo "$result" &&
if [[ $result == *$fe_path* ]]; then
echo "$result" &&
if [[ $result == *$fe_path* ]]; then
echo "|--------------------------------------------------------|"
echo "|***** THERE ARE CHANGES INSIDE FOLDER $fe_path *****|"
echo "|--------------------------------------------------------|"
@ -65,16 +75,36 @@ if [[ $result == *$fe_path* ]]; then
npm run build &&
cp -rf $project/$fe_path/build/* $FE_ROOT_FOLDER_PATH
fi
fi
echo "|----------------------|"
echo "|*** UPDATE LIBRARY ***|"
echo "|----------------------|"
cd $be_path &&
npm install
sleep 10
input_file="$HOOK_PATH/service_temp/giteaService.conf" &&
# Doc va xu ly tung dong
while IFS= read -r line; do
# Kiem tra xem dong có chua "_PATH" không
if [[ $line == *"_PROCESS_PATH"* && $line != "#"* && $line != *"_COMMAND"* ]]; then
IFS="=" read -r variable value <<<"$line"
variable=$(echo "$variable" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
path=$(echo "$value" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
# Loai bo khoang trong trong duong dan
path=$(echo "$path" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
# Kiem tra duong dan ton tai
if [ ! -e "$path" ]; then
echo ""
echo -e "\e[41mError: $path not exists.\e[0m"
echo ""
exit 1 # Dung chuong trinh
else
echo -e "\e[32mProcessing in\e[0m: $path"
run_commands "$variable"
fi
fi
done <"$input_file" &&
echo "|------------|"
echo "|*** DONE ***|"
echo "|------------|"

View File

@ -1,27 +0,0 @@
#Luu y: (*) La nhung bien moi truong can khai bao
#Duong dan thu muc, index.js file de chay dich vu giteaHook (cac bien do he thong tu dong cap nhat)
HOOK_PATH=/home/joseph/gitea_CICD
#Tai khoan git (*)
GIT_USERNAME=joseph.le@apactech.io
GIT_PASSWORD=Maypjtkh0ng
GIT_BRANCH=dev
#Email
EMAIL_ADDRESS=joseph@apactech.io
#Send mail: True or False
SEND_EMAIL=False
#Duong dan goc cua project (*)
PROJECT_PATH=/home/joseph/Demo_Git_Webhook
#Duong dan folder FE (*)
FE_PROJECT_PATH=/home/joseph/Demo_Git_Webhook/website/
#Duong dan folder BE (*)
BE_PROJECT_PATH=/home/joseph/Demo_Git_Webhook/server
#Duong dan folder public FE (*)
FE_ROOT_FOLDER_PATH=/var/www/html

42
service/giteaService.conf Executable file
View File

@ -0,0 +1,42 @@
# Luu y: (*) La nhung bien moi truong can khai bao
# Duong dan thu muc, index.js file de chay dich vu giteaHook (cac bien do he thong tu dong cap nhat)
HOOK_PATH=/home/gitea_CICD
# Tai khoan git (*)
GIT_USERNAME=joseph.le@apactech.io
GIT_PASSWORD=Maypjtkh0ng
GIT_BRANCH=main
# Email (*)
EMAIL_ADDRESS=joseph@apactech.io
# Send mail: True or False (*)
SEND_EMAIL=True
# Duong dan goc cua project (*)
PROJECT_PATH=/home/Log_service
# Duong dan folder FE (*)
FE_PROJECT_PATH=/home/Log_service/manage-view
# Duong dan folder public FE (*)
FE_ROOT_FOLDER_PATH=/var/www/html
#
# Cac duong dan khac can thuc thi khi pull. Co the them nhieu duong dan voi cu phap khai bao:
#
# Duong dan: <name>_PROCESS_PATH=</your/path>
# Cau lenh thuc thi: <name>_PROCESS_PATH_COMMAND=<command1> && <command2> ...
#
# Duong dan folder BE (*)
BE_PROCESS_PATH=/home/Log_service
BE_PROCESS_PATH_COMMAND=npm install && echo "\n" && echo "BACK_END"
# Duong dan folder Socket (*)
SOCKET_PROCESS_PATH=/home/Log_service
SOCKET_PROCESS_PATH_COMMAND=npm install && echo "\n" && echo "SOCKET"
# Duong dan folder khac (*)
KHAC_PROCESS_PATH=/home/Log_service
KHAC_PROCESS_PATH_COMMAND=npm install && echo "\n" && echo "KHAC"

1
service_temp/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.

View File

@ -0,0 +1,13 @@
[Unit]
Description=Gitea Hook Service
After=network.target
[Service]
ExecStart=/home/gitea_CICD/service_temp/giteaService.sh
Restart=always
WorkingDirectory=/home/gitea_CICD/service_temp
Restart=on-failure
EnvironmentFile=/home/gitea_CICD/service_temp/giteaService.conf
[Install]
WantedBy=multi-user.target

110
service_temp/giteaHook.sh Executable file
View File

@ -0,0 +1,110 @@
#!/bin/bash
#File chua bien moi truong
source /home/gitea_CICD/service_temp/giteaService.conf
#URL project
project=$PROJECT_PATH
#URL folder FE
fe_path=$(basename "$FE_PROJECT_PATH")
#URL folder BE
be_path=$BE_PROCESS_PATH
#Username git
username=$GIT_USERNAME
#Password git
password=$GIT_PASSWORD
#Git branch
branch=$GIT_BRANCH
cd $project
function run_commands() {
local name_path_folder="$1"
local command_name=$(echo "${name_path_folder}_COMMAND")
#echo $command_name &&
# Tìm command line
command_line=$(grep "$command_name" "$input_file") &&
command="${command_line#*=}" &&
echo "" &&
echo "$command" &&
echo "" &&
cd $path &&
echo -e $(eval "$command")
echo ""
}
result=$(expect -c "
set timeout 10
spawn git pull origin $GIT_BRANCH
expect {
\"Username for *\" {
send \"$username\r\"
exp_continue
}
\"Password for *\" {
sleep 2
send \"$password\r\r\"
exp_continue
}
eof
}
catch wait result
exit [lindex \$result 3]
") &&
echo "$result" &&
if [[ $result == *$fe_path* ]]; then
echo "|--------------------------------------------------------|"
echo "|***** THERE ARE CHANGES INSIDE FOLDER $fe_path *****|"
echo "|--------------------------------------------------------|"
echo "|---------------|"
echo "|*** INSTALL ***|"
echo "|---------------|"
cd $project/$fe_path &&
npm install
echo "|-------------|"
echo "|*** BUILD ***|"
echo "|-------------|"
npm run build &&
cp -rf $project/$fe_path/build/* $FE_ROOT_FOLDER_PATH
fi
echo "|----------------------|"
echo "|*** UPDATE LIBRARY ***|"
echo "|----------------------|"
input_file="$HOOK_PATH/service_temp/giteaService.conf" &&
# Doc va xu ly tung dong
while IFS= read -r line; do
# Kiem tra xem dong có chua "_PATH" không
if [[ $line == *"_PROCESS_PATH"* && $line != "#"* && $line != *"_COMMAND"* ]]; then
IFS="=" read -r variable value <<<"$line"
variable=$(echo "$variable" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
path=$(echo "$value" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
# Loai bo khoang trong trong duong dan
path=$(echo "$path" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
# Kiem tra duong dan ton tai
if [ ! -e "$path" ]; then
echo ""
echo -e "\e[41mError: $path not exists.\e[0m"
echo ""
exit 1 # Dung chuong trinh
else
echo -e "\e[32mProcessing in\e[0m: $path"
run_commands "$variable"
fi
fi
done <"$input_file" &&
echo "|------------|"
echo "|*** DONE ***|"
echo "|------------|"

42
service_temp/giteaService.conf Executable file
View File

@ -0,0 +1,42 @@
# Luu y: (*) La nhung bien moi truong can khai bao
# Duong dan thu muc, index.js file de chay dich vu giteaHook (cac bien do he thong tu dong cap nhat)
HOOK_PATH=/home/gitea_CICD
# Tai khoan git (*)
GIT_USERNAME=joseph.le@apactech.io
GIT_PASSWORD=Maypjtkh0ng
GIT_BRANCH=main
# Email (*)
EMAIL_ADDRESS=joseph@apactech.io
# Send mail: True or False (*)
SEND_EMAIL=True
# Duong dan goc cua project (*)
PROJECT_PATH=/home/Log_service
# Duong dan folder FE (*)
FE_PROJECT_PATH=/home/Log_service/manage-view
# Duong dan folder public FE (*)
FE_ROOT_FOLDER_PATH=/var/www/html
#
# Cac duong dan khac can thuc thi khi pull. Co the them nhieu duong dan voi cu phap khai bao:
#
# Duong dan: <name>_PROCESS_PATH=</your/path>
# Cau lenh thuc thi: <name>_PROCESS_PATH_COMMAND=<command1> && <command2> ...
#
# Duong dan folder BE (*)
BE_PROCESS_PATH=/home/Log_service
BE_PROCESS_PATH_COMMAND=npm install && echo "\n" && echo "BACK_END"
# Duong dan folder Socket (*)
SOCKET_PROCESS_PATH=/home/Log_service
SOCKET_PROCESS_PATH_COMMAND=npm install && echo "\n" && echo "SOCKET"
# Duong dan folder khac (*)
KHAC_PROCESS_PATH=/home/Log_service
KHAC_PROCESS_PATH_COMMAND=npm install && echo "\n" && echo "KHAC"

36
service_temp/giteaService.sh Executable file
View File

@ -0,0 +1,36 @@
#!/bin/bash
# Đường dẫn tới tệp index.js
indexjs_path=$HOOK_PATH/index.js
project_path=$HOOK_PATH
# Kiểm tra xem Node.js đã cài đặt chưa
if ! command -v node &> /dev/null; then
echo -e "\e[31mNode.js is not installed.\e[0m"
echo -e "\e[32mInstall Node.js...\e[0m"
curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash - &&
sudo apt-get install nodejs -y &&
node -v
else
echo -e "\e[32mNodejs is installed!\e[0m" &&
node -v
fi
# Kiểm tra xem npm đã cài đặt chưa
if ! command -v npm &> /dev/null; then
echo -e "\e[31mnpm is not installed. Install npm...\e[0m"
sudo apt-get install npm -y
else
echo -e "\e[32mnpm is installed!\e[0m" &&
npm -v
fi
# Kiểm tra xem tệp index.js có tồn tại không
if [ -f "$indexjs_path" ]; then
echo "Run file $indexjs_path..."
cd "$project_path" &&
npm install &&
node "$indexjs_path"
else
echo -e "\e[31mFile $indexjs_path not exists\e[0m"
fi

View File

@ -0,0 +1,13 @@
[Unit]
Description=Gitea Hook Service
After=network.target
[Service]
ExecStart=/home/gitea_CICD/service/giteaService.sh
Restart=always
WorkingDirectory=/home/gitea_CICD/service
Restart=on-failure
EnvironmentFile=/home/gitea_CICD/service/giteaService.conf
[Install]
WantedBy=multi-user.target

110
service_temp/service/giteaHook.sh Executable file
View File

@ -0,0 +1,110 @@
#!/bin/bash
#File chua bien moi truong
source /home/gitea_CICD/service/giteaService.conf
#URL project
project=$PROJECT_PATH
#URL folder FE
fe_path=$(basename "$FE_PROJECT_PATH")
#URL folder BE
be_path=$BE_PROCESS_PATH
#Username git
username=$GIT_USERNAME
#Password git
password=$GIT_PASSWORD
#Git branch
branch=$GIT_BRANCH
cd $project
function run_commands() {
local name_path_folder="$1"
local command_name=$(echo "${name_path_folder}_COMMAND")
#echo $command_name &&
# Tìm command line
command_line=$(grep "$command_name" "$input_file") &&
command="${command_line#*=}" &&
echo "" &&
echo "$command" &&
echo "" &&
cd $path &&
echo -e $(eval "$command")
echo ""
}
result=$(expect -c "
set timeout 10
spawn git pull origin $GIT_BRANCH
expect {
\"Username for *\" {
send \"$username\r\"
exp_continue
}
\"Password for *\" {
sleep 2
send \"$password\r\r\"
exp_continue
}
eof
}
catch wait result
exit [lindex \$result 3]
") &&
echo "$result" &&
if [[ $result == *$fe_path* ]]; then
echo "|--------------------------------------------------------|"
echo "|***** THERE ARE CHANGES INSIDE FOLDER $fe_path *****|"
echo "|--------------------------------------------------------|"
echo "|---------------|"
echo "|*** INSTALL ***|"
echo "|---------------|"
cd $project/$fe_path &&
npm install
echo "|-------------|"
echo "|*** BUILD ***|"
echo "|-------------|"
npm run build &&
cp -rf $project/$fe_path/build/* $FE_ROOT_FOLDER_PATH
fi
echo "|----------------------|"
echo "|*** UPDATE LIBRARY ***|"
echo "|----------------------|"
input_file="$HOOK_PATH/service_temp/giteaService.conf" &&
# Doc va xu ly tung dong
while IFS= read -r line; do
# Kiem tra xem dong có chua "_PATH" không
if [[ $line == *"_PROCESS_PATH"* && $line != "#"* && $line != *"_COMMAND"* ]]; then
IFS="=" read -r variable value <<<"$line"
variable=$(echo "$variable" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
path=$(echo "$value" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
# Loai bo khoang trong trong duong dan
path=$(echo "$path" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
# Kiem tra duong dan ton tai
if [ ! -e "$path" ]; then
echo ""
echo -e "\e[41mError: $path not exists.\e[0m"
echo ""
exit 1 # Dung chuong trinh
else
echo -e "\e[32mProcessing in\e[0m: $path"
run_commands "$variable"
fi
fi
done <"$input_file" &&
echo "|------------|"
echo "|*** DONE ***|"
echo "|------------|"

View File

@ -0,0 +1,42 @@
# Luu y: (*) La nhung bien moi truong can khai bao
# Duong dan thu muc, index.js file de chay dich vu giteaHook (cac bien do he thong tu dong cap nhat)
HOOK_PATH=/home/gitea_CICD
# Tai khoan git (*)
GIT_USERNAME=joseph.le@apactech.io
GIT_PASSWORD=Maypjtkh0ng
GIT_BRANCH=main
# Email (*)
EMAIL_ADDRESS=joseph@apactech.io
# Send mail: True or False (*)
SEND_EMAIL=True
# Duong dan goc cua project (*)
PROJECT_PATH=/home/Log_service
# Duong dan folder FE (*)
FE_PROJECT_PATH=/home/Log_service/manage-view
# Duong dan folder public FE (*)
FE_ROOT_FOLDER_PATH=/var/www/html
#
# Cac duong dan khac can thuc thi khi pull. Co the them nhieu duong dan voi cu phap khai bao:
#
# Duong dan: <name>_PROCESS_PATH=</your/path>
# Cau lenh thuc thi: <name>_PROCESS_PATH_COMMAND=<command1> && <command2> ...
#
# Duong dan folder BE (*)
BE_PROCESS_PATH=/home/Log_service
BE_PROCESS_PATH_COMMAND=npm install && echo "\n" && echo "BACK_END"
# Duong dan folder Socket (*)
SOCKET_PROCESS_PATH=/home/Log_service
SOCKET_PROCESS_PATH_COMMAND=npm install && echo "\n" && echo "SOCKET"
# Duong dan folder khac (*)
KHAC_PROCESS_PATH=/home/Log_service
KHAC_PROCESS_PATH_COMMAND=npm install && echo "\n" && echo "KHAC"

View File

@ -0,0 +1,36 @@
#!/bin/bash
# Đường dẫn tới tệp index.js
indexjs_path=$HOOK_PATH/index.js
project_path=$HOOK_PATH
# Kiểm tra xem Node.js đã cài đặt chưa
if ! command -v node &> /dev/null; then
echo -e "\e[31mNode.js is not installed.\e[0m"
echo -e "\e[32mInstall Node.js...\e[0m"
curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash - &&
sudo apt-get install nodejs -y &&
node -v
else
echo -e "\e[32mNodejs is installed!\e[0m" &&
node -v
fi
# Kiểm tra xem npm đã cài đặt chưa
if ! command -v npm &> /dev/null; then
echo -e "\e[31mnpm is not installed. Install npm...\e[0m"
sudo apt-get install npm -y
else
echo -e "\e[32mnpm is installed!\e[0m" &&
npm -v
fi
# Kiểm tra xem tệp index.js có tồn tại không
if [ -f "$indexjs_path" ]; then
echo "Run file $indexjs_path..."
cd "$project_path" &&
npm install &&
node "$indexjs_path"
else
echo -e "\e[31mFile $indexjs_path not exists\e[0m"
fi