Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for multi platform builds #124

Merged
merged 11 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 36 additions & 16 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,48 @@ on:
release:
types: [published]

permissions:
contents: read
packages: write
jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v3

- name: Generate Docker Tag
run: |
echo ${{ github.ref }} | cut -d '/' -f 3 > DOCKER_TAG
- name: Build and push container image
run: |
docker build --file build/Dockerfile.dist --tag ghcr.io/movetokube/postgres-operator:$(cat DOCKER_TAG) --tag movetokube/postgres-operator:$(cat DOCKER_TAG) .
docker tag ghcr.io/movetokube/postgres-operator:$(cat DOCKER_TAG) ghcr.io/movetokube/postgres-operator:latest
docker tag movetokube/postgres-operator:$(cat DOCKER_TAG) movetokube/postgres-operator:latest
docker login ghcr.io --username USERNAME --password ${{ secrets.GITHUB_TOKEN }}
docker push ghcr.io/movetokube/postgres-operator:$(cat DOCKER_TAG)
docker push ghcr.io/movetokube/postgres-operator:latest
docker login --username ${{ secrets.DOCKER_USER }} --password ${{ secrets.DOCKER_TOKEN }}
docker push movetokube/postgres-operator:$(cat DOCKER_TAG)
docker push movetokube/postgres-operator:latest
echo "DOCKER_TAG=$(cat DOCKER_TAG)" >> $GITHUB_ENV

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_TOKEN }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
file: ./build/Dockerfile.dist
platforms: linux/amd64,linux/arm64
push: true
tags: |
ghcr.io/movetokube/postgres-operator:latest
ghcr.io/movetokube/postgres-operator:${{ env.DOCKER_TAG }}
movetokube/postgres-operator:${{ env.DOCKER_TAG }}
movetokube/postgres-operator:latest
25 changes: 18 additions & 7 deletions build/Dockerfile.dist
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
FROM golang:1.18-stretch
# syntax=docker/dockerfile:1
FROM --platform=${BUILDPLATFORM} golang:1.18-stretch AS build

COPY . /go/src/github.com/movetokube/postgres-operator
WORKDIR /go/src/github.com/movetokube/postgres-operator/cmd/manager
ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG TARGETOS
ARG TARGETARCH

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /usr/local/bin/postgres-operator
WORKDIR /src
COPY go.mod go.sum ./
hitman99 marked this conversation as resolved.
Show resolved Hide resolved
RUN go mod download

COPY . .

FROM registry.access.redhat.com/ubi8/ubi-minimal:latest
RUN --mount=target=. \
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
go build -o /usr/local/bin/postgres-operator cmd/manager/main.go

FROM --platform=${TARGETPLATFORM} registry.access.redhat.com/ubi8/ubi-minimal:latest

ENV OPERATOR=/usr/local/bin/postgres-operator \
USER_UID=1001 \
Expand All @@ -20,5 +32,4 @@ RUN /usr/local/bin/user_setup

ENTRYPOINT ["/usr/local/bin/entrypoint"]

USER ${USER_UID}

USER ${USER_UID}