-
Notifications
You must be signed in to change notification settings - Fork 3
64 lines (60 loc) · 2.64 KB
/
build-docker-meta.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
name: build-docker-meta
run-name: ${{ inputs.context_dir }}
on:
workflow_dispatch:
inputs:
context_dir:
type: string
description: path to the directory containing the Dockerfile and meta.yml file (e.g. common/ccbr_chipseeker/)
required: true
push:
type: boolean
description: Push to DockerHub (uncheck to only build the container without pushing)
required: true
default: true
jobs:
build-docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pietrobolcato/[email protected]
id: metadata
with:
config: ${{ github.workspace }}/${{ github.event.inputs.context_dir }}/meta.yml
- name: Login to DockerHub
if: ${{ github.event.inputs.push == 'true' }}
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Prepare build-time variables
id: vars
run: |
echo "DATE=$(date +"%Y-%m-%d")" >> "$GITHUB_OUTPUT"
if [ ! -f ${{ github.event.inputs.context_dir }}/Dockerfile ] ; then
echo "ERROR: Dockerfile not found: ${{ github.event.inputs.context_dir }}/Dockerfile"
exit 1
fi
# for Docker Hub Description
echo " # ${{ github.repository }} ${{ steps.metadata.outputs['image_name'] }}\n" > tmp_README.md
echo "Dockerfile source: https://github.com/${{ github.repository }}/blob/${{ github.sha }}/${{ github.event.inputs.context_dir }}/Dockerfile\n" >> tmp_README.md
- 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: ${{ github.event.inputs.context_dir }}
push: ${{ github.event.inputs.push }}
tags: ${{ steps.metadata.outputs['container'] }}
build-args: |
BUILD_DATE=${{ steps.vars.outputs.DATE }}
BUILD_TAG=${{ steps.metadata.outputs['version'] }}
REPONAME=${{ steps.metadata.outputs['image_name'] }}
- name: Update Docker Hub Description
if: ${{ (github.event.inputs.push == 'true') && (steps.build-and-push.outcome == 'success') }}
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
repository: ${{ steps.metadata.outputs['dockerhub_namespace'] }}/${{ steps.metadata.outputs['image_name'] }}
readme-filepath: tmp_README.md