Skip to content

Commit 03f6cd7

Browse files
authored
CI: Build docker images in GHA, store cache inline and push to GHCR (#3380)
This PR is a potential model for nipreps using GHA to build Docker images. The latest build (from a previous commit's cache) took 2 minutes, including checkout, build and push. If the cache needs rebuilding, it's <10 minutes. This is a vast improvement from Circle all on it's own. I will make a separate PR to start triggering Circle builds from GHA after build. I would like to get to a model of: ```mermaid graph LR; subgraph GitHub; test & build end subgraph Circle build --> ds005 & ds054 & ds210 end subgraph gh2["GitHub"] test & ds005 & ds054 & ds210 --> deploy end ``` Where Circle runs anything where we want inspectable artifacts and nothing else. For SDCflows, it would be tests again, but with artifact saving turned on.
2 parents 52eee57 + 79ee1b6 commit 03f6cd7

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

.circleci/config.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ _check_skip_job: &check_skip_job
4747
cd /tmp/src/fmriprep
4848
COMMIT_MSG="$(git show -s --format=%s)"
4949
DOCBUILD="$(echo ${COMMIT_MSG} | grep -i -E '^docs?(\(\w+\))?:')"
50+
SKIP_ALL="$(echo ${COMMIT_MSG} | grep -i -E '\[skipcircle\]')"
5051
SKIP_PYTEST="$(echo ${COMMIT_MSG} | grep -i -E '\[skip[ _]?tests\]')"
5152
SKIP_DS005="$(echo ${COMMIT_MSG} | grep -i -E '\[skip[ _]?ds005\]' )"
5253
SKIP_DS054="$(echo ${COMMIT_MSG} | grep -i -E '\[skip[ _]?ds054\]' )"
@@ -62,6 +63,9 @@ _check_skip_job: &check_skip_job
6263
elif [[ -n "$DOCSBUILD" ]]; then # always try to skip docs builds
6364
echo "Only docs build"
6465
circleci step halt
66+
elif [ -n "$SKIP_ALL" ]; then
67+
echo "Skipping all!"
68+
circleci step halt
6569
elif [ -n "$CHECK_PYTEST" -a -n "$SKIP_PYTEST" ]; then
6670
echo "Skipping pytest"
6771
circleci step halt

.github/workflows/docker.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Docker build
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches: [ "master", "main", "maint/*", "gha-docker-build" ]
7+
tags: "*"
8+
pull_request:
9+
branches: [ "master", "main", "maint/*" ]
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref }}
13+
cancel-in-progress: true
14+
15+
env:
16+
REGISTRY: ghcr.io
17+
IMAGE_NAME: ${{ github.repository }}
18+
FORCE_COLOR: true
19+
20+
jobs:
21+
build-container:
22+
runs-on: ubuntu-latest
23+
permissions:
24+
contents: read
25+
packages: write
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@v4
29+
30+
- name: Setup Docker buildx
31+
uses: docker/setup-buildx-action@v3
32+
33+
- name: Log into registry ${{ env.REGISTRY }}
34+
if: github.event_name != 'pull_request'
35+
uses: docker/login-action@v3
36+
with:
37+
registry: ${{ env.REGISTRY }}
38+
username: ${{ github.actor }}
39+
password: ${{ secrets.GITHUB_TOKEN }}
40+
41+
- name: Extract Docker metadata
42+
id: meta
43+
uses: docker/metadata-action@v5
44+
with:
45+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
46+
47+
- name: Build and push Docker image
48+
uses: docker/build-push-action@v6
49+
with:
50+
context: .
51+
push: ${{ github.event_name != 'pull_request' }}
52+
tags: ${{ steps.meta.outputs.tags }}
53+
labels: ${{ steps.meta.outputs.labels }}
54+
cache-from: |
55+
type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:master
56+
type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.TARGET_BRANCH }}
57+
type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.tags[0] }}
58+
cache-to: type=inline
59+
env:
60+
TARGET_BRANCH: ${{ github.base_ref || github.ref_name }}

0 commit comments

Comments
 (0)