From d9aa50d4808bd665d8f6bc38bf23ed2365332268 Mon Sep 17 00:00:00 2001 From: Anoop Gopalakrishnan Date: Sun, 7 Jan 2024 11:34:02 -0800 Subject: [PATCH] fix: Use the default docker registry --- .github/workflows/build-server.yml | 37 ++++++++++++++++++++++++------ Dockerfile | 27 ++++++++++++++-------- 2 files changed, 47 insertions(+), 17 deletions(-) diff --git a/.github/workflows/build-server.yml b/.github/workflows/build-server.yml index 5bbe636..b5924f8 100644 --- a/.github/workflows/build-server.yml +++ b/.github/workflows/build-server.yml @@ -1,6 +1,6 @@ # This is a basic workflow to help you get started with Actions -name: Docker Builds +name: build # Controls when the workflow will run on: @@ -20,7 +20,7 @@ on: - 'v*.*.*' - 'wip-github-actions' -permissions: +permissions: contents: read packages: write @@ -30,13 +30,36 @@ jobs: runs-on: ubuntu-latest strategy: fail-fast: false + matrix: + platform: + - linux/amd64 + - linux/arm/v6 + - linux/arm/v7 + - linux/arm64 + - linux/arm64/v8 + steps: + - name: Prepare + run: | + platform=${{ matrix.platform }} + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV + - name: Checkout uses: actions/checkout@v4 - name: Set up QEMU uses: docker/setup-qemu-action@v3 + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.21 + + - name: Tests + run: | + go mod tidy + # go test -v ./... + - name: Set up Docker Buildx id: buildx uses: docker/setup-buildx-action@v3 @@ -45,7 +68,6 @@ jobs: if: github.event_name != 'pull_request' uses: docker/login-action@v3 with: - registry: hub.docker.com username: ${{ secrets.FERN_DOCKER_USER }} password: ${{ secrets.FERN_DOCKER_SECRET }} @@ -53,10 +75,8 @@ jobs: id: meta_fern_reporter uses: docker/metadata-action@v5 with: - # list of Docker images to use as base name for tags images: | anoop2811/fern-reporter - # generate Docker tags based on the following events/attributes tags: | type=schedule type=ref,event=branch @@ -65,11 +85,14 @@ jobs: type=semver,pattern={{major}}.{{minor}} type=semver,pattern={{major}} type=sha + - name: Build and push uses: docker/build-push-action@v5 with: - context: . - platforms: linux/amd64,linux/arm/v7,linux/arm64/v8 + outputs: "type=registry,push=true" push: ${{ github.event_name != 'pull_request' }} + context: . + platforms: ${{ matrix.platform }} + # platforms: linux/amd64,linux/arm/v7,linux/arm64/v8 tags: ${{ steps.meta_fern_reporter.outputs.tags }} labels: ${{ steps.meta_fern_reporter.outputs.labels }} diff --git a/Dockerfile b/Dockerfile index a34e7da..bfb996b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,30 +1,37 @@ # Build stage -FROM golang:1.21-alpine AS build-env +FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.21 as builder -# Set up necessary Go environment variables (optional, based on your app's needs) -# ENV GO111MODULE=on \ -# CGO_ENABLED=0 \ -# GOOS=linux \ -# GOARCH=amd64 +ARG TARGETPLATFORM +ARG BUILDPLATFORM +ARG TARGETOS +ARG TARGETARCH + +ENV GO111MODULE=on # Set the working directory inside the container WORKDIR /app # Copy the source from the current directory to the working Directory inside the container COPY . . +RUN go mod download # Build the Go app -RUN go mod tidy && go mod vendor && go build -o fern . +# RUN go mod tidy && go build -o fern . + +RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o fern . # Final stage: Run stage -FROM alpine +FROM --platform=${BUILDPLATFORM:-linux/amd64} gcr.io/distroless/static:nonroot -# Copy the pre-built binary file from the previous stage -COPY --from=build-env /app/fern /app/fern # Set the working directory in the container WORKDIR /app +# Copy the pre-built binary file from the previous stage +COPY --from=builder /app/fern /app/fern + +USER nonroot:nonroot + # Command to run the binary CMD ["/app/fern"]