Cache lambda docker layers using buildx
@@ -23,7 +23,7 @@ jobs:
working-directory: backend
run: docker push pythonitalia/pycon-backend:latest
- build-lambda-backend:
+ build-and-push-lambda-backend:
runs-on: ubuntu-20.04
steps:
@@ -33,16 +33,29 @@ jobs:
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- - name: Build the Docker image
- working-directory: backend
- run: docker build . --file Dockerfile.lambda --tag ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.eu-central-1.amazonaws.com/production-pycon-backend:latest
- - name: Publish the image
- working-directory: backend
- run: docker push ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.eu-central-1.amazonaws.com/production-pycon-backend:latest
+ - name: Set up Docker Buildx
+ id: buildx
+ uses: docker/setup-buildx-action@v1
+ - name: Cache Docker layers
+ uses: actions/cache@v2
+ with:
+ path: /tmp/.buildx-cache
+ key: ${{ runner.os }}-buildx-${{ github.sha }}
+ restore-keys: ${{ runner.os }}-buildx-
+ - name: Build and push
+ uses: docker/build-push-action@v2
+ with:
+ context: ./backend
+ file: ./backend/Dockerfile.lambda
+ builder: ${{ steps.buildx.outputs.name }}
+ push: true
+ tags: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.eu-central-1.amazonaws.com/production-pycon-backend:latest
+ cache-from: type=local,src=/tmp/.buildx-cache
+ cache-to: type=local,dest=/tmp/.buildx-cache
terraform:
runs-on: ubuntu-20.04
- needs: [build-lambda-backend]
+ needs: [build-and-push-lambda-backend]
defaults:
run:
working-directory: ./infrastructure
