Skip to content

Commit b9f94ba

Browse files
sergelogvinovhors
andauthored
K8SPSMDB-948: Multi arch build (#1356)
An easy way to build PSMDB for different architectures. Signed-off-by: Serge Logvinov <[email protected]> Co-authored-by: Viacheslav Sarzhan <[email protected]>
1 parent 0c38cd9 commit b9f94ba

File tree

6 files changed

+53
-16
lines changed

6 files changed

+53
-16
lines changed

.github/workflows/reviewdog.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
- uses: actions/[email protected]
3131
- uses: actions/setup-go@v5
3232
with:
33-
go-version: '^1.17'
33+
go-version: '^1.21'
3434
- run: go install mvdan.cc/sh/v3/cmd/shfmt@latest
3535
- run: $(go env GOPATH)/bin/shfmt -f . | grep -v 'vendor' | xargs $(go env GOPATH)/bin/shfmt -bn -ci -s -w
3636
- name: suggester / shfmt

.github/workflows/scan.yml

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,56 @@
11
name: Scan docker
22
on: [pull_request]
3+
4+
env:
5+
# Use docker.io for Docker Hub if empty
6+
REGISTRY: docker.io
7+
8+
# github.repository as <account>/<repo>
9+
IMAGE_NAME: perconalab/percona-server-mongodb-operator
10+
311
jobs:
412
build:
513
name: Build
614
runs-on: ubuntu-latest
715
steps:
816
- name: Checkout code
917
uses: actions/[email protected]
10-
- name: Build an image from Dockerfile
18+
19+
- name: Set up QEMU
20+
uses: docker/setup-qemu-action@v3
21+
22+
- name: Set up Docker Buildx
23+
uses: docker/setup-buildx-action@v3
24+
25+
- name: Build an image from Dockerfile (linux/arm64)
1126
run: |
12-
export IMAGE=perconalab/percona-server-mongodb-operator:${{ github.sha }}
27+
export IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}-arm64
1328
export DOCKER_PUSH=0
1429
export DOCKER_SQUASH=0
30+
export DOCKER_DEFAULT_PLATFORM='linux/arm64'
1531
./e2e-tests/build
1632
- name: Run Trivy vulnerability scanner
1733
uses: aquasecurity/[email protected]
1834
with:
19-
image-ref: 'docker.io/perconalab/percona-server-mongodb-operator:${{ github.sha }}'
35+
image-ref: '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}-arm64'
36+
format: 'table'
37+
exit-code: '1'
38+
ignore-unfixed: true
39+
vuln-type: 'os,library'
40+
severity: 'CRITICAL,HIGH'
41+
42+
- name: Build an image from Dockerfile (linux/amd64)
43+
run: |
44+
export IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}-amd64
45+
export DOCKER_PUSH=0
46+
export DOCKER_SQUASH=0
47+
export DOCKER_DEFAULT_PLATFORM='linux/amd64'
48+
./e2e-tests/build
49+
50+
- name: Run Trivy vulnerability scanner image (linux/amd64)
51+
uses: aquasecurity/[email protected]
52+
with:
53+
image-ref: '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}-amd64'
2054
format: 'table'
2155
exit-code: '1'
2256
ignore-unfixed: true

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
steps:
88
- uses: actions/setup-go@v5
99
with:
10-
go-version: '^1.19'
10+
go-version: '^1.21'
1111
- uses: actions/[email protected]
1212
- name: go test
1313
run: go test -v ./...

Jenkinsfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ EOF
323323
docker login -u '${USER}' -p '${PASS}'
324324
export RELEASE=0
325325
export IMAGE=\$DOCKER_TAG
326+
docker buildx create --use
326327
./e2e-tests/build
327328
docker logout
328329
"
@@ -349,7 +350,7 @@ EOF
349350
-v $WORKSPACE/src/github.com/percona/percona-server-mongodb-operator:/go/src/github.com/percona/percona-server-mongodb-operator \
350351
-w /go/src/github.com/percona/percona-server-mongodb-operator \
351352
-e GOFLAGS='-buildvcs=false' \
352-
golang:1.19 sh -c '
353+
golang:1.21 sh -c '
353354
go install github.com/google/[email protected];
354355
/go/bin/go-licenses csv github.com/percona/percona-server-mongodb-operator/cmd/manager \
355356
| cut -d , -f 3 \
@@ -377,7 +378,7 @@ EOF
377378
-v $WORKSPACE/src/github.com/percona/percona-server-mongodb-operator:/go/src/github.com/percona/percona-server-mongodb-operator \
378379
-w /go/src/github.com/percona/percona-server-mongodb-operator \
379380
-e GOFLAGS='-buildvcs=false' \
380-
golang:1.19 sh -c 'go build -v -o percona-server-mongodb-operator github.com/percona/percona-server-mongodb-operator/cmd/manager'
381+
golang:1.21 sh -c 'go build -v -o percona-server-mongodb-operator github.com/percona/percona-server-mongodb-operator/cmd/manager'
381382
"
382383
'''
383384

build/Dockerfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@ ARG GIT_COMMIT
77
ARG GIT_BRANCH
88
ARG GO_LDFLAGS
99
ARG GOOS=linux
10-
ARG GOARCH=amd64
1110
ARG CGO_ENABLED=0
1211

1312
RUN go mod download \
1413
&& mkdir -p build/_output/bin \
15-
&& GOOS=$GOOS GOARCH=$GOARCH CGO_ENABLED=$CGO_ENABLED GO_LDFLAGS=$GO_LDFLAGS \
14+
&& GOOS=$GOOS CGO_ENABLED=$CGO_ENABLED GO_LDFLAGS=$GO_LDFLAGS \
1615
go build -ldflags "-w -s -X main.GitCommit=$GIT_COMMIT -X main.GitBranch=$GIT_BRANCH" \
1716
-o build/_output/bin/percona-server-mongodb-operator \
1817
cmd/manager/main.go \
1918
&& cp -r build/_output/bin/percona-server-mongodb-operator /usr/local/bin/percona-server-mongodb-operator \
20-
&& GOOS=$GOOS GOARCH=$GOARCH CGO_ENABLED=$CGO_ENABLED GO_LDFLAGS=$GO_LDFLAGS \
19+
&& GOOS=$GOOS CGO_ENABLED=$CGO_ENABLED GO_LDFLAGS=$GO_LDFLAGS \
2120
go build -ldflags "-w -s -X main.GitCommit=$GIT_COMMIT -X main.GitBranch=$GIT_BRANCH" \
2221
-o build/_output/bin/mongodb-healthcheck \
2322
cmd/mongodb-healthcheck/main.go \

e2e-tests/build

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,31 @@ fi
1414
if [[ ${DOCKER_SQUASH:-1} == 1 ]]; then
1515
squash="--squash"
1616
fi
17+
if [[ ${DOCKER_PUSH:-1} == 1 ]]; then
18+
imgresult="--push=true"
19+
else
20+
imgresult="--load"
21+
fi
1722

1823
build_operator() {
1924
if [ "${RELEASE:-1}" = 0 ]; then
2025
GO_LDFLAGS="-race"
2126
fi
2227

2328
export IMAGE
24-
export DOCKER_DEFAULT_PLATFORM=${DOCKER_DEFAULT_PLATFORM:-linux/amd64}
29+
export DOCKER_DEFAULT_PLATFORM=${DOCKER_DEFAULT_PLATFORM:-"linux/amd64,linux/arm64"}
2530
export GO_LDFLAGS="-w -s -trimpath $GO_LDFLAGS"
2631
pushd ${src_dir}
27-
docker build \
32+
docker buildx build \
33+
--platform $DOCKER_DEFAULT_PLATFORM \
2834
--build-arg GIT_COMMIT=$GIT_COMMIT \
2935
--build-arg GIT_BRANCH=$GIT_BRANCH \
3036
--build-arg GO_LDFLAGS="$GO_LDFLAGS" \
37+
$imgresult \
3138
$squash \
3239
$no_cache \
3340
-t "${IMAGE}" -f build/Dockerfile .
3441
popd
35-
36-
if [ "${DOCKER_PUSH:-1}" = 1 ]; then
37-
docker push ${IMAGE}
38-
fi
3942
}
4043

4144
until docker ps; do sleep 1; done

0 commit comments

Comments
 (0)