Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: set up action to build docker images automagically #115

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: docker

on:
push:
branches:
- main
paths:
- "docker/**"
pull_request:
branches:
- main
paths:
- "docker/**"
workflow_dispatch:

jobs:
generate-matrix:
runs-on: ubuntu-latest
outputs:
matrix-metadata: ${{ steps.metadata.outputs.matrix }}
steps:
- uses: hellofresh/action-changed-files@v3
id: metadata
with:
pattern: docker/(?P<image_dir>\w+)/.*
default-patterns: |
meta.yml
Dockerfile

update-docker:
needs: [generate-matrix]
strategy:
matrix: ${{ fromJson(needs.generate-matrix.outputs.matrix-metadata) }}
if: ${{ fromJson(needs.generate-matrix.outputs.matrix-metadata).include[0] }} # skip if the matrix is empty!
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pietrobolcato/[email protected]
id: metadata
with:
config: ${{ github.workspace }}/docker/${{ matrix.image_dir }}/meta.yml
- name: Get date
id: date
run: |
echo "DATE=$(date +"%Y-%m-%d")" >> $GITHUB_OUTPUT
- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v4
# only try building & pushing the container if parsing the metadata worked
if: ${{ steps.metadata.outputs['container'] != '' }}
with:
context: docker/${{ matrix.image_dir }}
# only push container to docker hub if not triggered from a PR
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.metadata.outputs['container'] }}
build-args: |
BUILD_DATE=${{ steps.date.outputs.DATE }}
BUILD_TAG=${{ steps.metadata.outputs['version'] }}
REPONAME=${{ steps.metadata.outputs['image_name'] }}
4 changes: 4 additions & 0 deletions docker/wes_base/meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dockerhub_namespace: nciccbr
image_name: ccbr_wes_base
version: 1.1.0
container: "$(dockerhub_namespace)/$(image_name):$(version)"
Loading