Skip to content

Commit a0e1723

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

File tree

2 files changed

+89
-38
lines changed

2 files changed

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

.github/workflows/ci_checks.yaml

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -19,54 +19,22 @@ 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 }}
3429

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

6333
- name: Build Fenix
6434
uses: docker/bake-action@v5
6535
with:
66-
source: .
6736
files: .github/docker-compose.yml
6837
targets: fenix
69-
workdir: .
7038
set: |
7139
*.output=type=docker,name=fenix
7240
*.args.OMPI_VERSION=${{ matrix.ompi_version }}

0 commit comments

Comments
 (0)