-
Notifications
You must be signed in to change notification settings - Fork 526
232 lines (212 loc) · 8.15 KB
/
build-arm64-image.yaml
File metadata and controls
232 lines (212 loc) · 8.15 KB
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
name: Build arm64 Image
on:
pull_request:
branches:
- master
paths-ignore:
- 'docs/**'
- '**.md'
push:
branches:
- master
- release-*
paths-ignore:
- 'docs/**'
- '**.md'
concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: true
env:
GO_VERSION: ''
jobs:
build-kube-ovn-base:
name: Build kube-ovn-base
runs-on: ubuntu-24.04-arm
outputs:
build-base: ${{ steps.check.outputs.build-base }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- id: check
run: |
if [ ${{ github.event_name }} != 'pull_request' ]; then
exit
fi
tmp_dir=`mktemp -d`
cat > "$tmp_dir/on_changes.txt" <<EOF
dist/images/Dockerfile.base
dist/images/OpenBFDD-compile.patch
dist/images/go-deps/download-go-deps.sh
dist/images/go-deps/rebuild-go-deps.sh
EOF
if git diff --name-only HEAD^ HEAD | grep -Ff "$tmp_dir/on_changes.txt"; then
echo build-base=1 >> "$GITHUB_OUTPUT"
fi
rm -frv "$tmp_dir"
- uses: jlumbroso/free-disk-space@v1.3.1
if: steps.check.outputs.build-base == 1
with:
android: true
dotnet: true
haskell: true
docker-images: false
large-packages: false
tool-cache: false
swap-storage: false
- uses: docker/setup-buildx-action@v3
if: steps.check.outputs.build-base == 1
- uses: actions/setup-go@v5
if: steps.check.outputs.build-base == 1
id: setup-go
with:
go-version-file: go.mod
check-latest: true
cache: false
- name: Build kube-ovn-base image
id: build
if: steps.check.outputs.build-base == 1
env:
GO_VERSION: ${{ steps.setup-go.outputs.go-version }}
run: |
make base-arm64
make base-tar-arm64
- name: Upload base images to artifact
if: steps.check.outputs.build-base == 1
uses: actions/upload-artifact@v4
with:
name: kube-ovn-base
path: image-arm64.tar
build:
name: Build arm64
runs-on: ubuntu-24.04-arm
needs:
- build-kube-ovn-base
steps:
- uses: actions/checkout@v4
id: checkout
with:
ref: ${{ github.head_ref || github.ref }}
- uses: docker/setup-buildx-action@v3
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION || '' }}
go-version-file: go.mod
check-latest: true
cache: false
- name: Setup environment variables
run: |
echo "TAG=$(cat VERSION)" >> "$GITHUB_ENV"
echo "GO_FULL_VER=$(go env GOVERSION)" >> "$GITHUB_ENV"
- name: Go Cache
uses: actions/cache@v4
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-${{ env.GO_FULL_VER }}-arm64-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-${{ env.GO_FULL_VER }}-arm64-
- name: Download base images
if: needs.build-kube-ovn-base.outputs.build-base == 1
uses: actions/download-artifact@v4
with:
name: kube-ovn-base
- name: Load base images
if: needs.build-kube-ovn-base.outputs.build-base == 1
run: |
docker load --input image-arm64.tar
docker tag kubeovn/kube-ovn-base:$TAG-arm64 kubeovn/kube-ovn-base:$TAG
docker tag kubeovn/kube-ovn-base:$TAG-debug-arm64 kubeovn/kube-ovn-base:$TAG-debug
- name: Scan base image
uses: aquasecurity/trivy-action@0.31.0
env:
TRIVY_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-db:2
with:
scan-type: image
scanners: vuln
image-ref: docker.io/kubeovn/kube-ovn-base:${{ env.TAG }}
format: json
output: trivy-result.json
ignore-unfixed: true
trivyignores: .trivyignore
vuln-type: library
- name: Build kubectl and CNI plugins from source
env:
CGO_ENABLED: "0"
GO_INSTALL: "go install -v -mod=mod -trimpath"
run: |
cat trivy-result.json
dockerfile=${{ github.workspace }}/dist/images/Dockerfile
cni_plugins_version=`go list -m -f '{{.Version}}' github.com/containernetworking/plugins`
cni_plugins_build_flags="-ldflags '-extldflags -static -X github.com/containernetworking/plugins/pkg/utils/buildversion.BuildVersion=$cni_plugins_version'"
jq -r '.Results[] | select((.Type=="gobinary") and (.Vulnerabilities!=null)) | .Target' trivy-result.json | while read f; do
bin=`basename $f`
go_bin_dir=`go env GOPATH`/bin
case $bin in
loopback|macvlan)
echo "Building $bin@$cni_plugins_version from source..."
sh -c "cd /tmp && $GO_INSTALL $cni_plugins_build_flags github.com/containernetworking/plugins/plugins/main/$bin@$cni_plugins_version"
echo "COPY $bin /$f" >> "$dockerfile"
cp -a $go_bin_dir/$bin `dirname "$dockerfile"`
;;
portmap)
echo "Building $bin@$cni_plugins_version from source..."
sh -c "cd /tmp && $GO_INSTALL $cni_plugins_build_flags github.com/containernetworking/plugins/plugins/meta/$bin@$cni_plugins_version"
echo "COPY $bin /$f" >> "$dockerfile"
cp -a $go_bin_dir/$bin `dirname "$dockerfile"`
;;
kubectl)
go mod tidy
version=`go list -m -f '{{.Version}}' k8s.io/kubernetes`
mod_dir=`go list -m -f '{{.Dir}}' k8s.io/kubernetes`
source "$mod_dir/hack/lib/util.sh"
source "$mod_dir/hack/lib/logging.sh"
source "$mod_dir/hack/lib/version.sh"
repo=kubernetes/kubernetes
commit=unknown
read type tag_sha < <(echo $(curl -s "https://api.github.com/repos/$repo/git/ref/tags/$version" |
jq -r '.object.type,.object.sha'))
if [ $type = "commit" ]; then
commit=$tag_sha
else
commit=$(curl -s "https://api.github.com/repos/$repo/git/tags/$tag_sha" | jq -r '.object.sha')
fi
export KUBE_GIT_COMMIT="${commit}"
export KUBE_GIT_TREE_STATE='clean'
export KUBE_GIT_VERSION="${version}"
export KUBE_GIT_MAJOR=`echo $KUBE_GIT_VERSION | cut -d. -f1 | sed 's/$v//'`
export KUBE_GIT_MINOR=`echo $KUBE_GIT_VERSION | cut -d. -f2`
goldflags="all=$(kube::version::ldflags) -s -w"
echo "Building $bin@$version from source..."
$GO_INSTALL -ldflags="${goldflags}" k8s.io/kubernetes/cmd/kubectl
echo "COPY $bin /$f" >> "$dockerfile"
cp -a $go_bin_dir/$bin `dirname "$dockerfile"`
;;
*)
;;
esac
done
- name: Build
run: |
if [ ${{ needs.build-kube-ovn-base.outputs.build-base || 0 }} = 1 ]; then
make build-kube-ovn-arm64
else
make image-kube-ovn-arm64
fi
make image-vpc-nat-gateway
- name: Push
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
COMMIT: ${{ steps.checkout.outputs.commit }}
run: |
TAG=$(cat VERSION)
COMMIT=${COMMIT:0:9}
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
docker tag kubeovn/kube-ovn:$TAG kubeovn/kube-ovn:$TAG-$COMMIT-arm64
docker tag kubeovn/kube-ovn:$TAG-debug kubeovn/kube-ovn:$TAG-$COMMIT-debug-arm64
docker tag kubeovn/vpc-nat-gateway:$TAG kubeovn/vpc-nat-gateway:$TAG-$COMMIT-arm64
docker images
docker push kubeovn/kube-ovn:$TAG-$COMMIT-arm64
docker push kubeovn/kube-ovn:$TAG-$COMMIT-debug-arm64
docker push kubeovn/vpc-nat-gateway:$TAG-$COMMIT-arm64