Skip to content

Commit f498b20

Browse files
committed
add build arm image
Signed-off-by: lengrongfu <1275177125@qq.com>
1 parent 4d58525 commit f498b20

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Publish multiarch images on ghcr.io
2+
on:
3+
push:
4+
tags:
5+
- '*'
6+
7+
env:
8+
REGISTRY: ghcr.io
9+
IMAGE_NAME: ${{ github.repository }}
10+
11+
jobs:
12+
docker:
13+
name: Build and push postgres-operator multiarch images
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v3
18+
19+
- name: image name
20+
run: |
21+
VERSION=`git describe --tags --always --dirty`
22+
TAG=${VERSION}
23+
IMAGE=${{ env.REGISTRY }}/acid/postgres-operator:${TAG}
24+
echo "NAME=$IMAGE" >> $GITHUB_OUTPUT
25+
26+
- name: Set up QEMU
27+
uses: docker/setup-qemu-action@v2
28+
29+
- name: Set up Docker Buildx
30+
uses: docker/setup-buildx-action@v2
31+
32+
- name: Login to GHCR
33+
uses: docker/login-action@v2
34+
with:
35+
registry: ${{ env.REGISTRY }}
36+
username: ${{ github.actor }}
37+
password: ${{ secrets.GITHUB_TOKEN }}
38+
39+
- name: Run unit tests
40+
run: make test
41+
42+
- name: Build and push
43+
uses: docker/build-push-action@v3
44+
with:
45+
push: true
46+
platforms: |
47+
linux/amd64
48+
linux/arm64
49+
file: ./docker/Dockerfile-multi-arch
50+
build-args: [base-image=alpine:3.15]
51+
tags: "${{ steps.image.outputs.NAME }}"

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ docker: ${DOCKERDIR}/${DOCKERFILE} docker-context
7272
echo "git describe $(shell git describe --tags --always --dirty)"
7373
cd "${DOCKERDIR}" && docker build --rm -t "$(IMAGE):$(TAG)$(CDP_TAG)$(DEBUG_FRESH)$(DEBUG_POSTFIX)" -f "${DOCKERFILE}" .
7474

75+
build-multi-arch:
76+
docker buildx build --platform linux/arm64,linux/amd64 --push -t "$(IMAGE):$(TAG)" -f ./${DOCKERDIR}/Dockerfile-multi-arch .
77+
7578
indocker-race:
7679
docker run --rm -v "${GOPATH}":"${GOPATH}" -e GOPATH="${GOPATH}" -e RACE=1 -w ${PWD} golang:1.17.3 bash -c "make linux"
7780

docker/Dockerfile-multi-arch

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
ARG base_image=alpine:3.15
2+
FROM golang:1.18.3 as build
3+
WORKDIR /workspace
4+
ENV GO111MODULE=on \
5+
GOPROXY=https://goproxy.cn,direct \
6+
BINARY=postgres-operator
7+
COPY . .
8+
RUN CGO_ENABLED=0 go build -o build/linux/${BINARY} ./cmd/main.go
9+
10+
FROM ${base_image}
11+
LABEL maintainer="Team ACID @ Zalando <team-acid@zalando.de>"
12+
# We need root certificates to deal with teams api over https
13+
RUN apk --no-cache add curl \
14+
apk --no-cache add ca-certificates
15+
16+
COPY --from=build /workspace/build/linux /
17+
18+
RUN addgroup -g 1000 pgo
19+
RUN adduser -D -u 1000 -G pgo -g 'Postgres Operator' pgo
20+
21+
USER 1000:1000
22+
23+
ENTRYPOINT ["/postgres-operator"]

0 commit comments

Comments
 (0)