From 3d99e2d45677823f42f63c1bffbd295010c4ca84 Mon Sep 17 00:00:00 2001 From: Benjamin Eskola Date: Fri, 11 Aug 2023 14:14:46 +0100 Subject: [PATCH] Use Github Actions cache for docker directly Faster and more reliable than exporting and importing --- .github/workflows/deploy-environment.yml | 28 ++++++++---------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/.github/workflows/deploy-environment.yml b/.github/workflows/deploy-environment.yml index f9034a8..bae5986 100644 --- a/.github/workflows/deploy-environment.yml +++ b/.github/workflows/deploy-environment.yml @@ -37,22 +37,11 @@ jobs: id: login-ecr uses: aws-actions/amazon-ecr-login@v1 - - name: Setup docker cache - id: cache - uses: actions/cache@v2 - with: - path: docker-cache - key: ${{ runner.os }}-docker-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-docker- + - name: Expose GitHub Runtime for Docker build + uses: crazy-max/ghaction-github-runtime@v2 - - name: Load docker cache - run: | - if [ -d "docker-cache" ]; then - cat docker-cache/x* > paapi.tar - docker load < paapi.tar - rm -rf docker-cache - fi + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 - name: Build, tag, and push ${{ inputs.environment-name }} image to Amazon ECR id: build-image @@ -64,11 +53,12 @@ jobs: # Build a docker container and # push it to ECR so that it can # be deployed to ECS. - DOCKER_BUILDKIT=1 docker build -t paapi:$IMAGE_TAG -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfile.production . + DOCKER_BUILDKIT=1 docker buildx build \ + --cache-to type=gha,mode=max \ + --cache-from type=gha \ + --load \ + -t paapi:$IMAGE_TAG -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfile.production . docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG - docker save paapi:$IMAGE_TAG $(docker history -q paapi:$IMAGE_TAG | awk '!//{print}') >paapi.tar - mkdir docker-cache - split -b 5G paapi.tar docker-cache/x echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >>$GITHUB_OUTPUT - name: Download task definition for db_migrate and strip unused properties