-
Notifications
You must be signed in to change notification settings - Fork 18
125 lines (112 loc) · 3.83 KB
/
build_dockers_workflow.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
---
name: Build docker image - workflow_call/on-demand
'on':
workflow_call:
secrets:
DOCKER_PROVIDER:
required: true
DOCKER_USERNAME:
required: true
DOCKER_PASSWORD:
required: true
DOCKER_REPO:
required: true
inputs:
arch:
type: string
default: x86-64
features:
type: string
default: safe
version:
type: string
description: 'build tag/version'
tag_alias:
type: string
description: 'build tag alias'
platforms:
type: string
# linux/arm64, linux/amd64
default: linux/amd64
env:
IMAGE_NAME: tari-dan
jobs:
docker_build:
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- name: checkout tari-dan
uses: actions/checkout@v4
- name: environment setup
shell: bash
run: |
if [ -z "${{ inputs.version }}" ]; then
echo "Get current version"
TVN_VERSION=$(awk -F ' = ' '$1 ~ /version/ { gsub(/["]/, "", $2); printf("%s",$2) }' "${GITHUB_WORKSPACE}/applications/tari_validator_node/Cargo.toml")
TARI_SOURCE_ROOT="."
VBRANCH=$(git --git-dir ${TARI_SOURCE_ROOT}/.git branch --show-current)
VSHA_SHORT=$(git --git-dir ${TARI_SOURCE_ROOT}/.git rev-parse --short HEAD)
VERSION="v${TVN_VERSION}-${VBRANCH}_$(date -u '+%Y%m%d')_${VSHA_SHORT}"
else
VERSION=${{ inputs.version }}
fi
echo "Setting ${VERSION} as docker tag"
echo "VERSION=${VERSION}" >> $GITHUB_ENV
if [ ! -z "${{ inputs.tag_alias }}" ]; then
echo "Setup tag_alias"
echo "TAG_ALIAS=${{ secrets.DOCKER_PROVIDER }}/${{ secrets.DOCKER_REPO }}/${{ env.IMAGE_NAME }}:${{ inputs.tag_alias }}" >> $GITHUB_ENV
fi
- name: Set up QEMU for Docker
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: |
#name/${{ env.IMAGE_NAME }}
#ghcr.io/${{ github.repository }}
ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
#username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Docker Image Provider
uses: docker/login-action@v3
with:
registry: ${{ secrets.DOCKER_PROVIDER }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Docker image build and push
id: docker_build
uses: docker/build-push-action@v6
with:
context: .
file: ./docker_rig/${{ env.IMAGE_NAME }}.Dockerfile
platforms: ${{ inputs.platforms }}
push: true
provenance: false
# cache-from: type=gha
# cache-to: type=gha,mode=max
build-args: |
VERSION=${{ env.VERSION }}
ARCH=${{ inputs.arch }}
${{ env.DOCKER_SUBTAG }}
tags: |
${{ steps.meta.outputs.tags }}
${{ secrets.DOCKER_PROVIDER }}/${{ secrets.DOCKER_REPO }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}
${{ env.TAG_ALIAS }}
labels: ${{ steps.meta.outputs.labels }}
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}