-
-
Notifications
You must be signed in to change notification settings - Fork 140
202 lines (170 loc) · 6.98 KB
/
build-agent.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
name: Build Agent
on:
push:
branches: [ master ]
tags:
- v*
paths:
- 'agent/**'
- '.github/workflows/build-agent.yml'
pull_request:
branches: [ master ]
paths:
- 'agent/**'
- '.github/workflows/build-agent.yml'
jobs:
build:
runs-on: ubuntu-20.04
strategy:
matrix:
dockerfile: [amd64, arm32v6, arm32v7, arm64v8, i386]
include:
# includes a new variable of npm with a value of 2
# for the matrix leg matching the os and version
- dockerfile: amd64
arch: amd64
- dockerfile: arm32v6
arch: arm/6
- dockerfile: arm32v7
arch: arm/7
- dockerfile: arm64v8
arch: arm64/8
- dockerfile: i386
arch: i386
steps:
- name: checkout code
uses: actions/checkout@v4
- name: login to docker hub
if: "github.event_name != 'pull_request'"
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set github reference env
run: echo RELEASE_VERSION=${GITHUB_REF#refs/*/} >> $GITHUB_ENV
- name: Set docker build option env
if: "github.event_name != 'pull_request'"
run: echo "BUILD_OPTION=--provenance=false --push" >> $GITHUB_ENV
- name: build image
if: "!contains(github.ref, 'refs/tags/v')"
run: |
docker buildx build ${{ env.BUILD_OPTION }} -f agent/Dockerfile.${{ matrix.dockerfile }} \
--tag shellhubio/agent:${{ github.sha }}-${{ matrix.dockerfile }} \
--platform linux/${{ matrix.arch }} .
- name: build image from github tag
if: "contains(github.ref, 'refs/tags/v')"
run: |
docker buildx build ${{ env.BUILD_OPTION }} -f agent/Dockerfile.${{ matrix.dockerfile }} \
--tag shellhubio/agent:${{ env.RELEASE_VERSION }}-${{ matrix.dockerfile }} \
--build-arg SHELLHUB_VERSION=${{ env.RELEASE_VERSION }} \
--platform linux/${{ matrix.arch }} .
- name: export rootfs
if: "contains(github.ref, 'refs/tags/v')"
run: |
docker export $(docker create shellhubio/agent:${{ env.RELEASE_VERSION }}-${{ matrix.dockerfile }}) | gzip > rootfs-${{ matrix.dockerfile }}.tar.gz
- name: upload rootfs artifact
if: "contains(github.ref, 'refs/tags/v')"
uses: actions/upload-artifact@v4
with:
name: rootfs-${{ matrix.dockerfile }}
path: rootfs-${{ matrix.dockerfile }}.tar.gz
multiarch:
if: github.event_name != 'pull_request'
needs: build
runs-on: ubuntu-latest
steps:
- name: checkout code
uses: actions/checkout@v4
- name: Set github reference env
run: echo RELEASE_VERSION=${GITHUB_REF#refs/*/} >> $GITHUB_ENV
- name: login to docker hub
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
- name: build multiarch image
if: "!contains(github.ref, 'refs/tags/v')"
env:
DOCKER_CLI_EXPERIMENTAL: enabled
run: |
echo "Creating the manifest"
docker manifest create -a shellhubio/agent:${{ github.sha }} shellhubio/agent:${{ github.sha }}-amd64 shellhubio/agent:${{ github.sha }}-arm32v6 shellhubio/agent:${{ github.sha }}-arm32v7 shellhubio/agent:${{ github.sha }}-arm64v8
echo "Running amd64 manifest annotation"
docker manifest annotate shellhubio/agent:${{ github.sha }} shellhubio/agent:${{ github.sha }}-amd64 --os linux --arch amd64
archname=(arm32v6 arm32v7 arm64v8)
arch=(arm arm arm64)
variant=(v6 v7 v8)
for ((i = 0; i < 3; i++)) ; do
echo "Running ${archname[i]} manifest annotation"
docker manifest annotate shellhubio/agent:${{ github.sha }} shellhubio/agent:${{ github.sha }}-${archname[i]} --os linux --arch ${arch[i]} --variant ${variant[i]}
done
echo "Pushing multiarch manifest"
docker manifest push shellhubio/agent:${{ github.sha }}
- name: build multiarch image from github tag
if: contains(github.ref, 'refs/tags/v')
env:
DOCKER_CLI_EXPERIMENTAL: enabled
run: |
echo "Creating the manifest"
docker manifest create -a shellhubio/agent:${{ env.RELEASE_VERSION }} shellhubio/agent:${{ env.RELEASE_VERSION }}-amd64 shellhubio/agent:${{ env.RELEASE_VERSION }}-arm32v6 shellhubio/agent:${{ env.RELEASE_VERSION }}-arm32v7 shellhubio/agent:${{ env.RELEASE_VERSION }}-arm64v8
echo "Running amd64 manifest annotation"
docker manifest annotate shellhubio/agent:${{ env.RELEASE_VERSION }} shellhubio/agent:${{ env.RELEASE_VERSION }}-amd64 --os linux --arch amd64
archname=(arm32v6 arm32v7 arm64v8)
arch=(arm arm arm64)
variant=(v6 v7 v8)
for ((i = 0; i < 3; i++)) ; do
echo "Running ${archname[i]} manifest annotation"
docker manifest annotate shellhubio/agent:${{ env.RELEASE_VERSION }} shellhubio/agent:${{ env.RELEASE_VERSION }}-${archname[i]} --os linux --arch ${arch[i]} --variant ${variant[i]}
done
echo "Pushing multiarch manifest"
docker manifest push shellhubio/agent:${{ env.RELEASE_VERSION }}
vendored-tarball:
if: "contains(github.ref, 'refs/tags/v')"
needs: build
runs-on: ubuntu-20.04
steps:
- name: checkout code
uses: actions/checkout@v4
- name: export agent tarball
run: |
cd ./agent && go mod vendor && cd .. && tar czf shellhub-agent.tar.gz agent
- name: upload agent tarball artifact
uses: actions/upload-artifact@v4
with:
name: shellhub-agent
path: shellhub-agent.tar.gz
draft:
if: "contains(github.ref, 'refs/tags/v')"
needs: vendored-tarball
runs-on: ubuntu-latest
steps:
- name: download amd64
uses: actions/download-artifact@v4
with:
name: rootfs-amd64
- name: download arm32v6
uses: actions/download-artifact@v4
with:
name: rootfs-arm32v6
- name: download arm32v7
uses: actions/download-artifact@v4
with:
name: rootfs-arm32v7
- name: download arm64v8
uses: actions/download-artifact@v4
with:
name: rootfs-arm64v8
- name: download i386
uses: actions/download-artifact@v4
with:
name: rootfs-i386
- name: download vendored tarball
uses: actions/download-artifact@v4
with:
name: shellhub-agent
- name: release draft
uses: softprops/action-gh-release@v2
with:
draft: true
generate_release_notes: true
files: |
rootfs-*.tar.gz
shellhub-agent.tar.gz