Update 2021-11-29

Recently we create more PRs, notice that there are a lot of redundant steps (env setup before triggering checks, etc). Found out you can cache steps in GitHub Actions, so I did some research. Got it working and turns out I reduce at least 60% actions time for a large docker image build (since only the later RUN directives are changed more frequently). For pipenv it shaved off 1 minute 18 seconds. Pretty neat!

pipenv cache

# https://github.com/actions/setup-python#caching-packages-dependencies
- uses: actions/[email protected]
    python-version: '3.9'
    cache: 'pipenv'

docker build cache

- name: Set up Docker Buildx
  uses: docker/[email protected]

- name: Add IMAGE_TAG to env
  run: echo "IMAGE_TAG=`echo ${GITHUB_SHA::7}`" >> $GITHUB_ENV

- name: Build, tag, and push image to Amazon ECR
  uses: docker/[email protected]
    IMAGE_NAME: service/app
    context: .
    push: true
    tags: ${{ env.IMAGE_NAME }}:latest,${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
    cache-from: type=gha
    cache-to: type=gha,mode=max