CI/CD Quick Reference
Quick reference guide for common CI/CD tasks and commands.
GitHub Actions Workflow Triggers
Manual Trigger
on:
workflow_dispatch:
inputs:
environment:
description: 'Environment'
required: true
type: choice
options:
- staging
- production
Branch-Based Triggers
on:
push:
branches: [ main, staging ]
pull_request:
branches: [ main ]
Common Workflow Steps
Checkout Code
- uses: actions/checkout@v3
Setup Node.js
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'
Run Tests
- name: Run tests
run: npm test
Build Docker Image
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: image:tag
Deploy via SSH
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USER }}
key: ${{ secrets.SSH_KEY }}
script: |
cd /opt/sbmcrm
./deploy.sh
Huawei Cloud Commands
Login to SWR
docker login -u {username} -p {password} swr.ap-southeast-1.myhuaweicloud.com
Push Image to SWR
docker tag image:tag swr.ap-southeast-1.myhuaweicloud.com/org/repo:tag
docker push swr.ap-southeast-1.myhuaweicloud.com/org/repo:tag
Pull Image from SWR
docker pull swr.ap-southeast-1.myhuaweicloud.com/org/repo:tag
Deployment Commands
Update Services
cd /opt/sbmcrm
docker-compose pull
docker-compose up -d
Run Migrations
docker-compose exec api npm run migrate
Health Check
curl -f http://localhost:3000/health
View Logs
docker-compose logs -f api
Rollback
docker-compose down
docker-compose up -d --scale api=0
# Restore previous image
docker-compose up -d
Environment Variables
GitHub Secrets
Required secrets for CI/CD:
HUAWEI_ACCESS_KEY
HUAWEI_SECRET_KEY
STAGING_HOST
STAGING_USER
STAGING_SSH_KEY
PRODUCTION_HOST
PRODUCTION_USER
PRODUCTION_SSH_KEY
Docker Compose Environment
# .env file
REGISTRY=swr.ap-southeast-1.myhuaweicloud.com
IMAGE_NAME=sbmcrm-platform
IMAGE_TAG=latest
DATABASE_URL=postgresql://...
REDIS_URL=redis://...
Troubleshooting Commands
Check Workflow Status
# View workflow runs
gh run list
# View specific run
gh run view <run-id>
# View logs
gh run view <run-id> --log
Test SSH Connection
ssh -i ~/.ssh/key user@host
Test Docker Connection
docker login swr.ap-southeast-1.myhuaweicloud.com
docker pull swr.ap-southeast-1.myhuaweicloud.com/org/repo:tag
Check Container Status
docker-compose ps
docker-compose logs api
Best Practices Checklist
- Tests run on every PR
- Build only on successful tests
- Deploy only from protected branches
- Use environment-specific secrets
- Implement health checks
- Set up rollback procedures
- Monitor deployment status
- Send notifications on failure