forked from efrecon/docker-mosquitto
-
Notifications
You must be signed in to change notification settings - Fork 1
54 lines (46 loc) · 1.61 KB
/
build-versioned-image.yaml
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
name: Build versioned image
run-name: Build versioned image by @${{ github.actor }}
on:
workflow_dispatch
defaults:
run:
shell: bash
jobs:
build_image:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- name: Get ref name
id: github-ref-name
run: |
ref='${{ github.ref_name }}'
echo "Tag ref is ${ref}"
# replace any characters not permitted in a docker tag with an underscore
ref_name="${ref//[^A-Za-z0-9\.\-_]/_}"
echo "Sanitised ref name is ${ref_name}"
echo "ref=${ref_name}" >>"${GITHUB_OUTPUT}"
- name: Get docker image tag
id: docker-image-tag
run: |
sha_short=$(git rev-parse --short HEAD)
timestamp=$(date +'%Y%m%d_%H%M%S')
sha_tag="${ref}-${sha_short}"
timestamp_tag="${ref}-${timestamp}"
echo "Docker image tags are ${sha_tag} and ${timestamp_tag}"
echo "sha_tag=${sha_tag}" >>"${GITHUB_OUTPUT}"
echo "timestamp_tag=${timestamp_tag}" >>"${GITHUB_OUTPUT}"
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v5
with:
context: ./
file: ./Dockerfile
push: true
tags: |
"vocovo/docker-mosquitto:${{ steps.docker-image-tag.outputs.sha_tag }}"
"vocovo/docker-mosquitto:${{ steps.docker-image-tag.outputs.timestamp_tag }}"