-
Notifications
You must be signed in to change notification settings - Fork 2
85 lines (75 loc) · 2.93 KB
/
docker.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
---
name: 'Docker Pipeline'
on:
push:
branches:
- '**'
tags:
- '*.*.*'
pull_request:
env:
TERM: xterm
# enable Docker push only if the required secrets are defined
ENABLE_DOCKER_PUSH: ${{ secrets.DOCKERHUB_USER != null && secrets.DOCKERHUB_TOKEN != null }}
jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
# Set Docker image
- name: Set up Docker repository
run: echo "DOCKERHUB_REPO=$( if [[ -n $USER_REPO ]]; then echo $USER_REPO; else echo $GITHUB_REPOSITORY; fi )" >> $GITHUB_ENV
env:
USER_REPO: ${{ secrets.DOCKERHUB_REPO }}
- name: Set software version
run: |
sw_version=$(jq -r ".version" package.json)
ref_name=${{ github.ref_name }}
if [[ ${ref_name} == 'develop' ]]; then sw_version="${sw_version}-dev"; fi
echo "SOFTWARE_VERSION=${sw_version}" >> $GITHUB_ENV
sw_version_tag=false
if [[ "${ref_name}" == "master" || "${ref_name}" == "develop" ]]; then sw_version_tag=true; fi
echo "ENABLE_SOFTWARE_VERSION_TAG=${sw_version_tag}" >> $GITHUB_ENV
cp package.json{,.orig} && jq --arg sw_ver "${sw_version}.build${{ github.run_number }}" '.version = $sw_ver' package.json.orig > package.json
# Extract Docker metadata
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.DOCKERHUB_REPO }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'master') }}
type=raw,value=${{ env.SOFTWARE_VERSION }},enable=${{env.ENABLE_SOFTWARE_VERSION_TAG}}
type=raw,value=${{ env.SOFTWARE_VERSION}}.build${{ github.run_number }},enable=${{env.ENABLE_SOFTWARE_VERSION_TAG}}
type=sha
labels: |
org.opencontainers.image.software=${{ env.SOFTWARE_VERSION }}.build${{ github.run_number }}
org.opencontainers.image.build=${{ github.run_number }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: all
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
# DockerHub Login
- name: Login to DockerHub
uses: docker/login-action@v2
if: ${{ env.ENABLE_DOCKER_PUSH == 'true' }}
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# Build and push
- name: Build
uses: docker/build-push-action@v3
with:
builder: ${{ steps.buildx.outputs.name }}
context: .
file: ./docker/Dockerfile
platforms: linux/amd64
push: ${{ env.ENABLE_DOCKER_PUSH == 'true' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}