A Node.js-based continuous integration and continuous deployment (CI/CD) server that handles GitHub webhooks to automatically deploy frontend and backend applications to development and production environments.
- Automated deployments triggered by GitHub push events
- Separate webhook endpoints for frontend and backend deployments
- Support for both development and production environments
- Secure webhook verification using GitHub signatures
- Environment-based configuration
- Node Version Manager (NVM)
- Node.js (v20.17.0)
- npm
- PM2 (for process management)
- Git
- Bash shell
- Sudo access (for production deployments)
- Clone the repository:
git clone https://github.com/DigitalGuards/theqrlwallet-auto-deploy.git
cd theqrlwallet-auto-deploy- Install dependencies:
npm install- Create a
.envfile in the root directory with the following variables:
PORT=3000
SECRET=your_github_webhook_secret
NVM_PATH=/path/to/nvm/nvm.sh
FRONTEND_PROD_PATH=/path/to/frontend/prod/repo
FRONTEND_DEV_PATH=/path/to/frontend/dev/repo
BACKEND_PROD_PATH=/path/to/backend/prod/repo
BACKEND_DEV_PATH=/path/to/backend/dev/repo
FRONTEND_DEPLOYED_PROD_PATH=/path/to/frontend/prod/deployed
FRONTEND_DEV_PM2_NAME=frontend-dev
BACKEND_PROD_PM2_NAME=backend-prod
BACKEND_DEV_PM2_NAME=backend-dev- Start the server:
node server.js- Configure GitHub webhooks:
- Add webhook URLs for your frontend and backend repositories:
- Frontend webhook:
http://your-server:PORT/frontend-webhook - Backend webhook:
http://your-server:PORT/backend-webhook
- Frontend webhook:
- Set content type to
application/json - Set the secret to match your
SECRETenvironment variable - Select the "Push" event
- Add webhook URLs for your frontend and backend repositories:
- URL:
/frontend-webhook - Handles deployments for the frontend application
- Supports both main (production) and dev (development) branches
- URL:
/backend-webhook - Handles deployments for the backend application
- Supports both main (production) and dev (development) branches
The server implements GitHub's webhook signature verification using SHA-256 HMAC validation. Each request is verified against the secret configured in the environment variables.
The project includes four deployment scripts:
-
deploy-frontend-prod.sh: Deploys frontend to production- Pulls from main branch
- Builds the application
- Copies built files to production server
-
deploy-frontend-dev.sh: Deploys frontend to development- Pulls from dev branch
- Installs dependencies
- Restarts PM2 process
-
deploy-backend-prod.sh: Deploys backend to production- Pulls from main branch
- Installs dependencies
- Restarts PM2 process
-
deploy-backend-dev.sh: Deploys backend to development- Pulls from dev branch
- Installs dependencies
- Restarts PM2 process
- Failed signature verification returns 401 status code
- Failed deployments return 500 status code with error details
- All deployment activities are logged to the console
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License. See the LICENSE file for details.