GitHub Action Docker image cache

Here’s a working Github Actions workflow with Docker layer caching and image build in separate step for transparency:

name: Fly

on:
  push:
    branches:
      - main

env:
  FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}

jobs:
  fly_deploy:
    name: Deploy with Fly

    runs-on: ubuntu-20.04

    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Setup Docker layer caching
        uses: satackey/action-docker-layer-caching@v0.0.11
        continue-on-error: true

      - name: Build app Docker image
        run: docker build . -t myapp

      - name: Deploy with Fly
        uses: superfly/flyctl-actions@1.1
        with:
          args: "deploy -i myapp"

It has cut my Elixir + Rust + Node multistage builds from ~6min to ~2-3min. The cache restoration step does take ~50s so things could be better if Github one day does this in native way.

1 Like