Skip to content

Commit

Permalink
Merge pull request #124 from brpaz/master
Browse files Browse the repository at this point in the history
Add support for multi platform builds
  • Loading branch information
hitman99 authored Nov 15, 2023
2 parents 3c2516d + 7644666 commit 76f09b1
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 23 deletions.
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 ./
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}

0 comments on commit 76f09b1

Please sign in to comment.