From 5e9caf2fd3d55aefe03ed0fcea6e19bd14dc8158 Mon Sep 17 00:00:00 2001 From: shgtkshruch Date: Sat, 31 Jul 2021 21:03:56 +0900 Subject: [PATCH] Cache docker layer https://github.com/docker/build-push-action/pull/406 --- .github/workflows/deploy.yml | 400 +++++++++++++++++------------------ 1 file changed, 200 insertions(+), 200 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index afdc7ee..fb66a97 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -57,7 +57,7 @@ jobs: file: ./Dockerfile.prod target: bundle cache-from: type=local,src=/tmp/.buildx-cache/bundle - cache-to: type=local,dest=/tmp/.buildx-cache-new/bundle + cache-to: type=local,dest=/tmp/.buildx-cache-new/bundle,mode=max - name: Build npm stage uses: docker/build-push-action@v2 @@ -66,7 +66,7 @@ jobs: file: ./Dockerfile.prod target: npm cache-from: type=local,src=/tmp/.buildx-cache/npm - cache-to: type=local,dest=/tmp/.buildx-cache-new/npm + cache-to: type=local,dest=/tmp/.buildx-cache-new/npm,mode=max - name: Build docker image id: docker-build @@ -136,201 +136,201 @@ jobs: type=local,src=/tmp/.buildx-cache-new/npm cache-to: type=local,dest=/tmp/.buildx-cache-new - maintenance-on: - if: ${{ always() && github.event.inputs.maintenance == 'true'}} - needs: [build-rails-image, build-nuxt-image] - environment: - name: ${{ github.event.inputs.env }} - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v1 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: ap-northeast-1 - - - name: Setup AWS Copilot - run: | - curl -Lo copilot-linux https://github.com/aws/copilot-cli/releases/download/${{ env.COPILOT_VERSION }}/copilot-linux - chmod +x copilot-linux - sudo mv copilot-linux /usr/local/bin/copilot - - - name: Trun on maintenance mode - run: | - copilot svc exec \ - --app chronos \ - --env ${{ github.event.inputs.env }} \ - --name rails \ - --command 'bin/maintenance on' - - rails-migration: - if: ${{ always() && github.event.inputs.rails == 'true' }} - needs: [maintenance-on] - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v1 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: ap-northeast-1 - - - name: Login to Amazon ECR - id: login-ecr - uses: aws-actions/amazon-ecr-login@v1 - - - name: Setup AWS Copilot - run: | - curl -Lo copilot-linux https://github.com/aws/copilot-cli/releases/download/${{ env.COPILOT_VERSION }}/copilot-linux - chmod +x copilot-linux - sudo mv copilot-linux /usr/local/bin/copilot - - - name: Run migration - run: | - copilot task run \ - --image ${{ steps.login-ecr.outputs.registry }}/chronos/rails:${{ github.sha }} \ - --command 'bin/rails db:prepare' \ - --app chronos \ - --env ${{ github.event.inputs.env }} \ - --env-vars RAILS_LOG_TO_STDOUT=true,RAILS_ENV=production \ - --secrets RAILS_MASTER_KEY=/copilot/chronos/${{ github.event.inputs.env }}/secrets/RAILS_MASTER_KEY \ - --follow - - deploy-services: - if: ${{ always() && github.event.inputs.rails == 'true' }} - needs: [rails-migration] - runs-on: ubuntu-latest - timeout-minutes: 30 - strategy: - matrix: - service: [rails, admin-rails] - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v1 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: ap-northeast-1 - - - name: Setup AWS Copilot - run: | - curl -Lo copilot-linux https://github.com/aws/copilot-cli/releases/download/${{ env.COPILOT_VERSION }}/copilot-linux - chmod +x copilot-linux - sudo mv copilot-linux /usr/local/bin/copilot - - - name: Replace docker image tag to github sha - run: | - manifest_path="copilot/${{ matrix.service }}/manifest.yml" - sed -i -e 's//${{ github.sha }}/' $manifest_path - - - name: Deploy Rails service - run: | - copilot svc deploy \ - --app chronos \ - --env ${{ github.event.inputs.env }} \ - --name ${{ matrix.service }} - - deploy-jobs: - if: ${{ always() && github.event.inputs.rails == 'true' }} - needs: [rails-migration] - runs-on: ubuntu-latest - strategy: - matrix: - job: [slack-notification, slack-notification-30] - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v1 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: ap-northeast-1 - - - name: Setup AWS Copilot - run: | - curl -Lo copilot-linux https://github.com/aws/copilot-cli/releases/download/${{ env.COPILOT_VERSION }}/copilot-linux - chmod +x copilot-linux - sudo mv copilot-linux /usr/local/bin/copilot - - - name: Replace docker image tag to github sha - run: | - manifest_path="copilot/${{ matrix.job }}/manifest.yml" - sed -i -e 's//${{ github.sha }}/' $manifest_path - - - name: Deploy scheduled job - run: | - copilot job deploy \ - --app chronos \ - --env ${{ github.event.inputs.env }} \ - --name ${{ matrix.job }} - - deploy-nuxt: - if: ${{ always() && github.event.inputs.nuxt == 'true' }} - needs: [rails-migration] - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v1 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: ap-northeast-1 - - - name: Setup AWS Copilot - run: | - curl -Lo copilot-linux https://github.com/aws/copilot-cli/releases/download/${{ env.COPILOT_VERSION }}/copilot-linux - chmod +x copilot-linux - sudo mv copilot-linux /usr/local/bin/copilot - - - name: Deploy frontend service - run: | - copilot svc deploy \ - --app chronos \ - --env ${{ github.event.inputs.env }} \ - --name frontend - - maintenance-off: - if: ${{ always() && github.event.inputs.maintenance == 'true' }} - needs: [deploy-services, deploy-jobs, deploy-nuxt] - environment: - name: ${{ github.event.inputs.env }} - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v1 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: ap-northeast-1 - - - name: Setup AWS Copilot - run: | - curl -Lo copilot-linux https://github.com/aws/copilot-cli/releases/download/${{ env.COPILOT_VERSION }}/copilot-linux - chmod +x copilot-linux - sudo mv copilot-linux /usr/local/bin/copilot - - - name: Turn off maintenance mode - run: | - copilot svc exec \ - --app chronos \ - --env ${{ github.event.inputs.env }} \ - --name rails \ - --command 'bin/maintenance off' + # maintenance-on: + # if: ${{ always() && github.event.inputs.maintenance == 'true'}} + # needs: [build-rails-image, build-nuxt-image] + # environment: + # name: ${{ github.event.inputs.env }} + # runs-on: ubuntu-latest + # steps: + # - name: Checkout + # uses: actions/checkout@v2 + + # - name: Configure AWS Credentials + # uses: aws-actions/configure-aws-credentials@v1 + # with: + # aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + # aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + # aws-region: ap-northeast-1 + + # - name: Setup AWS Copilot + # run: | + # curl -Lo copilot-linux https://github.com/aws/copilot-cli/releases/download/${{ env.COPILOT_VERSION }}/copilot-linux + # chmod +x copilot-linux + # sudo mv copilot-linux /usr/local/bin/copilot + + # - name: Trun on maintenance mode + # run: | + # copilot svc exec \ + # --app chronos \ + # --env ${{ github.event.inputs.env }} \ + # --name rails \ + # --command 'bin/maintenance on' + + # rails-migration: + # if: ${{ always() && github.event.inputs.rails == 'true' }} + # needs: [maintenance-on] + # runs-on: ubuntu-latest + # steps: + # - name: Checkout + # uses: actions/checkout@v2 + + # - name: Configure AWS Credentials + # uses: aws-actions/configure-aws-credentials@v1 + # with: + # aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + # aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + # aws-region: ap-northeast-1 + + # - name: Login to Amazon ECR + # id: login-ecr + # uses: aws-actions/amazon-ecr-login@v1 + + # - name: Setup AWS Copilot + # run: | + # curl -Lo copilot-linux https://github.com/aws/copilot-cli/releases/download/${{ env.COPILOT_VERSION }}/copilot-linux + # chmod +x copilot-linux + # sudo mv copilot-linux /usr/local/bin/copilot + + # - name: Run migration + # run: | + # copilot task run \ + # --image ${{ steps.login-ecr.outputs.registry }}/chronos/rails:${{ github.sha }} \ + # --command 'bin/rails db:prepare' \ + # --app chronos \ + # --env ${{ github.event.inputs.env }} \ + # --env-vars RAILS_LOG_TO_STDOUT=true,RAILS_ENV=production \ + # --secrets RAILS_MASTER_KEY=/copilot/chronos/${{ github.event.inputs.env }}/secrets/RAILS_MASTER_KEY \ + # --follow + + # deploy-services: + # if: ${{ always() && github.event.inputs.rails == 'true' }} + # needs: [rails-migration] + # runs-on: ubuntu-latest + # timeout-minutes: 30 + # strategy: + # matrix: + # service: [rails, admin-rails] + # steps: + # - name: Checkout + # uses: actions/checkout@v2 + + # - name: Configure AWS Credentials + # uses: aws-actions/configure-aws-credentials@v1 + # with: + # aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + # aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + # aws-region: ap-northeast-1 + + # - name: Setup AWS Copilot + # run: | + # curl -Lo copilot-linux https://github.com/aws/copilot-cli/releases/download/${{ env.COPILOT_VERSION }}/copilot-linux + # chmod +x copilot-linux + # sudo mv copilot-linux /usr/local/bin/copilot + + # - name: Replace docker image tag to github sha + # run: | + # manifest_path="copilot/${{ matrix.service }}/manifest.yml" + # sed -i -e 's//${{ github.sha }}/' $manifest_path + + # - name: Deploy Rails service + # run: | + # copilot svc deploy \ + # --app chronos \ + # --env ${{ github.event.inputs.env }} \ + # --name ${{ matrix.service }} + + # deploy-jobs: + # if: ${{ always() && github.event.inputs.rails == 'true' }} + # needs: [rails-migration] + # runs-on: ubuntu-latest + # strategy: + # matrix: + # job: [slack-notification, slack-notification-30] + # steps: + # - name: Checkout + # uses: actions/checkout@v2 + + # - name: Configure AWS Credentials + # uses: aws-actions/configure-aws-credentials@v1 + # with: + # aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + # aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + # aws-region: ap-northeast-1 + + # - name: Setup AWS Copilot + # run: | + # curl -Lo copilot-linux https://github.com/aws/copilot-cli/releases/download/${{ env.COPILOT_VERSION }}/copilot-linux + # chmod +x copilot-linux + # sudo mv copilot-linux /usr/local/bin/copilot + + # - name: Replace docker image tag to github sha + # run: | + # manifest_path="copilot/${{ matrix.job }}/manifest.yml" + # sed -i -e 's//${{ github.sha }}/' $manifest_path + + # - name: Deploy scheduled job + # run: | + # copilot job deploy \ + # --app chronos \ + # --env ${{ github.event.inputs.env }} \ + # --name ${{ matrix.job }} + + # deploy-nuxt: + # if: ${{ always() && github.event.inputs.nuxt == 'true' }} + # needs: [rails-migration] + # runs-on: ubuntu-latest + # steps: + # - name: Checkout + # uses: actions/checkout@v2 + + # - name: Configure AWS Credentials + # uses: aws-actions/configure-aws-credentials@v1 + # with: + # aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + # aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + # aws-region: ap-northeast-1 + + # - name: Setup AWS Copilot + # run: | + # curl -Lo copilot-linux https://github.com/aws/copilot-cli/releases/download/${{ env.COPILOT_VERSION }}/copilot-linux + # chmod +x copilot-linux + # sudo mv copilot-linux /usr/local/bin/copilot + + # - name: Deploy frontend service + # run: | + # copilot svc deploy \ + # --app chronos \ + # --env ${{ github.event.inputs.env }} \ + # --name frontend + + # maintenance-off: + # if: ${{ always() && github.event.inputs.maintenance == 'true' }} + # needs: [deploy-services, deploy-jobs, deploy-nuxt] + # environment: + # name: ${{ github.event.inputs.env }} + # runs-on: ubuntu-latest + # steps: + # - name: Checkout + # uses: actions/checkout@v2 + + # - name: Configure AWS Credentials + # uses: aws-actions/configure-aws-credentials@v1 + # with: + # aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + # aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + # aws-region: ap-northeast-1 + + # - name: Setup AWS Copilot + # run: | + # curl -Lo copilot-linux https://github.com/aws/copilot-cli/releases/download/${{ env.COPILOT_VERSION }}/copilot-linux + # chmod +x copilot-linux + # sudo mv copilot-linux /usr/local/bin/copilot + + # - name: Turn off maintenance mode + # run: | + # copilot svc exec \ + # --app chronos \ + # --env ${{ github.event.inputs.env }} \ + # --name rails \ + # --command 'bin/maintenance off'