Skip to content

GitHub Actions Examples

CI/CD workflows for deploying with Ops Atlas.

Deploy on Push

yaml
# .github/workflows/deploy.yml
name: Deploy to Production

on:
  push:
    branches: [main]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3
      
      - name: Login to Registry
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      
      - name: Build and Push
        uses: docker/build-push-action@v5
        with:
          push: true
          tags: ghcr.io/${{ github.repository }}:${{ github.sha }}
          cache-from: type=gha
          cache-to: type=gha,mode=max

  deploy:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - name: Deploy via Ops Atlas
        run: |
          curl -X POST "${{ secrets.OPSATLAS_URL }}/api/v1/deployments" \
            -H "Authorization: Bearer ${{ secrets.OPSATLAS_TOKEN }}" \
            -H "Content-Type: application/json" \
            -d '{
              "service": "${{ github.event.repository.name }}",
              "version": "${{ github.sha }}",
              "strategy": "rolling"
            }'
      
      - name: Wait for Deployment
        run: |
          for i in {1..30}; do
            STATUS=$(curl -s "${{ secrets.OPSATLAS_URL }}/api/v1/deployments/latest?service=${{ github.event.repository.name }}" \
              -H "Authorization: Bearer ${{ secrets.OPSATLAS_TOKEN }}" | jq -r '.data.status')
            
            if [ "$STATUS" = "success" ]; then
              echo "Deployment successful!"
              exit 0
            elif [ "$STATUS" = "failed" ]; then
              echo "Deployment failed!"
              exit 1
            fi
            
            echo "Status: $STATUS - waiting..."
            sleep 10
          done
          echo "Deployment timeout!"
          exit 1

PR Preview Environments

yaml
# .github/workflows/preview.yml
name: Preview Environment

on:
  pull_request:
    types: [opened, synchronize, reopened]

jobs:
  preview:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Create Preview
        run: |
          curl -X POST "${{ secrets.OPSATLAS_URL }}/api/v1/environments" \
            -H "Authorization: Bearer ${{ secrets.OPSATLAS_TOKEN }}" \
            -H "Content-Type: application/json" \
            -d '{
              "name": "pr-${{ github.event.pull_request.number }}",
              "service": "${{ github.event.repository.name }}",
              "version": "${{ github.sha }}",
              "ttl": "24h"
            }'
      
      - name: Comment PR
        uses: actions/github-script@v7
        with:
          script: |
            github.rest.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body: '🚀 Preview deployed: https://pr-${{ github.event.pull_request.number }}.preview.example.com'
            })

Required Secrets

Add these secrets to your repository:

SecretDescription
OPSATLAS_URLOps Atlas API URL (e.g., https://ops.example.com)
OPSATLAS_TOKENAPI key with deploy permissions

Released under the MIT License.