update index.js, env

This commit is contained in:
Joseph Le 2023-10-13 13:21:50 +11:00
parent 148c52c103
commit fa09ae76bb
4 changed files with 15 additions and 27 deletions

View File

@ -5,7 +5,7 @@
### 1) Clone project to your server ### 1) Clone project to your server
```sh ```sh
git clone https://<USERNAME>:<PASSWORD>gitea.nswteam.net/joseph/gitea_CICD.git git clone https://<USERNAME>:<PASSWORD>@gitea.nswteam.net/joseph/gitea_CICD.git
``` ```
- Get username: - Get username:
<div><img src="https://i.ibb.co/pLR2BjH/image.png" alt="getUsername" width="300"></div> <div><img src="https://i.ibb.co/pLR2BjH/image.png" alt="getUsername" width="300"></div>

View File

@ -3,14 +3,19 @@ const express = require("express");
const app = express(); const app = express();
const { exec } = require("child_process"); const { exec } = require("child_process");
const nodeMailer = require("nodemailer"); const nodeMailer = require("nodemailer");
const contentFile = fs.readFileSync(
"./service_run/giteaService.conf",
"utf8"
);
const PORT = contentFile
.split("\n")
.filter((i) => i.includes("PORT_SERVICE"))[0]
?.split("=")[1]
.trim();
app.use(express.json()); app.use(express.json());
app.post("/git/gitea-webhook", async (req, res) => { app.post("/git/gitea-webhook", async (req, res) => {
const contentFile = await fs.readFileSync(
"./service_run/giteaService.conf",
"utf8"
);
const checkSendMail = contentFile const checkSendMail = contentFile
.split("\n") .split("\n")
.filter((i) => i.includes("SEND_EMAIL"))[0] .filter((i) => i.includes("SEND_EMAIL"))[0]
@ -75,7 +80,6 @@ app.post("/git/gitea-webhook", async (req, res) => {
}); });
}); });
const PORT = 5000;
app.listen(PORT, () => { app.listen(PORT, () => {
console.log("Server is running on port ", PORT); console.log("Server is running on port ", PORT);
}); });

View File

@ -38,25 +38,8 @@ function run_commands() {
echo "" echo ""
} }
result=$(expect -c " result=$(spawn git pull origin $GIT_BRANCH) &&
set timeout 10 echo "$result" &&
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 if [[ $result == *$fe_path* ]]; then
echo "|--------------------------------------------------------|" echo "|--------------------------------------------------------|"
echo "|***** THERE ARE CHANGES INSIDE FOLDER $fe_path *****|" echo "|***** THERE ARE CHANGES INSIDE FOLDER $fe_path *****|"

View File

@ -4,10 +4,11 @@
HOOK_PATH=/home/gitea_CICD HOOK_PATH=/home/gitea_CICD
# Git account (*) # Git account (*)
GIT_USERNAME=<your_username>
GIT_PASSWORD=<your_password>
GIT_BRANCH=<your_branch> GIT_BRANCH=<your_branch>
# Port of server (*)
PORT_SERVICE=5000
# Email: Used to send notifications when the repository has updates (*) # Email: Used to send notifications when the repository has updates (*)
EMAIL_ADDRESS=<youremail> EMAIL_ADDRESS=<youremail>
# Enable/Disable send mail: True or False (*) # Enable/Disable send mail: True or False (*)