|
| 1 | +# GitHub Actions workflow for deploying the application to production environment |
| 2 | +# This workflow handles both UI deployment and database migrations |
| 3 | +name: Deploy to production environment |
| 4 | + |
| 5 | +# Concurrency control to prevent multiple deployments running simultaneously |
| 6 | +# If a new deployment is triggered while one is running, the previous one will be cancelled |
| 7 | +concurrency: |
| 8 | + group: production-app-deploy |
| 9 | + cancel-in-progress: true |
| 10 | + |
| 11 | +# Trigger conditions for this workflow |
| 12 | +on: |
| 13 | + push: |
| 14 | + branches: |
| 15 | + - next # Deploy on every push to next branch |
| 16 | + workflow_dispatch: # Allow manual triggering from GitHub UI |
| 17 | + |
| 18 | +jobs: |
| 19 | + # Job for deploying the UI/frontend application |
| 20 | + deploy-ui: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + |
| 23 | + # Environment variables for Kamal deployment and container registry |
| 24 | + env: |
| 25 | + DOCKER_BUILDKIT: 1 # Enable Docker BuildKit for faster builds |
| 26 | + KAMAL_REGISTRY_LOGIN_SERVER: ${{ secrets.KAMAL_REGISTRY_LOGIN_SERVER }} |
| 27 | + KAMAL_REGISTRY_USERNAME: ${{ secrets.KAMAL_REGISTRY_USERNAME }} |
| 28 | + KAMAL_REGISTRY_PASSWORD: ${{ secrets.KAMAL_REGISTRY_PASSWORD }} |
| 29 | + KAMAL_SERVER_IP: ${{ secrets.KAMAL_SERVER_IP }} |
| 30 | + KAMAL_APP_DOMAIN: ${{ secrets.KAMAL_APP_DOMAIN }} |
| 31 | + KAMAL_APP_NAME: ${{ secrets.KAMAL_APP_NAME }} |
| 32 | + |
| 33 | + steps: |
| 34 | + # Step 1: Checkout the repository code |
| 35 | + - uses: actions/checkout@v4 |
| 36 | + |
| 37 | + # Step 2: Setup Ruby environment for Kamal deployment tool |
| 38 | + - uses: ruby/setup-ruby@v1 |
| 39 | + with: |
| 40 | + ruby-version: 3.3.1 |
| 41 | + bundler-cache: true # Cache Ruby dependencies for faster builds |
| 42 | + |
| 43 | + # Step 3: Install Kamal deployment tool |
| 44 | + - run: gem install kamal |
| 45 | + |
| 46 | + # Step 4: Setup SSH agent for server access |
| 47 | + - uses: webfactory/ssh-agent@v0.9.0 |
| 48 | + with: |
| 49 | + ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} |
| 50 | + |
| 51 | + # Step 5: Authenticate with Azure Container Registry |
| 52 | + - name: Login to Azure Container Registry |
| 53 | + uses: azure/docker-login@v1 |
| 54 | + with: |
| 55 | + login-server: ${{ secrets.KAMAL_REGISTRY_LOGIN_SERVER }} |
| 56 | + username: ${{ secrets.KAMAL_REGISTRY_USERNAME }} |
| 57 | + password: ${{ secrets.KAMAL_REGISTRY_PASSWORD }} |
| 58 | + |
| 59 | + # Step 6: Setup Docker Buildx for better caching and performance |
| 60 | + - name: Set up Docker Buildx for cache |
| 61 | + uses: docker/setup-buildx-action@v3 |
| 62 | + |
| 63 | + # Step 7: Verify Kamal installation |
| 64 | + - run: kamal version |
| 65 | + |
| 66 | + # Step 8: Release any existing deployment locks |
| 67 | + # This prevents conflicts when redeploying while a previous deployment is running |
| 68 | + - run: kamal lock release |
| 69 | + # Uncomment for verbose output during troubleshooting: |
| 70 | + # - run: kamal lock release --verbose |
| 71 | + |
| 72 | + # Step 9: Initial Kamal setup (only needed once per server) |
| 73 | + # Note: This step might need to be run manually on the server first time |
| 74 | + # to add the user to the docker group: `sudo usermod -aG docker $USER | newgrp docker | docker ps` |
| 75 | + - run: kamal setup |
0 commit comments