-
Notifications
You must be signed in to change notification settings - Fork 32
149 lines (129 loc) · 4.54 KB
/
docker-build.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
146
147
148
149
name: Build Docker Images and Binaries
# reusable workflow, do not add triggers
on:
workflow_call:
workflow_dispatch:
permissions:
id-token: write
contents: read
packages: write
jobs:
goreleaser:
strategy:
fail-fast: false
matrix:
os:
- linux
arch:
- amd64
- arm64
runs-on: burnt-labs-${{ matrix.arch }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Prepare environment
run: |
echo "SHORT_SHA=${GITHUB_SHA:0:7}" | tee -a $GITHUB_ENV
sed -En 's/^go (.*)$/GO_VERSION=\1/p' go.mod | tee -a $GITHUB_ENV
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Run GoReleaser
run: |
make build-${{ matrix.os }}-${{ matrix.arch }}
- name: Upload binary
uses: actions/upload-artifact@v4
with:
name: xiond-${{ matrix.os}}-${{ matrix.arch }}
path: dist/${{ env.SHORT_SHA }}/xiond_${{ matrix.os }}_${{ matrix.arch }}/xiond
retention-days: 3
build-docker:
name: main
needs: goreleaser
strategy:
fail-fast: false
matrix:
os:
- linux
arch:
- amd64
- arm64
runs-on: burnt-labs-${{ matrix.arch }}
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up docker buildx for push
uses: docker/setup-buildx-action@v3
with:
driver: docker
platforms: ${{ matrix.os }}/${{ matrix.arch }}
- name: Prepare environment
run: |
echo "PLATFORM=${{ matrix.os }}/${{ matrix.arch }}" | tr '/' '-' | tee -a $GITHUB_ENV
echo "XIOND_FN=xiond/${{ matrix.os }}/${{ matrix.arch }}" | tr '/' '-' | tee -a $GITHUB_ENV
echo "DOCKER_FN=docker/${{ matrix.os }}/${{ matrix.arch }}.tar" | tr '/' '-' | tee -a $GITHUB_ENV
echo "HEIGHLINER_FN=heighliner/${{ matrix.os }}/${{ matrix.arch }}.tar" | tr '/' '-' | tee -a $GITHUB_ENV
echo "VERSION=$(git describe --tags | sed 's/^v//')" | tee -a $GITHUB_ENV
echo "SHORT_SHA=${GITHUB_SHA:0:7}" | tee -a $GITHUB_ENV
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: xiond-${{ matrix.os }}-${{ matrix.arch }}
merge-multiple: true
- uses: int128/docker-build-cache-config-action@v1
id: cache
with:
image: ghcr.io/${{ github.repository }}/cache
- name: Build Docker Image
id: build-docker
uses: docker/build-push-action@v5
with:
build-args: |
COMMIT="${GITHUB_SHA}"
VERSION=${{ env.VERSION }}
TAG_VERSION="${SHORT_SHA}"
CALLER=goreleaser
labels: ${{ steps.meta.outputs.labels }}
platforms: ${{ matrix.os }}/${{ matrix.arch }}
push: false
target: release
cache-from: ${{ steps.cache.outputs.cache-from }}
cache-to: ${{ steps.cache.outputs.cache-to }}
outputs: type=docker,name=xion:${{ matrix.os }}-${{ matrix.arch }},name-canonical=true
- name: Build Heighliner Image
id: build-heighliner
uses: docker/build-push-action@v5
with:
build-args: |
BASE_IMAGE=xion
VERSION=${{ matrix.os }}-${{ matrix.arch }}
BINARIES=/usr/bin/xiond
CALLER=goreleaser
labels: ${{ steps.meta.outputs.labels }}
platforms: ${{ matrix.os }}/${{ matrix.arch }}
target: heighliner
outputs: type=docker,name=heighliner:${{ matrix.os }}-${{ matrix.arch }},name-canonical=true
- name: Save Docker Image
working-directory: ${{ runner.temp }}
run: |
docker save xion:${{ matrix.os }}-${{ matrix.arch }} > ${{ env.DOCKER_FN }}
- name: Upload Docker Image
uses: actions/upload-artifact@v4
with:
name: ${{ env.DOCKER_FN }}
path: ${{ runner.temp }}/${{ env.DOCKER_FN }}
if-no-files-found: error
retention-days: 3
- name: Save Heighliner Image
working-directory: ${{ runner.temp }}
run: |
docker save heighliner:${{ matrix.os }}-${{ matrix.arch }} > ${{ env.HEIGHLINER_FN }}
- name: Upload Heighliner Image
uses: actions/upload-artifact@v4
with:
name: ${{ env.HEIGHLINER_FN }}
path: ${{ runner.temp }}/${{ env.HEIGHLINER_FN }}
if-no-files-found: error
retention-days: 3