-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
name: Docker build | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: [ "master", "main", "maint/*", "gha-docker-build" ] | ||
tags: "*" | ||
pull_request: | ||
branches: [ "master", "main", "maint/*" ] | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }} | ||
FORCE_COLOR: true | ||
|
||
jobs: | ||
build-container: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Docker buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Log into registry ${{ env.REGISTRY }} | ||
if: github.event_name != 'pull_request' | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Extract Docker metadata | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: . | ||
push: ${{ github.event_name != 'pull_request' }} | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
cache-from: | | ||
type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:master | ||
type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.TARGET_BRANCH }} | ||
type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.tags[0] }} | ||
cache-to: type=inline | ||
env: | ||
TARGET_BRANCH: ${{ github.base_ref || github.ref_name }} |