update source variables

This commit is contained in:
root 2025-05-14 15:53:23 +07:00
parent 8d732a72e9
commit 979105c08c
7 changed files with 171 additions and 151 deletions

View File

@ -1,9 +0,0 @@
FROM node:16.3.0-alpine
RUN apk update
RUN apk add --no-cache --upgrade bash
#RUN addgroup -S admin && adduser -S admin -G admin
WORKDIR /data
#RUN chown -R admin:admin /data
#RUN chmod 755 /data
#USER admin
CMD npm install; npm run start

196
README.md
View File

@ -1,55 +1,74 @@
# gitea_CICD
# Gitea CICD Service
<div align="center"><img src="https://upload.wikimedia.org/wikipedia/commons/d/d9/Node.js_logo.svg" alt="NodeJS" width="300"></div>
<div align="center">
<img src="https://static-00.iconduck.com/assets.00/ci-cd-line-icon-512x511-3m4br5fx.png" alt="CI/CD" width="200">
<h3>Automated CI/CD System for Gitea</h3>
</div>
### 1) Clone project to your server
## 📝 Description
```sh
Gitea CICD Service is an automated CI/CD (Continuous Integration/Continuous Deployment) solution for projects hosted on Gitea. The system automatically monitors repository events (such as push, pull request) and executes corresponding commands to build, test, and deploy applications.
### 🌟 Key Features
- Automatic triggering on Gitea events (push, pull request)
- Support for multiple environments and technologies (Node.js, Frontend, Backend)
- Email notifications for events
- Flexible configuration through config file
- Nginx integration for webhook handling
- Runs as a systemd service for reliability
## 🚀 Installation
### System Requirements
- Node.js (version 16.3.0 or higher)
- NPM
- Nginx
- Git
- Systemd (for Linux)
### Installation Steps
1. **Clone repository**
```bash
git clone https://gitea.nswteam.net/joseph/gitea_CICD.git
```
### 2) Access the folder you just cloned
root@root#
```sh
cd gitea_CICD
```
### 3) Check the directory path
root@root#
```sh
pwd
```
- output: <path>/gitea_CICD
### 4) Create folder service_run
root@root#
```sh
2. **Create service_run directory and configure**
```bash
mkdir service_run
```
Copy environment file
```sh
cp service/giteaService.conf service_run/giteaService.conf
```
### 5) Fill in environment variables (\*)
root@root#
```sh
3. **Configure environment variables**
```bash
nano service_run/giteaService.conf
```
### 6) Add Nginx configuration
- Open the Nginx configuration file.
Required environment variables:
- `GIT_USERNAME`: Gitea username
- `GIT_PASSWORD`: Gitea password
- `GIT_REPOSITORY`: Repository URL
- `GIT_BRANCH`: Branch to monitor
- `PORT_SERVICE`: Service port
- `EMAIL_ADDRESS`: Notification email
- `SEND_EMAIL`: Enable/disable email notifications (True/False)
- `RECEIVE_EMAIL_ADDRESS`: Email address to receive notifications
- `EMAIL_FROM`: Sender email address
- `EMAIL_HOST`: Email server host
- `EMAIL_PORT`: Email server port
- `EMAIL_SECURE`: Secure connection (True/False)
- `EMAIL_USER`: Email username
- `EMAIL_PASSWORD`: Email password
- `PROJECT_PATH`: Project directory path
- Add thr following configuration content.
4. **Configure Nginx**
```
Add the following configuration to your Nginx config file:
```nginx
location /git/ {
#index index.html;
proxy_pass http://<IP-address>:<PORT>;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-Host $host;
@ -72,46 +91,93 @@ root@root#
}
```
- Change "IP-address" and "PORT". The "PORT" corresponds to the "PORT_SERVICE" of the "service_run/giteaService.conf" file.
- Restart Nginx service.
```sh
Restart Nginx:
```bash
systemctl restart nginx
```
### 7) Run file "install.sh" to install service
root@root#
```sh
5. **Install service**
```bash
./install.sh
```
<div align="center"><img src="https://i.ibb.co/VJHhb3y/install-Service.png" alt="install server" width="600"></div>
## ⚙️ Configure Gitea Webhook
### 8) Add webhook
1. Access your Gitea repository
2. Go to Settings > Webhooks
3. Click "Add Webhook"
4. Fill in the information:
- Target URL: `http://your-domain/git/gitea-webhook`
- Trigger on: Select events to monitor
- Branch filter: Enter branch to monitor (or '*' for all)
- Open your project on Gitea:
- Choose "Setting"
<div align="center"><img src="https://i.ibb.co/QHsST4D/image.png" alt="webhook1" width="800"></div>
- Choose "Webhooks" and "Add Webhooks"
<div align="center"><img src="https://i.ibb.co/bKFpvbV/image.png" alt="webhook2" width="800"></div>
- Fill in the information
<div align="center"><img src="https://i.ibb.co/GJ55RDr/image.png" alt="webhook3" width="800"></div>
- Target URL: URL to the API that handles requests when a event is triggered (Default: your_domain/git/gitea-webhook).
- Trigger on: Event to trigger the webhook.
- Branch filter: Events will be listened on the branch you choose. ( '*' :all branch)
#### ** Note: **
- Project gitea_CICD should be placed at the same folder level as your project
## 📁 Directory Structure
```
├── your_project
└── gitea_CICD project
gitea_CICD/
├── service/ # Service files directory
│ ├── giteaService.conf # Configuration template
│ ├── giteaService.sh # Main script
│ └── giteaHook.service # Systemd configuration
├── service_run/ # Runtime directory (created during installation)
├── index.js # Main webhook handler
├── install.sh # Installation script
└── README.md # Documentation
```
- Depending on the technology your project uses, the "gitea_CICD/service_run/giteaHook.sh" file will be custom configured to match the technology.
## 🔧 Customize Build Process
<div align="center"><h4><i>**____ Joseph Le____ **</i></h4></div>
You can customize the build process by adding environment variables in `giteaService.conf`:
```bash
# Syntax:
<name>_PROCESS_PATH=/path/to/directory
<name>_PROCESS_PATH_COMMAND=command1 && command2 ...
# Example:
FE_PROCESS_PATH=/home/project/frontend
FE_PROCESS_PATH_COMMAND=npm install && npm run build
BE_PROCESS_PATH=/home/project/backend
BE_PROCESS_PATH_COMMAND=npm install && npm run start
```
## 📧 Email Notifications
The system sends email notifications when:
- New repository events occur
- Build process succeeds/fails
- Errors occur during processing
## 🔍 Monitoring and Troubleshooting
- View service logs:
```bash
journalctl -u giteaHook -f
```
- Check service status:
```bash
systemctl status giteaHook
```
## 📝 Important Notes
1. The `gitea_CICD` project should be placed at the same level as the project to be monitored
2. Ensure appropriate file and directory permissions
3. Verify environment variables before running the service
4. Use HTTPS for webhooks to ensure security
## 👨‍💻 Author
**Joseph Le** - [GitHub](https://github.com/joseph)
## 📄 License
This project is licensed under the ISC License.
---
<div align="center">
<sub>Built with ❤️ by Joseph Le</sub>
</div>

View File

View File

@ -1,10 +0,0 @@
version: '3'
services:
giteahook:
build: .
container_name: giteahook
volumes:
- ".:/data"
tty: true
ports:
- '8000:8001'

View File

@ -25,12 +25,12 @@ const getConfigValue = (key) => contentFile
// Configure email transporter
const createTransporter = () => nodeMailer.createTransport({
pool: true,
host: "mail.apactech.io",
port: 465,
secure: true,
host: getConfigValue("EMAIL_HOST") || "smtp.gmail.com",
port: parseInt(getConfigValue("EMAIL_PORT") || "587"),
secure: getConfigValue("EMAIL_SECURE") === "True",
auth: {
user: "admin@apactech.io",
pass: "BGK!dyt6upd2eax1bhz",
user: getConfigValue("EMAIL_USER") || "git@notification.com",
pass: getConfigValue("EMAIL_PASSWORD") || "123456789",
},
});
@ -39,7 +39,8 @@ app.use(express.json());
app.post("/git/gitea-webhook", async (req, res) => {
let title = "";
const checkSendMail = getConfigValue("SEND_EMAIL");
const emailAddress = getConfigValue("EMAIL_ADDRESS");
const emailAddress = getConfigValue("RECEIVE_EMAIL_ADDRESS");
const emailFrom = getConfigValue("EMAIL_FROM") || "git@notification.com";
const giteaEvent = req.headers["x-gitea-event"];
// Return response immediately
@ -51,7 +52,7 @@ app.post("/git/gitea-webhook", async (req, res) => {
if (checkSendMail === "True") {
const transporter = createTransporter();
const options = {
from: "admin@apactech.io",
from: emailFrom,
to: emailAddress,
subject: "Git notifications (Fail)",
html: "<h3>There is an active build process. Please check and push again in a few minutes.</h3>",
@ -90,7 +91,7 @@ app.post("/git/gitea-webhook", async (req, res) => {
if (checkSendMail === "True") {
const transporter = createTransporter();
const options = {
from: "admin@apactech.io",
from: emailFrom,
to: emailAddress,
subject: title,
html: `

View File

@ -15,10 +15,15 @@ GIT_BRANCH=<your_branch>
PORT_SERVICE=5000
# Email: Used to send notifications when the repository has updates (*)
EMAIL_ADDRESS=<youremail>
# Enable/Disable send mail: True or False (*)
SEND_EMAIL=True
SEND_EMAIL=False
RECEIVE_EMAIL_ADDRESS=<youremail>
EMAIL_FROM=
EMAIL_HOST=
EMAIL_PORT=
EMAIL_SECURE=True
EMAIL_USER=
EMAIL_PASSWORD=
# URL of project directory (*)
# Example: /home/My_project/
PROJECT_PATH=</project/directory/path>

33
test.js
View File

@ -1,33 +0,0 @@
const nodeMailer = require("nodemailer");
// Configure email transporter
const transporter = nodeMailer.createTransport({
pool: true,
host: "mail.apactech.io",
port: 465,
secure: true,
auth: {
user: "admin@apactech.io",
pass: "BGK!dyt6upd2eax1bhz",
},
});
// const transporter = createTransporter();
const options = {
from: "admin@apactech.io",
to: "joseph@apactech.io",
subject: "Test",
html: `
<h1>*** event ***</h1>
<h4>Committer: N/A</h4>
<h4>Message: N/A</h4>
<h4>Branch: N/A</h4>
<h4>Process output:</h4>
<textarea style='wordWrap:break-word; display: block; width:100%; height:70vh;border:solid 2px orange'>N/A</textarea>
`,
};
transporter.sendMail(options);
console.log("first")