Add caching for pulled Docker images #35
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Run pipeline | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| permissions: | |
| contents: write | |
| # Make sure we only ever run one per branch so we don't have issues pushing | |
| # after running the pipeline | |
| concurrency: | |
| group: calkit-run-${{ github.ref }} | |
| cancel-in-progress: false | |
| jobs: | |
| main: | |
| name: Run | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| # For PRs, checkout the head ref to avoid detached HEAD | |
| ref: ${{ github.head_ref || github.ref_name }} | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Configure Git credentials | |
| run: | | |
| git config user.name github-actions[bot] | |
| git config user.email 41898282+github-actions[bot]@users.noreply.github.com | |
| - name: Cache Docker images | |
| uses: actions/cache@v4 | |
| with: | |
| path: /tmp/docker-cache | |
| key: ${{ runner.os }}-docker-images | |
| restore-keys: | | |
| ${{ runner.os }}-docker- | |
| - name: Load Docker cache | |
| run: | | |
| if [ -f /tmp/docker-cache/docker-cache.tar ]; then | |
| echo "Loading Docker images from cache..." | |
| docker load < /tmp/docker-cache/docker-cache.tar | |
| fi | |
| - name: Setup uv | |
| uses: astral-sh/setup-uv@v5 | |
| - name: Install Calkit | |
| run: uv tool install calkit-python | |
| - name: Restore DVC cache | |
| id: cache-dvc-restore | |
| uses: actions/cache/restore@v4 | |
| with: | |
| path: .dvc/cache | |
| key: ${{ runner.os }}-dvc-cache-${{ github.sha }} | |
| restore-keys: | | |
| ${{ runner.os }}-dvc-cache- | |
| - run: calkit config remote-auth | |
| env: | |
| CALKIT_DVC_TOKEN: ${{ secrets.CALKIT_DVC_TOKEN }} | |
| - run: calkit dvc pull | |
| continue-on-error: true | |
| - run: calkit run | |
| - name: Save Docker cache | |
| run: | | |
| mkdir -p /tmp/docker-cache | |
| # Save all non-base images | |
| docker images --format "{{.Repository}}:{{.Tag}}" | grep -v "<none>" | grep -v "ubuntu\|alpine\|debian" > /tmp/docker-images.txt || true | |
| if [ -s /tmp/docker-images.txt ]; then | |
| echo "Saving Docker images to cache..." | |
| docker save $(cat /tmp/docker-images.txt) > /tmp/docker-cache/docker-cache.tar | |
| fi | |
| if: always() | |
| # If running on a PR, push to that branch, else push to main | |
| - run: calkit save -am "Run pipeline" | |
| env: | |
| CALKIT_DVC_TOKEN: ${{ secrets.CALKIT_DVC_TOKEN }} | |
| - name: Save DVC cache | |
| id: cache-dvc-save | |
| uses: actions/cache/save@v4 | |
| with: | |
| path: .dvc/cache | |
| key: ${{ runner.os }}-dvc-cache-${{ github.sha }} |