Skip to content

Commit e50c10a

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

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
id: image
21+
run: |
22+
VERSION=`git describe --tags --always --dirty`
23+
TAG=${VERSION}
24+
IMAGE=${{ env.REGISTRY }}/acid/postgres-operator:${TAG}
25+
echo "NAME=$IMAGE" >> $GITHUB_OUTPUT
26+
base_arm_image=alpine:3.15
27+
sed -i '' 's/{base_image}/${base_arm_image}/g' ./docker/Dockerfile-multi-arch
28+
29+
- name: Set up QEMU
30+
uses: docker/setup-qemu-action@v2
31+
32+
- name: Set up Docker Buildx
33+
uses: docker/setup-buildx-action@v2
34+
35+
- name: Login to GHCR
36+
uses: docker/login-action@v2
37+
with:
38+
registry: ${{ env.REGISTRY }}
39+
username: ${{ github.actor }}
40+
password: ${{ secrets.GITHUB_TOKEN }}
41+
42+
- name: Run unit tests
43+
run: make test
44+
45+
- name: Build and push
46+
uses: docker/build-push-action@v3
47+
with:
48+
push: true
49+
platforms: |
50+
linux/amd64
51+
linux/arm64
52+
file: ./docker/Dockerfile-multi-arch
53+
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+
FROM golang:1.18.3 as build
2+
WORKDIR /workspace
3+
ENV GO111MODULE=on \
4+
GOPROXY=https://goproxy.cn,direct \
5+
BINARY=postgres-operator
6+
COPY . .
7+
RUN CGO_ENABLED=0 go build -o build/linux/${BINARY} ./cmd/main.go
8+
9+
FROM {base_image}
10+
LABEL maintainer="Team ACID @ Zalando <team-acid@zalando.de>"
11+
12+
# We need root certificates to deal with teams api over https
13+
RUN apk --no-cache add curl
14+
RUN 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)