update source variables
This commit is contained in:
parent
8d732a72e9
commit
979105c08c
|
|
@ -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
|
|
||||||
216
README.md
216
README.md
|
|
@ -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.
|
||||||
git clone https://gitea.nswteam.net/joseph/gitea_CICD.git
|
|
||||||
|
### 🌟 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
|
||||||
|
cd gitea_CICD
|
||||||
```
|
```
|
||||||
|
|
||||||
### 2) Access the folder you just cloned
|
2. **Create service_run directory and configure**
|
||||||
|
```bash
|
||||||
|
mkdir service_run
|
||||||
|
cp service/giteaService.conf service_run/giteaService.conf
|
||||||
|
```
|
||||||
|
|
||||||
root@root#
|
3. **Configure environment variables**
|
||||||
```sh
|
```bash
|
||||||
cd gitea_CICD
|
nano service_run/giteaService.conf
|
||||||
```
|
```
|
||||||
|
|
||||||
### 3) Check the directory path
|
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
|
||||||
|
|
||||||
root@root#
|
4. **Configure Nginx**
|
||||||
```sh
|
|
||||||
pwd
|
|
||||||
```
|
|
||||||
- output: <path>/gitea_CICD
|
|
||||||
|
|
||||||
### 4) Create folder service_run
|
Add the following configuration to your Nginx config file:
|
||||||
|
```nginx
|
||||||
root@root#
|
location /git/ {
|
||||||
|
|
||||||
```sh
|
|
||||||
mkdir service_run
|
|
||||||
```
|
|
||||||
Copy environment file
|
|
||||||
```sh
|
|
||||||
cp service/giteaService.conf service_run/giteaService.conf
|
|
||||||
```
|
|
||||||
|
|
||||||
### 5) Fill in environment variables (\*)
|
|
||||||
|
|
||||||
root@root#
|
|
||||||
```sh
|
|
||||||
nano service_run/giteaService.conf
|
|
||||||
```
|
|
||||||
|
|
||||||
### 6) Add Nginx configuration
|
|
||||||
- Open the Nginx configuration file.
|
|
||||||
|
|
||||||
- Add thr following configuration content.
|
|
||||||
|
|
||||||
```
|
|
||||||
location /git/ {
|
|
||||||
#index index.html;
|
|
||||||
proxy_pass http://<IP-address>:<PORT>;
|
proxy_pass http://<IP-address>:<PORT>;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header X-Forwarded-Host $host;
|
proxy_set_header X-Forwarded-Host $host;
|
||||||
|
|
@ -69,49 +88,96 @@ root@root#
|
||||||
proxy_buffers 4 256k;
|
proxy_buffers 4 256k;
|
||||||
proxy_busy_buffers_size 256k;
|
proxy_busy_buffers_size 256k;
|
||||||
proxy_temp_file_write_size 256k;
|
proxy_temp_file_write_size 256k;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
- Change "IP-address" and "PORT". The "PORT" corresponds to the "PORT_SERVICE" of the "service_run/giteaService.conf" file.
|
Restart Nginx:
|
||||||
|
```bash
|
||||||
|
systemctl restart nginx
|
||||||
|
```
|
||||||
|
|
||||||
- Restart Nginx service.
|
5. **Install service**
|
||||||
```sh
|
```bash
|
||||||
systemctl restart nginx
|
./install.sh
|
||||||
```
|
```
|
||||||
### 7) Run file "install.sh" to install service
|
|
||||||
|
|
||||||
root@root#
|
## ⚙️ Configure Gitea Webhook
|
||||||
```sh
|
|
||||||
./install.sh
|
|
||||||
```
|
|
||||||
|
|
||||||
<div align="center"><img src="https://i.ibb.co/VJHhb3y/install-Service.png" alt="install server" width="600"></div>
|
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)
|
||||||
|
|
||||||
### 8) Add webhook
|
## 📁 Directory Structure
|
||||||
|
|
||||||
- Open your project on Gitea:
|
```
|
||||||
- Choose "Setting"
|
gitea_CICD/
|
||||||
<div align="center"><img src="https://i.ibb.co/QHsST4D/image.png" alt="webhook1" width="800"></div>
|
├── 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
|
||||||
|
```
|
||||||
|
|
||||||
- Choose "Webhooks" and "Add Webhooks"
|
## 🔧 Customize Build Process
|
||||||
<div align="center"><img src="https://i.ibb.co/bKFpvbV/image.png" alt="webhook2" width="800"></div>
|
|
||||||
|
|
||||||
- Fill in the information
|
You can customize the build process by adding environment variables in `giteaService.conf`:
|
||||||
<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).
|
```bash
|
||||||
- Trigger on: Event to trigger the webhook.
|
# Syntax:
|
||||||
- Branch filter: Events will be listened on the branch you choose. ( '*' :all branch)
|
<name>_PROCESS_PATH=/path/to/directory
|
||||||
|
<name>_PROCESS_PATH_COMMAND=command1 && command2 ...
|
||||||
|
|
||||||
#### ** Note: **
|
# Example:
|
||||||
|
FE_PROCESS_PATH=/home/project/frontend
|
||||||
|
FE_PROCESS_PATH_COMMAND=npm install && npm run build
|
||||||
|
|
||||||
- Project gitea_CICD should be placed at the same folder level as your project
|
BE_PROCESS_PATH=/home/project/backend
|
||||||
|
BE_PROCESS_PATH_COMMAND=npm install && npm run start
|
||||||
|
```
|
||||||
|
|
||||||
```
|
## 📧 Email Notifications
|
||||||
├── your_project
|
|
||||||
└── gitea_CICD project
|
|
||||||
```
|
|
||||||
|
|
||||||
- Depending on the technology your project uses, the "gitea_CICD/service_run/giteaHook.sh" file will be custom configured to match the technology.
|
The system sends email notifications when:
|
||||||
|
- New repository events occur
|
||||||
|
- Build process succeeds/fails
|
||||||
|
- Errors occur during processing
|
||||||
|
|
||||||
<div align="center"><h4><i>**____ Joseph Le____ **</i></h4></div>
|
## 🔍 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>
|
||||||
|
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
version: '3'
|
|
||||||
services:
|
|
||||||
giteahook:
|
|
||||||
build: .
|
|
||||||
container_name: giteahook
|
|
||||||
volumes:
|
|
||||||
- ".:/data"
|
|
||||||
tty: true
|
|
||||||
ports:
|
|
||||||
- '8000:8001'
|
|
||||||
17
index.js
17
index.js
|
|
@ -25,12 +25,12 @@ const getConfigValue = (key) => contentFile
|
||||||
// Configure email transporter
|
// Configure email transporter
|
||||||
const createTransporter = () => nodeMailer.createTransport({
|
const createTransporter = () => nodeMailer.createTransport({
|
||||||
pool: true,
|
pool: true,
|
||||||
host: "mail.apactech.io",
|
host: getConfigValue("EMAIL_HOST") || "smtp.gmail.com",
|
||||||
port: 465,
|
port: parseInt(getConfigValue("EMAIL_PORT") || "587"),
|
||||||
secure: true,
|
secure: getConfigValue("EMAIL_SECURE") === "True",
|
||||||
auth: {
|
auth: {
|
||||||
user: "admin@apactech.io",
|
user: getConfigValue("EMAIL_USER") || "git@notification.com",
|
||||||
pass: "BGK!dyt6upd2eax1bhz",
|
pass: getConfigValue("EMAIL_PASSWORD") || "123456789",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -39,7 +39,8 @@ app.use(express.json());
|
||||||
app.post("/git/gitea-webhook", async (req, res) => {
|
app.post("/git/gitea-webhook", async (req, res) => {
|
||||||
let title = "";
|
let title = "";
|
||||||
const checkSendMail = getConfigValue("SEND_EMAIL");
|
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"];
|
const giteaEvent = req.headers["x-gitea-event"];
|
||||||
|
|
||||||
// Return response immediately
|
// Return response immediately
|
||||||
|
|
@ -51,7 +52,7 @@ app.post("/git/gitea-webhook", async (req, res) => {
|
||||||
if (checkSendMail === "True") {
|
if (checkSendMail === "True") {
|
||||||
const transporter = createTransporter();
|
const transporter = createTransporter();
|
||||||
const options = {
|
const options = {
|
||||||
from: "admin@apactech.io",
|
from: emailFrom,
|
||||||
to: emailAddress,
|
to: emailAddress,
|
||||||
subject: "Git notifications (Fail)",
|
subject: "Git notifications (Fail)",
|
||||||
html: "<h3>There is an active build process. Please check and push again in a few minutes.</h3>",
|
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") {
|
if (checkSendMail === "True") {
|
||||||
const transporter = createTransporter();
|
const transporter = createTransporter();
|
||||||
const options = {
|
const options = {
|
||||||
from: "admin@apactech.io",
|
from: emailFrom,
|
||||||
to: emailAddress,
|
to: emailAddress,
|
||||||
subject: title,
|
subject: title,
|
||||||
html: `
|
html: `
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,15 @@ GIT_BRANCH=<your_branch>
|
||||||
PORT_SERVICE=5000
|
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>
|
|
||||||
# Enable/Disable send mail: True or False (*)
|
# 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 (*)
|
# URL of project directory (*)
|
||||||
# Example: /home/My_project/
|
# Example: /home/My_project/
|
||||||
PROJECT_PATH=</project/directory/path>
|
PROJECT_PATH=</project/directory/path>
|
||||||
|
|
|
||||||
33
test.js
33
test.js
|
|
@ -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")
|
|
||||||
Loading…
Reference in New Issue