Go to file
root 979105c08c update source variables 2025-05-14 15:53:23 +07:00
service update source variables 2025-05-14 15:53:23 +07:00
.gitignore update .gitignore 2023-10-17 04:16:16 +00:00
README.md update source variables 2025-05-14 15:53:23 +07:00
index.js update source variables 2025-05-14 15:53:23 +07:00
install.sh update source variables 2025-05-14 14:54:29 +07:00
package-lock.json add FE env 2023-10-20 14:15:49 +11:00
package.json update email and REAME.md 2023-10-03 09:24:10 +00:00

README.md

Gitea CICD Service

CI/CD

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

  1. Clone repository
git clone https://gitea.nswteam.net/joseph/gitea_CICD.git
cd gitea_CICD
  1. Create service_run directory and configure
mkdir service_run
cp service/giteaService.conf service_run/giteaService.conf
  1. Configure environment variables
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
  1. 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
  1. Install service
./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:

# 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

  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

📄 License

This project is licensed under the ISC License.


Built with ❤️ by Joseph Le