-
Notifications
You must be signed in to change notification settings - Fork 7
68 lines (65 loc) · 2.16 KB
/
docker.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
65
66
67
68
# Builds a Docker image and publishes it into Dockerhub
name: Docker Base
on:
workflow_call:
inputs:
dockerhub_username:
required: true
type: string
project_name:
required: true
type: string
docker_tags:
required: false
type: string
source_branch:
description: "Specifies which branch should be used when building the image"
required: false
type: string
default: main
secrets:
DOCKERHUB_TOKEN:
required: true
jobs:
build-and-publish-image:
name: Docker build & release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ inputs.source_branch }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ inputs.dockerhub_username }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# sets the tag env variable
- uses: olegtarasov/get-tag@v2.1
id: tagName
- name: Declare build variables
id: vars
shell: bash
run: |
echo "commit_hash=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
echo "curr_date=$(date --rfc-3339=seconds)" >> $GITHUB_OUTPUT
- name: Set the version tag
# If the workflow contains a tag, set a version docker tag in format "user/project:tag"
id: version_tag
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
run: echo "version_tag=${{ inputs.dockerhub_username }}/${{ inputs.project_name}}:${{ steps.tagName.outputs.tag }}" >> $GITHUB_OUTPUT
- name: Build and Push
uses: docker/build-push-action@v2
with:
push: true
tags: |
${{ steps.version_tag.outputs.version_tag }}
${{ inputs.docker_tags }}
context: .
build-args: |
BUILD_DATE=${{ steps.vars.outputs.curr_date }}
BUILD_VERSION=${{ steps.tagName.outputs.tag }}
REVISION=${{ steps.vars.outputs.commit_hash }}