Skip to content

Commit 51f7168

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

File tree

2 files changed

+96
-38
lines changed

2 files changed

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

.github/workflows/ci_checks.yaml

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

2121
steps:
22-
- name: Checkout repository
22+
- name: Checkout
2323
uses: actions/checkout@v3
2424

25-
- name: Set up Docker Buildx
26-
uses: docker/setup-buildx-action@v2
27-
28-
- name: Log in to GHCR container registry
29-
uses: docker/login-action@v3
25+
- name: Build the environment image
26+
uses: ./.github/workflows/build-env
3027
with:
31-
registry: ghcr.io
32-
username: ${{ github.actor }}
33-
password: ${{ secrets.GITHUB_TOKEN }}
28+
ompi_version: ${{ matrix.ompi_version }}
29+
token: ${{ secrets.GITHUB_TOKEN }}
3430

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 }}
31+
- name: Set up Docker Buildx
32+
uses: docker/setup-buildx-action@v2
6233

6334
- name: Build Fenix
6435
uses: docker/bake-action@v5
6536
with:
66-
source: .
6737
files: .github/docker-compose.yml
6838
targets: fenix
69-
workdir: .
7039
set: |
7140
*.output=type=docker,name=fenix
7241
*.args.OMPI_VERSION=${{ matrix.ompi_version }}

0 commit comments

Comments
 (0)