Skip to content

Commit 45c3156

Browse files
Only rebuild images on request, or once 14 days old
1 parent 848e50e commit 45c3156

File tree

2 files changed

+103
-39
lines changed

2 files changed

+103
-39
lines changed

.github/workflows/build-env.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: Build Fenix's Environment Image
2+
3+
on:
4+
# workflow_call = called by another workflow
5+
workflow_call:
6+
inputs:
7+
ompi_version:
8+
description: "Open MPI version to build"
9+
type: string
10+
required: true
11+
max_age:
12+
description: "Maximum image age before rebuild, in days"
13+
type: number
14+
required: false
15+
default: 14
16+
# workflow_dispatch = manual trigger
17+
workflow_dispatch:
18+
inputs:
19+
ompi_version:
20+
description: "Open MPI version to build"
21+
type: string
22+
required: true
23+
max_age:
24+
description: "Maximum image age before rebuild, in days"
25+
type: number
26+
required: false
27+
default: 0
28+
29+
env:
30+
IMAGE_NAME: ghcr.io/sandialabs/fenix/env
31+
32+
jobs:
33+
detect_image:
34+
runs-on: ubuntu-latest
35+
outputs:
36+
found: ${{ steps.outputs.found }}
37+
steps:
38+
- name: Check for valid image
39+
run: |
40+
IMG=${{ env.IMAGE_NAME }}:${{ inputs.ompi_version }}
41+
docker image rm -f $IMG; docker pull $IMG || true
42+
IMG_CREATED=$(docker inspect --type=image --format '{{.Created}}' $IMG 2>/dev/null)
43+
if [ -z "$IMG_CREATED" ]; then
44+
echo "found=false" >> $GITHUB_OUTPUT
45+
exit 0
46+
fi
47+
48+
IMG_AGE=$(( ($(date +%s) - $(date -d "$IMG_CREATED" +%s)) / (60*60*24) ))
49+
if [ "$IMG_AGE" -lt ${{ inputs.max_age }} ]; then
50+
echo "found=true" >> $GITHUB_OUTPUT
51+
else
52+
echo "found=false" >> $GITHUB_OUTPUT
53+
fi
54+
55+
build_image:
56+
runs-on: ubuntu-latest
57+
needs: detect_image
58+
if: needs.detect_image.outputs.found == 'false'
59+
steps:
60+
- name: Checkout repository
61+
uses: actions/checkout@v3
62+
63+
- name: Set up Docker Buildx
64+
uses: docker/setup-buildx-action@v2
65+
66+
- name: Log in to GHCR container registry
67+
uses: docker/login-action@v3
68+
with:
69+
registry: ghcr.io
70+
username: ${{ github.actor }}
71+
password: ${{ secrets.GITHUB_TOKEN }}
72+
73+
- name: Bake the bootstrap docker image
74+
uses: docker/bake-action@v5
75+
with:
76+
files: .github/docker-compose.yml
77+
targets: bootstrap
78+
workdir: .
79+
set: |
80+
*.output=type=docker,name=bootstrap
81+
*.cache-from=type=gha,scope=bootstrap/${{ matrix.ompi_version }}
82+
*.cache-to=type=gha,mode=max,scope=bootstrap/${{ matrix.ompi_version }}
83+
*.args.OMPI_VERSION=${{ matrix.ompi_version }}
84+
85+
- name: Bootstrap the environment Dockerfile
86+
run: docker run -v ${GITHUB_WORKSPACE}/.github:/configs bootstrap
87+
88+
- name: Build the environment
89+
uses: docker/bake-action@v5
90+
with:
91+
files: .github/docker-compose.yml
92+
targets: env
93+
workdir: .
94+
pull: true
95+
set: |
96+
*.cache-from=type=gha,scope=env/${{ matrix.ompi_version }}
97+
*.cache-to=type=gha,mode=max,scope=env/${{ matrix.ompi_version }}
98+
env.tags=ghcr.io/sandialabs/fenix/env:${{ matrix.ompi_version }}
99+
env.output=type=registry,name=ghcr.io/sandialabs/fenix/env:${{ matrix.ompi_version }}

.github/workflows/ci_checks.yaml

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -19,54 +19,19 @@ jobs:
1919
- 5.0.3
2020

2121
steps:
22-
- name: Checkout repository
23-
uses: actions/checkout@v3
22+
- name: Build the environment image
23+
uses: ./.github/workflows/build-env
24+
with:
25+
ompi_version: ${{ matrix.ompi_version }}
2426

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

28-
- name: Log in to GHCR container registry
29-
uses: docker/login-action@v3
30-
with:
31-
registry: ghcr.io
32-
username: ${{ github.actor }}
33-
password: ${{ secrets.GITHUB_TOKEN }}
34-
35-
- name: Bake the bootstrap docker image
36-
uses: docker/bake-action@v5
37-
with:
38-
files: .github/docker-compose.yml
39-
targets: bootstrap
40-
workdir: .
41-
set: |
42-
*.output=type=docker,name=bootstrap
43-
*.cache-from=type=gha,scope=bootstrap/${{ matrix.ompi_version }}
44-
*.cache-to=type=gha,mode=max,scope=bootstrap/${{ matrix.ompi_version }}
45-
*.args.OMPI_VERSION=${{ matrix.ompi_version }}
46-
47-
- name: Bootstrap the environment Dockerfile
48-
run: docker run -v ${GITHUB_WORKSPACE}/.github:/configs bootstrap
49-
50-
- name: Build the environment
51-
uses: docker/bake-action@v5
52-
with:
53-
files: .github/docker-compose.yml
54-
targets: env
55-
workdir: .
56-
pull: true
57-
set: |
58-
*.cache-from=type=gha,scope=env/${{ matrix.ompi_version }}
59-
*.cache-to=type=gha,mode=max,scope=env/${{ matrix.ompi_version }}
60-
env.tags=ghcr.io/sandialabs/fenix/env:${{ matrix.ompi_version }}
61-
env.output=type=registry,name=ghcr.io/sandialabs/fenix/env:${{ matrix.ompi_version }}
62-
6330
- name: Build Fenix
6431
uses: docker/bake-action@v5
6532
with:
66-
source: .
6733
files: .github/docker-compose.yml
6834
targets: fenix
69-
workdir: .
7035
set: |
7136
*.output=type=docker,name=fenix
7237
*.args.OMPI_VERSION=${{ matrix.ompi_version }}

0 commit comments

Comments
 (0)