Skip to content

Commit 405d447

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

File tree

2 files changed

+105
-37
lines changed

2 files changed

+105
-37
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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+
IMAGE_TAG: ${{ github.event.inputs.ompi_version }}
32+
33+
jobs:
34+
detect_image:
35+
runs-on: ubuntu-latest
36+
steps:
37+
- name: Check for valid image
38+
run: |
39+
IMG=${IMAGE_NAME}:${{ inputs.ompi_version }}
40+
docker image rm -f $IMG; docker pull $IMG || true
41+
IMG_CREATED=$(docker inspect --type=image --format '{{.Created}}' $IMG 2>/dev/null)
42+
if [ -z "$IMG_CREATED" ]; then
43+
echo "found=false" >> $GITHUB_OUTPUT
44+
exit 0
45+
fi
46+
47+
IMG_AGE=$(( ($(date +%s) - $(date -d "$IMG_CREATED" +%s)) / (60*60*24) ))
48+
if [ "$IMG_AGE" -lt ${{ github.event.inputs.max_age }} ]; then
49+
echo "found=true" >> $GITHUB_OUTPUT
50+
else
51+
echo "found=false" >> $GITHUB_OUTPUT
52+
fi
53+
outputs:
54+
found: ${{ job.steps.outputs.found }}
55+
56+
build_image:
57+
runs-on: ubuntu-latest
58+
needs: detect_image
59+
if: needs.detect_image.outputs.found == 'false'
60+
steps:
61+
- name: Checkout repository
62+
uses: actions/checkout@v3
63+
64+
- name: Set up Docker Buildx
65+
uses: docker/setup-buildx-action@v2
66+
67+
- name: Log in to GHCR container registry
68+
uses: docker/login-action@v3
69+
with:
70+
registry: ghcr.io
71+
username: ${{ github.actor }}
72+
password: ${{ secrets.GITHUB_TOKEN }}
73+
74+
- name: Bake the bootstrap docker image
75+
uses: docker/bake-action@v5
76+
with:
77+
files: .github/docker-compose.yml
78+
targets: bootstrap
79+
workdir: .
80+
set: |
81+
*.output=type=docker,name=bootstrap
82+
*.cache-from=type=gha,scope=bootstrap/${{ github.event.inputs.ompi_version }}
83+
*.cache-to=type=gha,mode=max,scope=bootstrap/${{ github.event.inputs.ompi_version }}
84+
*.args.OMPI_VERSION=${{ github.event.inputs.ompi_version }}
85+
86+
- name: Bootstrap the environment Dockerfile
87+
run: docker run -v ${GITHUB_WORKSPACE}/.github:/configs bootstrap
88+
89+
- name: Build the environment
90+
uses: docker/bake-action@v5
91+
with:
92+
files: .github/docker-compose.yml
93+
targets: env
94+
workdir: .
95+
pull: true
96+
set: |
97+
*.cache-from=type=gha,scope=env/${{ github.event.inputs.ompi_version }}
98+
*.cache-to=type=gha,mode=max,scope=env/${{ github.event.inputs.ompi_version }}
99+
env.tags=ghcr.io/sandialabs/fenix/env:${{ github.event.inputs.ompi_version }}
100+
env.output=type=registry,name=ghcr.io/sandialabs/fenix/env:${{ github.event.inputs.ompi_version }}

.github/workflows/ci_checks.yaml

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,51 +22,19 @@ jobs:
2222
- name: Checkout repository
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)