|
|
||
|---|---|---|
| service | ||
| .gitignore | ||
| README.md | ||
| index.js | ||
| install.sh | ||
| package-lock.json | ||
| package.json | ||
README.md
Gitea CICD Service
Automated CI/CD System for Gitea
📝 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
- Clone repository
git clone https://gitea.nswteam.net/joseph/gitea_CICD.git
cd gitea_CICD
- Create service_run directory and configure
mkdir service_run
cp service/giteaService.conf service_run/giteaService.conf
- Configure environment variables
nano service_run/giteaService.conf
Required environment variables:
GIT_USERNAME: Gitea usernameGIT_PASSWORD: Gitea passwordGIT_REPOSITORY: Repository URLGIT_BRANCH: Branch to monitorPORT_SERVICE: Service portEMAIL_ADDRESS: Notification emailSEND_EMAIL: Enable/disable email notifications (True/False)RECEIVE_EMAIL_ADDRESS: Email address to receive notificationsEMAIL_FROM: Sender email addressEMAIL_HOST: Email server hostEMAIL_PORT: Email server portEMAIL_SECURE: Secure connection (True/False)EMAIL_USER: Email usernameEMAIL_PASSWORD: Email passwordPROJECT_PATH: Project directory path
- Configure Nginx
Add the following configuration to your Nginx config file:
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:
systemctl restart nginx
- Install service
./install.sh
⚙️ Configure Gitea Webhook
- Access your Gitea repository
- Go to Settings > Webhooks
- Click "Add Webhook"
- 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)
- Target URL:
📁 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:
# 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:
journalctl -u giteaHook -f
- Check service status:
systemctl status giteaHook
📝 Important Notes
- The
gitea_CICDproject should be placed at the same level as the project to be monitored - Ensure appropriate file and directory permissions
- Verify environment variables before running the service
- Use HTTPS for webhooks to ensure security
👨💻 Author
Joseph Le - GitHub
📄 License
This project is licensed under the ISC License.
Built with ❤️ by Joseph Le