Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rebuild images only when needed #73

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions .github/workflows/build-env/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: Build Environment Image
description: Build the Open MPI environment image for Fenix

inputs:
ompi_version:
description: "Open MPI version to build"
type: string
required: true
token:
description: "GitHub token for logging into GHCR"
type: string
required: true
max_age:
description: "Maximum image age before rebuild, in days"
type: number
required: false
default: 14

runs:
using: "composite"
steps:
- name: Check for valid image
shell: bash
run: |
set +e
IMG=ghcr.io/sandialabs/fenix/env:${{ inputs.ompi_version }}
echo "IMG=$IMG" >> $GITHUB_ENV

docker image rm -f $IMG 2>/dev/null
docker pull $IMG >/dev/null 2>&1
IMG_CREATED=$(docker inspect --type=image --format '{{.Created}}' $IMG 2>/dev/null)
if [ -z "$IMG_CREATED" ]; then
echo "Did not find image $IMG"
echo "found=false" >> $GITHUB_ENV
exit 0
fi

IMG_AGE=$(( ($(date +%s) - $(date -d "$IMG_CREATED" +%s)) / (60*60*24) ))
echo "Found image $IMG created $IMG_AGE days ago"
if [ "$IMG_AGE" -lt ${{ inputs.max_age }} ]; then
echo "Image is valid, skipping build"
echo "found=true" >> $GITHUB_ENV
else
echo "Image is too old, rebuilding"
echo "found=false" >> $GITHUB_ENV
fi

#Remaining actions only run if we didn't find a valid image.
- name: Checkout repository
if: env.found != 'true'
uses: actions/checkout@v3

- name: Set up Docker Buildx
if: env.found != 'true'
uses: docker/setup-buildx-action@v2

- name: Log in to GHCR container registry
if: env.found != 'true'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ inputs.token }}

- name: Bake the bootstrap docker image
if: env.found != 'true'
uses: docker/bake-action@v5
with:
files: .github/docker-compose.yml
targets: bootstrap
workdir: .
set: |
*.output=type=docker,name=bootstrap
*.args.OMPI_VERSION=${{ inputs.ompi_version }}

- name: Bootstrap the environment Dockerfile
if: env.found != 'true'
shell: bash
run: docker run -v ${GITHUB_WORKSPACE}/.github:/configs bootstrap

- name: Build the environment
if: env.found != 'true'
uses: docker/bake-action@v5
with:
files: .github/docker-compose.yml
targets: env
workdir: .
pull: true
set: |
env.tags=ghcr.io/sandialabs/fenix/env:${{ inputs.ompi_version }}
env.output=type=registry,name=ghcr.io/sandialabs/fenix/env:${{ inputs.ompi_version }}
53 changes: 9 additions & 44 deletions .github/workflows/ci_checks.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
name: Build & Test

on:
push:
pull_request_target:
types:
- opened
- synchronized
- edited
pull_request:

jobs:
test:
Expand All @@ -19,54 +14,24 @@ jobs:
- 5.0.3

steps:
- name: Checkout repository
- name: Checkout
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log in to GHCR container registry
uses: docker/login-action@v3
- name: Build the environment image
uses: ./.github/workflows/build-env
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
ompi_version: ${{ matrix.ompi_version }}
token: ${{ secrets.GITHUB_TOKEN }}
max_age: 14 #days

- name: Bake the bootstrap docker image
uses: docker/bake-action@v5
with:
files: .github/docker-compose.yml
targets: bootstrap
workdir: .
set: |
*.output=type=docker,name=bootstrap
*.cache-from=type=gha,scope=bootstrap/${{ matrix.ompi_version }}
*.cache-to=type=gha,mode=max,scope=bootstrap/${{ matrix.ompi_version }}
*.args.OMPI_VERSION=${{ matrix.ompi_version }}

- name: Bootstrap the environment Dockerfile
run: docker run -v ${GITHUB_WORKSPACE}/.github:/configs bootstrap

- name: Build the environment
uses: docker/bake-action@v5
with:
files: .github/docker-compose.yml
targets: env
workdir: .
pull: true
set: |
*.cache-from=type=gha,scope=env/${{ matrix.ompi_version }}
*.cache-to=type=gha,mode=max,scope=env/${{ matrix.ompi_version }}
env.tags=ghcr.io/sandialabs/fenix/env:${{ matrix.ompi_version }}
env.output=type=registry,name=ghcr.io/sandialabs/fenix/env:${{ matrix.ompi_version }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build Fenix
uses: docker/bake-action@v5
with:
source: .
files: .github/docker-compose.yml
targets: fenix
workdir: .
set: |
*.output=type=docker,name=fenix
*.args.OMPI_VERSION=${{ matrix.ompi_version }}
Expand Down
Loading