update .gitignore

This commit is contained in:
Joseph Le 2023-10-12 14:34:50 +11:00
parent 7f892158e1
commit 556490b0f4
12 changed files with 11 additions and 413 deletions

1
.gitignore vendored
View File

@ -0,0 +1 @@
service_run

View File

@ -8,7 +8,7 @@ app.use(express.json());
app.post("/git/gitea-webhook", async (req, res) => {
const contentFile = await fs.readFileSync(
"./service_temp/giteaService.conf",
"./service_run/giteaService.conf",
"utf8"
);
const checkSendMail = contentFile
@ -29,7 +29,7 @@ app.post("/git/gitea-webhook", async (req, res) => {
.status(200)
.send({ mess: "The event has been received!", data: req.body });
exec("./service_temp/giteaHook.sh", (error, stdout, stderr) => {
exec("./service_run/giteaHook.sh", (error, stdout, stderr) => {
if (error) {
console.log(`Error executing command: ${error}`);
// res.status(500).send("PULL ERROR")

View File

@ -14,28 +14,28 @@ if [ -d "/etc/systemd/system" ]; then
echo "|------------------------------|"
echo ""
cp -rf service service_temp &&
cp -rf service/* service_run &&
sleep 2 &&
sudo sed -i "s#ExecStart=.*#ExecStart=$escaped_pwd_install/service_temp/giteaService.sh#" $pwd_install/service_temp/giteaHook.service &&
sudo sed -i "s#ExecStart=.*#ExecStart=$escaped_pwd_install/service_run/giteaService.sh#" $pwd_install/service_run/giteaHook.service &&
echo -e "* \e[32mExecStart\e[0m *" &&
sleep 1 &&
sudo sed -i "s#WorkingDirectory=.*#WorkingDirectory=$escaped_pwd_install/service_temp#" $pwd_install/service_temp/giteaHook.service &&
sudo sed -i "s#WorkingDirectory=.*#WorkingDirectory=$escaped_pwd_install/service_run#" $pwd_install/service_run/giteaHook.service &&
echo -e "* \e[32mWorkingDirectory\e[0m *" &&
sleep 1 &&
sudo sed -i "s#EnvironmentFile=.*#EnvironmentFile=$escaped_pwd_install/service_temp/giteaService.conf#" $pwd_install/service_temp/giteaHook.service &&
sudo sed -i "s#EnvironmentFile=.*#EnvironmentFile=$escaped_pwd_install/service_run/giteaService.conf#" $pwd_install/service_run/giteaHook.service &&
echo -e "* \e[32mEnvironmentFile\e[0m *" &&
sleep 1 &&
sudo sed -i "s#HOOK_PATH=.*#HOOK_PATH=$escaped_pwd_install#" $pwd_install/service_temp/giteaService.conf &&
sudo sed -i "s#HOOK_PATH=.*#HOOK_PATH=$escaped_pwd_install#" $pwd_install/service_run/giteaService.conf &&
echo -e "* \e[32mHOOK_PATH\e[0m *" &&
sleep 1 &&
sudo sed -i "s#source .*#source $escaped_pwd_install/service_temp/giteaService.conf#" $pwd_install/service_temp/giteaHook.sh &&
sudo sed -i "s#source .*#source $escaped_pwd_install/service_run/giteaService.conf#" $pwd_install/service_run/giteaHook.sh &&
echo -e "* \e[32mEXEC_FILE\e[0m *" &&
echo ""
sleep 1 &&
systemctl stop giteaHook.service
input_file="$pwd_install/service_temp/giteaService.conf" &&
input_file="$pwd_install/service_run/giteaService.conf" &&
#Doc va xu ly tung dong
while IFS= read -r line; do
@ -57,7 +57,7 @@ if [ -d "/etc/systemd/system" ]; then
fi
fi
done <"$input_file" &&
cp $pwd_install/service_temp/giteaHook.service /etc/systemd/system/giteaHook.service &&
cp $pwd_install/service_run/giteaHook.service /etc/systemd/system/giteaHook.service &&
echo "" &&
echo -e "* \e[32mCopy service file\e[0m *" &&
systemctl daemon-reload &&

View File

@ -1 +0,0 @@
.

View File

@ -1,13 +0,0 @@
[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

View File

@ -1,110 +0,0 @@
#!/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 "|------------|"

View File

@ -1,42 +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/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

@ -1,36 +0,0 @@
#!/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

@ -1,13 +0,0 @@
[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

View File

@ -1,110 +0,0 @@
#!/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

@ -1,42 +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/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

@ -1,36 +0,0 @@
#!/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