DevOps standards, CI/CD pipelines, and containerization practices...
DevOps standards, CI/CD pipelines, and containerization practices.
Strict Requirements: When creating a Pull Request, the following checks MUST run and MUST pass before merging:
Security Checks (Strict)
pnpm audit, Dependabot, or SnykSonarQube Analysis (Strict)
Unit Tests (Strict)
Linting (Strict)
Required GitHub Actions versions:
actions/checkout@v4pnpm/action-setup@v2 (with pnpm version >= 10)actions/setup-node@v4 (with Node.js 22.x)Example GitHub Actions workflow:
Note: The following PR checks are strict requirements - all must be included and pass before merging.
name: PR Checks
on:
pull_request:
branches: [main, develop]
jobs:
security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v2
with:
version: 10
- uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'pnpm'
- run: pnpm install --frozen-lockfile
- run: pnpm audit --audit-level=moderate
sonarqube:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: pnpm/action-setup@v2
with:
version: 10
- uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'pnpm'
- run: pnpm install --frozen-lockfile
- name: SonarQube Scan
uses: sonarsource/sonarqube-scan-action@master
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v2
with:
version: 10
- uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'pnpm'
- run: pnpm install --frozen-lockfile
- run: pnpm run test:ci
- uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v2
with:
version: 10
- uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'pnpm'
- run: pnpm install --frozen-lockfile
- run: pnpm run lint
- run: pnpm run format:check
Set up Docker and Docker Compose for local development and deployment.
Docker Compose Structure:
version: '3.8'
services:
app:
build: .
ports:
- "3000:3000"
environment:
- NODE_ENV=development
volumes:
- .:/app
- /app/node_modules
depends_on:
- prometheus
- grafana
prometheus:
image: prom/prometheus:latest
ports:
- "9090:9090"
volumes:
- ./prometheus:/etc/prometheus
- prometheus_data:/prometheus
grafana:
image: grafana/grafana:latest
ports:
- "3001:3000"
environment:
- GF_SECURITY_ADMIN_PASSWORD=admin
volumes:
- grafana_data:/var/lib/grafana
depends_on:
- prometheus
volumes:
prometheus_data:
grafana_data:
Dockerfile Best Practices:
Additional Services:
The GitHub CLI (gh) provides powerful commands for managing GitHub Actions workflows, runs, secrets, and other DevOps operations.
List and View Workflows:
# List all workflows in repository
gh workflow list
# View workflow details
gh workflow view <workflow-id>
# View workflow YAML file
gh workflow view <workflow-id> --yaml
# View workflow runs
gh run list
# View specific workflow run
gh run view <run-id>
# View workflow run logs
gh run view <run-id> --log
# Watch workflow run in real-time
gh run watch <run-id>
Run and Manage Workflows:
# Manually trigger a workflow
gh workflow run <workflow-id>
# Run workflow with inputs
gh workflow run <workflow-id> --field key=value
# Rerun a failed workflow
gh run rerun <run-id>
# Cancel a running workflow
gh run cancel <run-id>
# Delete workflow runs
gh run delete <run-id>
For AI Agents:
Manage GitHub Actions Caches:
# List all caches
gh cache list
# Delete specific cache
gh cache delete <cache-id>
# Delete all caches (use with caution)
gh cache list --json id --jq '.[].id' | xargs -I {} gh cache delete {}
For AI Agents:
Repository Secrets:
# List secrets
gh secret list
# Set a secret
gh secret set SECRET_NAME --body "secret-value"
# Delete a secret
gh secret delete SECRET_NAME
Repository Variables:
# List variables
gh variable list
# Get variable value
gh variable get VARIABLE_NAME
# Set variable
gh variable set VARIABLE_NAME --body "variable-value"
# Delete variable
gh variable delete VARIABLE_NAME
For AI Agents:
Check PR Status:
# Check all checks for a PR
gh pr checks <pr-number>
# Wait for checks to complete
gh pr checks <pr-number> --watch
# View check details
gh run view <run-id> --log
For AI Agents:
Workflow Enable/Disable:
# Disable a workflow
gh workflow disable <workflow-id>
# Enable a workflow
gh workflow enable <workflow-id>
Download Artifacts:
# List artifacts from a run
gh run view <run-id> --json artifacts
# Download artifacts
gh run download <run-id>
For AI Agents:
Example: Automated Deployment Workflow
#!/bin/bash
# Automated deployment script using gh CLI
# 1. Check if PR is ready
PR_NUMBER=$(gh pr list --head $(git branch --show-current) --json number -q '.[0].number')
if [ -z "$PR_NUMBER" ]; then
echo "No PR found for current branch"
exit 1
fi
# 2. Wait for all checks to pass
echo "Waiting for CI checks..."
gh pr checks $PR_NUMBER --watch
# 3. Verify checks passed
CHECKS_STATUS=$(gh pr checks $PR_NUMBER --json status -q '.[].status')
if [[ "$CHECKS_STATUS" == *"FAILURE"* ]]; then
echo "Some checks failed. Deployment aborted."
exit 1
fi
# 4. Merge PR
gh pr merge $PR_NUMBER --squash --delete-branch
# 5. Wait for deployment workflow
echo "Waiting for deployment workflow..."
DEPLOY_RUN=$(gh run list --workflow=deploy.yml --limit 1 --json databaseId -q '.[0].databaseId')
gh run watch $DEPLOY_RUN
# 6. Verify deployment
DEPLOY_STATUS=$(gh run view $DEPLOY_RUN --json conclusion -q '.conclusion')
if [ "$DEPLOY_STATUS" != "success" ]; then
echo "Deployment failed!"
exit 1
fi
echo "Deployment successful!"
For AI Agents:
Deployment Status:
# View deployment status (via API)
gh api repos/:owner/:repo/deployments
# View deployment environments
gh api repos/:owner/:repo/environments
For AI Agents:
gh pr checks before merginggh run watch for real-time updates--json output for programmatic processingCommon Commands for Debugging:
# View recent failed runs
gh run list --status failure --limit 10
# View logs for failed run
gh run view <run-id> --log --failed
# Check workflow syntax
gh workflow view <workflow-id> --yaml
# Verify secrets are set
gh secret list
# Check cache status
gh cache list
For AI Agents: