From adb729d910ae399558aefd419a3d2e80159cd39c Mon Sep 17 00:00:00 2001 From: Bruno Paz <184563+brpaz@users.noreply.github.com> Date: Sun, 30 Jul 2023 16:02:55 +0100 Subject: [PATCH 01/10] multi platform build --- .github/workflows/release.yml | 49 +++++++++++++++++++++++------------ build/Dockerfile.dist | 25 +++++++++++++----- 2 files changed, 51 insertions(+), 23 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index edc9dc68..d4760bb6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -6,26 +6,43 @@ on: 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 + # Set docker tag in github env + 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: . + platforms: linux/amd64,linux/arm64 + push: true + tags: + ghcr.io/brpaz/postgres-operator:latest + ghcr.io/brpaz/postgres-operator:${DOCKER_TAG} + brpaz/postgres-operator:${DOCKER_TAG} + brpaz/postgres-operator:latest diff --git a/build/Dockerfile.dist b/build/Dockerfile.dist index 66b80fb1..3da0221f 100644 --- a/build/Dockerfile.dist +++ b/build/Dockerfile.dist @@ -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 \ @@ -20,5 +32,4 @@ RUN /usr/local/bin/user_setup ENTRYPOINT ["/usr/local/bin/entrypoint"] -USER ${USER_UID} - +USER ${USER_UID} \ No newline at end of file From b00b51e26c580ebc269ce0a082c84f48aad0b55e Mon Sep 17 00:00:00 2001 From: Bruno Paz <184563+brpaz@users.noreply.github.com> Date: Sun, 30 Jul 2023 16:07:25 +0100 Subject: [PATCH 02/10] multi platform build --- .github/workflows/release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d4760bb6..57730e49 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -43,6 +43,6 @@ jobs: push: true tags: ghcr.io/brpaz/postgres-operator:latest - ghcr.io/brpaz/postgres-operator:${DOCKER_TAG} - brpaz/postgres-operator:${DOCKER_TAG} + ghcr.io/brpaz/postgres-operator:${{ env.DOCKER_TAG }} + brpaz/postgres-operator:${{ env.DOCKER_TAG }} brpaz/postgres-operator:latest From 08b38d7d1b7bbb7dc2657637e9f33bcaabc99da0 Mon Sep 17 00:00:00 2001 From: Bruno Paz <184563+brpaz@users.noreply.github.com> Date: Sun, 30 Jul 2023 16:09:47 +0100 Subject: [PATCH 03/10] multi platform build --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 57730e49..3429a3a6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -41,7 +41,7 @@ jobs: context: . platforms: linux/amd64,linux/arm64 push: true - tags: + tags: | ghcr.io/brpaz/postgres-operator:latest ghcr.io/brpaz/postgres-operator:${{ env.DOCKER_TAG }} brpaz/postgres-operator:${{ env.DOCKER_TAG }} From 9dc8172b1ed045eab8735694c149d7a821f2062a Mon Sep 17 00:00:00 2001 From: Bruno Paz <184563+brpaz@users.noreply.github.com> Date: Sun, 30 Jul 2023 16:11:32 +0100 Subject: [PATCH 04/10] multi platform build --- .github/workflows/release.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3429a3a6..89b8a124 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -39,6 +39,7 @@ jobs: uses: docker/build-push-action@v4 with: context: . + file: ./build/Dockerfile.dist platforms: linux/amd64,linux/arm64 push: true tags: | From a8375093a91dc9c9da7712c132660d335ea167c8 Mon Sep 17 00:00:00 2001 From: Bruno Paz <184563+brpaz@users.noreply.github.com> Date: Sun, 30 Jul 2023 16:15:33 +0100 Subject: [PATCH 05/10] multi platform build --- .github/workflows/release.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 89b8a124..c5b6b268 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,6 +4,9 @@ on: release: types: [published] +permissions: + contents: read + packages: write jobs: build: runs-on: ubuntu-latest @@ -40,7 +43,7 @@ jobs: with: context: . file: ./build/Dockerfile.dist - platforms: linux/amd64,linux/arm64 + platforms: linux/amd64,linux/arm64,linux/arm/v7 push: true tags: | ghcr.io/brpaz/postgres-operator:latest From 663e77d6fceaf47f1ef2d9a2bcb29289bc8abd21 Mon Sep 17 00:00:00 2001 From: Bruno Paz <184563+brpaz@users.noreply.github.com> Date: Sun, 30 Jul 2023 16:23:05 +0100 Subject: [PATCH 06/10] multi platform build --- build/Dockerfile.dist | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build/Dockerfile.dist b/build/Dockerfile.dist index 3da0221f..a6f587a0 100644 --- a/build/Dockerfile.dist +++ b/build/Dockerfile.dist @@ -20,6 +20,8 @@ RUN --mount=target=. \ FROM --platform=${TARGETPLATFORM} registry.access.redhat.com/ubi8/ubi-minimal:latest +ARG TARGETPLATFORM + ENV OPERATOR=/usr/local/bin/postgres-operator \ USER_UID=1001 \ USER_NAME=postgres-operator From 5dc660e2d250c1245a9fbf76b3c653d244b5a2aa Mon Sep 17 00:00:00 2001 From: Bruno Paz <184563+brpaz@users.noreply.github.com> Date: Sun, 30 Jul 2023 16:30:16 +0100 Subject: [PATCH 07/10] multi platform build --- .github/workflows/release.yml | 2 +- build/Dockerfile.dist | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c5b6b268..5854fc38 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -43,7 +43,7 @@ jobs: with: context: . file: ./build/Dockerfile.dist - platforms: linux/amd64,linux/arm64,linux/arm/v7 + platforms: linux/amd64,linux/arm64 push: true tags: | ghcr.io/brpaz/postgres-operator:latest diff --git a/build/Dockerfile.dist b/build/Dockerfile.dist index a6f587a0..3da0221f 100644 --- a/build/Dockerfile.dist +++ b/build/Dockerfile.dist @@ -20,8 +20,6 @@ RUN --mount=target=. \ FROM --platform=${TARGETPLATFORM} registry.access.redhat.com/ubi8/ubi-minimal:latest -ARG TARGETPLATFORM - ENV OPERATOR=/usr/local/bin/postgres-operator \ USER_UID=1001 \ USER_NAME=postgres-operator From ff72d7bbab0ff16573dabc917119be58a3318b0e Mon Sep 17 00:00:00 2001 From: Bruno Paz <184563+brpaz@users.noreply.github.com> Date: Sun, 30 Jul 2023 16:39:55 +0100 Subject: [PATCH 08/10] multi platform build --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5854fc38..f8d8ebea 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -35,7 +35,7 @@ jobs: uses: docker/login-action@v2 with: registry: ghcr.io - username: ${{ github.repository_owner }} + username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Build and push From 71ac3e9b305e9c63a0b43f8db3971d395c67f1d6 Mon Sep 17 00:00:00 2001 From: Bruno Paz <184563+brpaz@users.noreply.github.com> Date: Sun, 30 Jul 2023 16:45:36 +0100 Subject: [PATCH 09/10] updates --- .github/workflows/release.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f8d8ebea..f8a207aa 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -16,7 +16,6 @@ jobs: - name: Generate Docker Tag run: | echo ${{ github.ref }} | cut -d '/' -f 3 > DOCKER_TAG - # Set docker tag in github env echo "DOCKER_TAG=$(cat DOCKER_TAG)" >> $GITHUB_ENV - name: Set up QEMU @@ -46,7 +45,7 @@ jobs: platforms: linux/amd64,linux/arm64 push: true tags: | - ghcr.io/brpaz/postgres-operator:latest - ghcr.io/brpaz/postgres-operator:${{ env.DOCKER_TAG }} - brpaz/postgres-operator:${{ env.DOCKER_TAG }} - brpaz/postgres-operator:latest + ghcr.io/movetokube/postgres-operator:latest + ghcr.io/movetokube/postgres-operator:${{ env.DOCKER_TAG }} + movetokube/postgres-operator:${{ env.DOCKER_TAG }} + movetokube/postgres-operator:latest From aba386ded45caf2937717b9433c3dc8d585dee9b Mon Sep 17 00:00:00 2001 From: Bruno Paz <184563+brpaz@users.noreply.github.com> Date: Sun, 30 Jul 2023 17:13:58 +0100 Subject: [PATCH 10/10] fix --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f8a207aa..9eda1e02 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -34,7 +34,7 @@ jobs: uses: docker/login-action@v2 with: registry: ghcr.io - username: ${{ github.actor }} + username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} - name: Build and push