From 50cb9f6e7da910e67bf1ef75201b98c0b26ed9f2 Mon Sep 17 00:00:00 2001 From: Kelly Sovacool Date: Thu, 26 Sep 2024 15:11:51 -0400 Subject: [PATCH] ci: set up action to build docker images automagically --- .github/workflows/docker.yml | 64 ++++++++++++++++++++++++++++++++++++ docker/wes_base/meta.yml | 4 +++ 2 files changed, 68 insertions(+) create mode 100644 .github/workflows/docker.yml create mode 100644 docker/wes_base/meta.yml diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..de1d9f8 --- /dev/null +++ b/.github/workflows/docker.yml @@ -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\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/action-read-yaml@1.0.0 + 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'] }} diff --git a/docker/wes_base/meta.yml b/docker/wes_base/meta.yml new file mode 100644 index 0000000..5a252c9 --- /dev/null +++ b/docker/wes_base/meta.yml @@ -0,0 +1,4 @@ +dockerhub_namespace: nciccbr +image_name: ccbr_wes_base +version: 1.1.0 +container: "$(dockerhub_namespace)/$(image_name):$(version)"