-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GHA workflow to build and push Docker images
- Loading branch information
Showing
3 changed files
with
80 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
name: Build and publish Docker images | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- devel | ||
- specky | ||
paths: | ||
- "env/*/Dockerfile" | ||
- "env/*/environment.yml" | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
INCLUDE_DIR: "env/" | ||
REPOSITORY: ${{ github.repository }} | ||
|
||
jobs: | ||
changed-directories: | ||
name: Get last directory name of changed files | ||
runs-on: ubuntu-latest | ||
outputs: | ||
matrix: ${{ steps.changed-files.outputs.all_changed_files }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Get changed files | ||
uses: tj-actions/changed-files@v45 | ||
id: changed-files | ||
with: | ||
matrix: true | ||
dir_names: true | ||
path: ${{ env.INCLUDE_DIR }} | ||
dir_names_include_files: ${{ env.INCLUDE_DIR }} | ||
dir_names_exclude_current_dir: true | ||
|
||
build-and-push-image: | ||
name: Build and push Docker images | ||
runs-on: ubuntu-latest | ||
needs: changed-directories | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
name: ${{ fromJSON(needs.changed-directories.outputs.matrix) }} | ||
platform: [linux/amd64, linux/arm64] | ||
permissions: | ||
contents: read | ||
packages: write | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Extract metadata for Docker | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.REPOSITORY }}/${{ matrix.name }} | ||
tags: | | ||
type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }} | ||
type=ref,event=branch,enable=${{ !endsWith(github.ref, github.event.repository.default_branch) }} | ||
flavor: | | ||
latest=false | ||
- name: Log in to the Container registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: ${{ env.INCLUDE_DIR }}/${{ matrix.name }} | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
platforms: ${{ matrix.platform }} |
File renamed without changes.
File renamed without changes.