Skip to content

Save and load docker images locally #2

Save and load docker images locally

Save and load docker images locally #2

name: 'Docker Build and Push'

Check failure on line 1 in .github/workflows/reusable_docker_build.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/reusable_docker_build.yml

Invalid workflow file

(Line: 45, Col: 9): Unexpected value 'attach_workspace', (Line: 47, Col: 9): Unexpected value 'root', (Line: 48, Col: 9): Unexpected value 'paths', (Line: 45, Col: 9): There's not enough info to determine what you meant. Add one of these properties: run, shell, uses, with, working-directory, (Line: 92, Col: 9): Unexpected value 'persist_to_workspace', (Line: 94, Col: 9): Unexpected value 'root', (Line: 95, Col: 9): Unexpected value 'paths', (Line: 92, Col: 9): There's not enough info to determine what you meant. Add one of these properties: run, shell, uses, with, working-directory
on:
workflow_call:
inputs:
dockerfile-repo:
description: 'Repository containing Dockerfile to be built'
default: ${{ github.repository }}
required: false
type: string
dockerfile-path:
description: 'Path to the Dockerfile to be built'
required: true
type: string
docker-image-tag:
description: 'Tag for the Docker image to push'
required: true
type: string
docker-image-savepath:
description: 'Save built image locally to this path (if provided)'
required: false
type: string
docker-image-loadpath:
description: 'Before the build, load this image from the specified path'
required: false
type: string
permissions: {}
jobs:
docker:
name: 'Build and push Docker container'
runs-on: ubuntu-latest
timeout-minutes: 90
steps:
- name: 'Check out Dockerfile'
uses: actions/checkout@v4
with:
repository: ${{ inputs.dockerfile-repo }}
sparse-checkout: ${{ inputs.dockerfile-path }}
sparse-checkout-cone-mode: false
path: .
- attach_workspace:
if: ${{ inputs.docker-image-loadpath != null }}
root: .
paths:
- ${{ inputs.docker-image-loadpath }}
- name: 'Load previously built Docker image'
if: ${{ inputs.docker-image-loadpath != null }}
run: |
docker image load -i ${{ inputs.docker-image-loadpath }}
echo ${{ inputs.docker-image-loadpath }} > .dockerignore
- name: 'Set up Docker buildx'
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3
- name: 'Log into GitHub Container Repository'
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
logout: true
- name: 'Show available images'
run:
docker images
- name: 'Build and Push Docker Container'
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6
with:
context: .
push: ${{ github.ref == 'refs/heads/main' }}
load: true
no-cache: true
file: ${{ inputs.dockerfile-path }}
tags: ${{ inputs.docker-image-tag }}
build-args: |
ARCH=default
BRANCH=main
PETSC_EXTRA_ARGS="--download-eigen --download-metis --download-parmetis --download-mmg --download-parmmg --download-ptscotch"
- name: 'Save Docker Container Locally'
if: ${{ inputs.docker-image-savepath != null }}
run: |
mkdir -p `dirname ${{ inputs.docker-image-savepath }}`
docker image save -o ${{ inputs.docker-image-savepath }} ${{ inputs.docker-image-tag }}
- persist_to_workspace:
if: ${{ inputs.docker-image-savepath != null }}
root: .
paths:
- ${{ inputs.docker-image-savepath }}