gitea_CICD/README.md

184 lines
4.9 KiB
Markdown

# Gitea CICD Service
<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>
## 📝 Description
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
cd gitea_CICD
```
2. **Create service_run directory and configure**
```bash
mkdir service_run
cp service/giteaService.conf service_run/giteaService.conf
```
3. **Configure environment variables**
```bash
nano service_run/giteaService.conf
```
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
4. **Configure Nginx**
Add the following configuration to your Nginx config file:
```nginx
location /git/ {
proxy_pass http://<IP-address>:<PORT>;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_pass_request_headers on;
proxy_max_temp_file_size 0;
proxy_connect_timeout 900;
proxy_send_timeout 900;
proxy_read_timeout 900;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_temp_file_write_size 256k;
}
```
Restart Nginx:
```bash
systemctl restart nginx
```
5. **Install service**
```bash
./install.sh
```
## ⚙️ Configure Gitea 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)
## 📁 Directory Structure
```
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
```
## 🔧 Customize Build Process
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>