Skip to content

Commit f5447ef

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

File tree

2 files changed

+100
-44
lines changed

2 files changed

+100
-44
lines changed
+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
set +e
26+
IMG=ghcr.io/sandialabs/fenix/env:${{ inputs.ompi_version }}
27+
echo "IMG=$IMG" >> $GITHUB_ENV
28+
29+
docker image rm -f $IMG 2>/dev/null
30+
docker pull $IMG >/dev/null 2>&1
31+
IMG_CREATED=$(docker inspect --type=image --format '{{.Created}}' $IMG 2>/dev/null)
32+
if [ -z "$IMG_CREATED" ]; then
33+
echo "Did not find image $IMG"
34+
echo "found=false" >> $GITHUB_ENV
35+
exit 0
36+
fi
37+
38+
IMG_AGE=$(( ($(date +%s) - $(date -d "$IMG_CREATED" +%s)) / (60*60*24) ))
39+
echo "Found image $IMG created $IMG_AGE days ago"
40+
if [ "$IMG_AGE" -lt ${{ inputs.max_age }} ]; then
41+
echo "Image is valid, skipping build"
42+
echo "found=true" >> $GITHUB_ENV
43+
else
44+
echo "Image is too old, rebuilding"
45+
echo "found=false" >> $GITHUB_ENV
46+
fi
47+
48+
#Remaining actions only run if we didn't find a valid image.
49+
- name: Checkout repository
50+
if: env.found != 'true'
51+
uses: actions/checkout@v3
52+
53+
- name: Set up Docker Buildx
54+
if: env.found != 'true'
55+
uses: docker/setup-buildx-action@v2
56+
57+
- name: Log in to GHCR container registry
58+
if: env.found != 'true'
59+
uses: docker/login-action@v3
60+
with:
61+
registry: ghcr.io
62+
username: ${{ github.actor }}
63+
password: ${{ inputs.token }}
64+
65+
- name: Bake the bootstrap docker image
66+
if: env.found != 'true'
67+
uses: docker/bake-action@v5
68+
with:
69+
files: .github/docker-compose.yml
70+
targets: bootstrap
71+
workdir: .
72+
set: |
73+
*.output=type=docker,name=bootstrap
74+
*.args.OMPI_VERSION=${{ inputs.ompi_version }}
75+
76+
- name: Bootstrap the environment Dockerfile
77+
if: env.found != 'true'
78+
shell: bash
79+
run: docker run -v ${GITHUB_WORKSPACE}/.github:/configs bootstrap
80+
81+
- name: Build the environment
82+
if: env.found != 'true'
83+
uses: docker/bake-action@v5
84+
with:
85+
files: .github/docker-compose.yml
86+
targets: env
87+
workdir: .
88+
pull: true
89+
set: |
90+
env.tags=ghcr.io/sandialabs/fenix/env:${{ inputs.ompi_version }}
91+
env.output=type=registry,name=ghcr.io/sandialabs/fenix/env:${{ inputs.ompi_version }}

.github/workflows/ci_checks.yaml

+9-44
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
name: Build & Test
22

33
on:
4-
push:
5-
pull_request_target:
6-
types:
7-
- opened
8-
- synchronized
9-
- edited
4+
pull_request:
105

116
jobs:
127
test:
@@ -19,54 +14,24 @@ jobs:
1914
- 5.0.3
2015

2116
steps:
22-
- name: Checkout repository
17+
- name: Checkout
2318
uses: actions/checkout@v3
2419

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
20+
- name: Build the environment image
21+
uses: ./.github/workflows/build-env
3022
with:
31-
registry: ghcr.io
32-
username: ${{ github.actor }}
33-
password: ${{ secrets.GITHUB_TOKEN }}
23+
ompi_version: ${{ matrix.ompi_version }}
24+
token: ${{ secrets.GITHUB_TOKEN }}
25+
max_age: 14 #days
3426

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

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)