-
Notifications
You must be signed in to change notification settings - Fork 671
145 lines (133 loc) · 6.55 KB
/
image-build-binary.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
## Github workflow to build a multiarch docker image from pre-built binaries
name: Docker Image (Binary)
on:
workflow_call:
inputs:
tag:
required: true
type: string
description: "Version tag of release"
docker_tag:
required: true
type: string
description: "Version tag for docker images"
## Define which docker arch to build for
env:
docker_platforms: "linux/arm64, linux/arm/v7, linux/amd64, linux/amd64/v3"
docker-org: blockstack
concurrency:
group: docker-image-binary-${{ github.head_ref || github.ref || github.run_id }}
## Always cancel duplicate jobs
cancel-in-progress: true
run-name: ${{ inputs.tag }}
jobs:
## Runs when the following is true:
## - tag is provided
## - workflow is building default branch (master)
image:
if: |
inputs.tag != ''
name: Build Image
runs-on: ubuntu-latest
strategy:
fail-fast: false
## Build a maximum of 2 images concurrently based on matrix.dist
max-parallel: 2
matrix:
dist:
- alpine
- debian
steps:
## Setup Docker for the builds
- name: Docker setup
id: docker_setup
uses: stacks-network/actions/docker@main
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
## if the repo owner is not `stacks-network`, default to a docker-org of the repo owner (i.e. github user id)
## this allows forks to run the docker push workflows without having to hardcode a dockerhub org (but it does require docker hub user to match github username)
- name: Set Local env vars
id: set_env
if: |
github.repository_owner != 'stacks-network'
run: |
echo "docker-org=${{ github.repository_owner }}" >> "$GITHUB_ENV"
- name: Check Signer Release
id: check_signer_release
run: |
case "${{ inputs.tag }}" in
signer-*)
echo "is-signer-release=true" >> $GITHUB_ENV
;;
*)
echo "is-signer-release=false" >> $GITHUB_ENV
;;
esac
## Set docker metatdata
## - depending on the matrix.dist, different tags will be enabled
## ex. debian will have this tag: `type=ref,event=tag,enable=${{ matrix.dist == 'debian' }}`
- name: Docker Metadata ( ${{matrix.dist}} )
if: ${{ env.is-signer-release == 'true' }}
id: docker_metadata_signer
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 #v5.5.1
with:
images: |
${{env.docker-org}}/stacks-signer
tags: |
type=raw,value=latest,enable=${{ inputs.docker_tag != '' && (github.ref == format('refs/heads/{0}', github.event.repository.default_branch) ) && matrix.dist == 'debian' }}
type=raw,value=${{ inputs.docker_tag }}-${{ matrix.dist }},enable=${{ inputs.docker_tag != '' && matrix.dist == 'debian'}}
type=raw,value=${{ inputs.docker_tag }},enable=${{ inputs.docker_tag != '' && matrix.dist == 'debian' }}
type=ref,event=tag,enable=${{ matrix.dist == 'debian' }}
type=raw,value=latest-${{ matrix.dist }},enable=${{ inputs.docker_tag != '' && (github.ref == format('refs/heads/{0}', github.event.repository.default_branch) ) && matrix.dist == 'alpine' }}
type=raw,value=${{ inputs.docker_tag }}-${{ matrix.dist }},enable=${{ inputs.docker_tag != '' && matrix.dist == 'alpine' }}
- name: Docker Metadata ( ${{matrix.dist}} )
if: ${{ env.is-signer-release == 'false' }}
id: docker_metadata_node
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 #v5.5.1
with:
## tag images with current repo name `stacks-core` as well as legacy `stacks-blockchain`
images: |
${{env.docker-org}}/${{ github.event.repository.name }}
${{env.docker-org}}/stacks-blockchain
tags: |
type=raw,value=latest,enable=${{ inputs.docker_tag != '' && (github.ref == format('refs/heads/{0}', github.event.repository.default_branch) ) && matrix.dist == 'debian' }}
type=raw,value=${{ inputs.docker_tag }}-${{ matrix.dist }},enable=${{ inputs.docker_tag != '' && matrix.dist == 'debian'}}
type=raw,value=${{ inputs.docker_tag }},enable=${{ inputs.docker_tag != '' && matrix.dist == 'debian' }}
type=ref,event=tag,enable=${{ matrix.dist == 'debian' }}
type=raw,value=latest-${{ matrix.dist }},enable=${{ inputs.docker_tag != '' && (github.ref == format('refs/heads/{0}', github.event.repository.default_branch) ) && matrix.dist == 'alpine' }}
type=raw,value=${{ inputs.docker_tag }}-${{ matrix.dist }},enable=${{ inputs.docker_tag != '' && matrix.dist == 'alpine' }}
## Build docker image for signer release
- name: Build and Push ( ${{matrix.dist}} )
if: ${{ env.is-signer-release == 'true' }}
id: docker_build_signer
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0
with:
file: ./.github/actions/dockerfiles/Dockerfile.${{ matrix.dist }}-binary
platforms: ${{ env.docker_platforms }}
tags: ${{ steps.docker_metadata_signer.outputs.tags }}
labels: ${{ steps.docker_metadata_signer.outputs.labels }}
build-args: |
TAG=${{ inputs.tag }}
REPO=${{ github.repository_owner }}/${{ github.event.repository.name }}
STACKS_NODE_VERSION=${{ inputs.tag || env.GITHUB_SHA_SHORT }}
GIT_BRANCH=${{ env.GITHUB_REF_SHORT }}
GIT_COMMIT=${{ env.GITHUB_SHA_SHORT }}
push: ${{ env.DOCKER_PUSH }}
## Build docker image for node release
- name: Build and Push ( ${{matrix.dist}} )
if: ${{ env.is-signer-release == 'false' }}
id: docker_build_node
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0
with:
file: ./.github/actions/dockerfiles/Dockerfile.${{ matrix.dist }}-binary
platforms: ${{ env.docker_platforms }}
tags: ${{ steps.docker_metadata_node.outputs.tags }}
labels: ${{ steps.docker_metadata_node.outputs.labels }}
build-args: |
TAG=${{ inputs.tag }}
REPO=${{ github.repository_owner }}/${{ github.event.repository.name }}
STACKS_NODE_VERSION=${{ inputs.tag || env.GITHUB_SHA_SHORT }}
GIT_BRANCH=${{ env.GITHUB_REF_SHORT }}
GIT_COMMIT=${{ env.GITHUB_SHA_SHORT }}
push: ${{ env.DOCKER_PUSH }}