Try cleaner way of caching with Docker #711
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: deploy bot stack | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| on: | |
| push: { branches: [main] } | |
| # TODO: REMOVE BEFORE MERGE | |
| pull_request: { branches: [main] } | |
| jobs: | |
| deploy: | |
| name: Deploy Stack | |
| runs-on: ubuntu-latest | |
| container: ubuntu:noble | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| # actions/cache will detect zstd and will become much faster. | |
| - name: Install zstd | |
| run: | | |
| apt-get update -y | |
| apt-get install -y zstd | |
| - name: Install Docker | |
| run: | | |
| # Make scripts executable | |
| chmod +x ./.github/scripts/* | |
| # Install Docker | |
| ./.github/scripts/install-docker.bash | |
| - name: Set up Docker Buildx with GHA caching support | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| aws-access-key-id: ${{ secrets.DEPLOYER_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ secrets.DEPLOYER_ACCESS_SECRET_KEY }} | |
| aws-region: "eu-west-1" | |
| - name: Login to Amazon ECR | |
| id: login-ecr | |
| uses: aws-actions/amazon-ecr-login@v2 | |
| - name: Restore .build | |
| if: ${{ runner.debug != '1' }} | |
| id: "restore-cache" | |
| uses: actions/cache/restore@v4 | |
| with: | |
| path: .build | |
| key: "penny-release-docker-static-build-${{ runner.os }}-${{ github.event.after }}" | |
| restore-keys: "penny-release-docker-static-build-${{ runner.os }}-" | |
| - name: Build, tag and push Docker image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| build-args: | | |
| SWIFT_CONFIGURATION=release | |
| EXEC_NAME=Penny | |
| # CHANGE TO TRUE BEFORE MERGE | |
| push: false | |
| tags: ${{ steps.login-ecr.outputs.registry }}/penny-bot-discord-image:${{ github.sha }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Fill in the new image ID in the Amazon ECS task definition | |
| id: task-def | |
| uses: aws-actions/amazon-ecs-render-task-definition@v1 | |
| with: | |
| task-definition: ./deploy/penny-discord-bot-task.json | |
| container-name: penny-bot | |
| image: ${{ steps.login-ecr.outputs.registry }}/penny-bot-discord-image:${{ github.sha }} | |
| - name: Deploy to Amazon ECS Service | |
| id: task-dep | |
| uses: aws-actions/amazon-ecs-deploy-task-definition@v2 | |
| with: | |
| task-definition: ${{ steps.task-def.outputs.task-definition }} | |
| wait-for-service-stability: true | |
| - name: Deploy to AWS cloudformation | |
| uses: aws-actions/aws-cloudformation-github-deploy@v1 | |
| with: | |
| name: penny-discord-bot-stack | |
| template: ./deploy/penny-discord-bot-stack.yml | |
| no-fail-on-empty-changeset: "1" | |
| parameter-overrides: >- | |
| TaskDefinition=${{ steps.task-dep.outputs.task-definition-arn }} |