diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index edc9dc68..9eda1e02 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 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