Skip to content

Commit

Permalink
Add GHA workflow to build and push Docker images
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterius committed Oct 3, 2024
1 parent 159afe1 commit 2e35b81
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions .github/workflows/build-images.yml
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.

0 comments on commit 2e35b81

Please sign in to comment.