Skip to content

Commit fafb018

Browse files
authored
K8SPG-451 add arm support (#569)
* K8SPG-451 add arm support * fix trivy scan * start to use go 1.21 * use build script * use env var
1 parent 168a536 commit fafb018

File tree

4 files changed

+54
-14
lines changed

4 files changed

+54
-14
lines changed

.github/workflows/scan.yml

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,57 @@
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-postgresql-operator
10+
311
jobs:
412
build:
513
name: Build
614
runs-on: ubuntu-latest
715
steps:
816
- name: Checkout code
917
uses: actions/checkout@v4
10-
- name: Build an image from Dockerfile
18+
19+
- name: Set up QEMU
20+
uses: docker/setup-qemu-action@v2
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-postgresql-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
16-
- name: Run Trivy vulnerability scanner
32+
33+
- name: Run Trivy vulnerability scanner image (linux/arm64)
1734
uses: aquasecurity/[email protected]
1835
with:
19-
image-ref: 'docker.io/perconalab/percona-postgresql-operator:${{ github.sha }}'
36+
image-ref: '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}-arm64'
37+
format: 'table'
38+
exit-code: '1'
39+
ignore-unfixed: true
40+
vuln-type: 'os,library'
41+
severity: 'CRITICAL,HIGH'
42+
43+
- name: Build an image from Dockerfile (linux/amd64)
44+
run: |
45+
export IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}-amd64
46+
export DOCKER_PUSH=0
47+
export DOCKER_SQUASH=0
48+
export DOCKER_DEFAULT_PLATFORM='linux/amd64'
49+
./e2e-tests/build
50+
51+
- name: Run Trivy vulnerability scanner image (linux/amd64)
52+
uses: aquasecurity/[email protected]
53+
with:
54+
image-ref: '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}-amd64'
2055
format: 'table'
2156
exit-code: '1'
2257
ignore-unfixed: true

Jenkinsfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ pipeline {
325325
docker login -u '${USER}' -p '${PASS}'
326326
export RELEASE=0
327327
export IMAGE=\$DOCKER_TAG
328+
docker buildx create --use
328329
./e2e-tests/build
329330
docker logout
330331
"
@@ -507,4 +508,4 @@ pipeline {
507508
deleteDir()
508509
}
509510
}
510-
}
511+
}

build/postgres-operator/Dockerfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.20 AS go_builder
1+
FROM golang:1.21 AS go_builder
22
WORKDIR /go/src/github.com/percona/percona-postgresql-operator
33

44
COPY . .
@@ -8,11 +8,10 @@ ARG GIT_COMMIT
88
ARG GIT_BRANCH
99
ARG GO_LDFLAGS
1010
ARG GOOS=linux
11-
ARG GOARCH=amd64
1211
ARG CGO_ENABLED=0
1312

1413
RUN mkdir -p build/_output/bin \
15-
&& CGO_ENABLED=$CGO_ENABLED GOOS=$GOOS GOARCH=$GOARCH GO_LDFLAGS=$GO_LDFLAGS \
14+
&& CGO_ENABLED=$CGO_ENABLED GOOS=$GOOS 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/postgres-operator \
1817
./cmd/postgres-operator \

e2e-tests/build

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,34 @@ if [[ ${DOCKER_SQUASH:-1} == 1 ]]; then
2020
squash="--squash"
2121
fi
2222

23+
24+
if [[ ${DOCKER_PUSH:-1} == 1 ]]; then
25+
imgresult="--push=true"
26+
else
27+
imgresult="--load"
28+
fi
29+
2330
BUILD_COMPONENT=${COMPONENT:-"postgres-operator"}
2431

2532
build_operator() {
2633
if [ "${RELEASE:-1}" = 0 ]; then
2734
GO_LDFLAGS="-race"
2835
fi
2936

30-
export DOCKER_DEFAULT_PLATFORM=${DOCKER_DEFAULT_PLATFORM:-"linux/amd64"}
37+
export DOCKER_DEFAULT_PLATFORM=${DOCKER_DEFAULT_PLATFORM:-"linux/amd64,linux/arm64"}
3138
export GO_LDFLAGS="-w -s -trimpath ${GO_LDFLAGS}"
3239
pushd "${ROOT_REPO}" || exit
33-
docker build \
40+
docker buildx build \
41+
--platform $DOCKER_DEFAULT_PLATFORM \
3442
--build-arg GIT_COMMIT="${GIT_COMMIT}" \
3543
--build-arg GIT_BRANCH="${GIT_BRANCH}" \
3644
--build-arg BUILD_TIME="${BUILD_TIME}" \
3745
--build-arg GO_LDFLAGS="${GO_LDFLAGS}" \
46+
$imgresult \
3847
$squash \
3948
$no_cache \
4049
-t "${IMAGE}" -f build/${BUILD_COMPONENT}/Dockerfile .
4150
popd || exit
42-
43-
if [ "${DOCKER_PUSH:-1}" = 1 ]; then
44-
docker push "${IMAGE}"
45-
fi
4651
}
4752

4853
if [[ $BUILD == "0" ]]; then

0 commit comments

Comments
 (0)