From b0e2720a73dbfffeedfdf7b0ed113b163372d4c1 Mon Sep 17 00:00:00 2001 From: Salil Apte Date: Sun, 23 Jul 2023 21:40:59 +0530 Subject: [PATCH] Fix: Dockerfile image issue * update dockerfile to fix earlier issue with non-existent directory * added docker image workflow to enable build after push on main branch --- .github/workflows/docker-image.yml | 18 ++++++++++++++++++ Dockerfile | 16 ++++++++++------ 2 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/docker-image.yml diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..d657a63 --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,18 @@ +name: Docker Image CI + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Build the Docker image + run: docker build . --file Dockerfile --tag my-image-name:$(date +%s) diff --git a/Dockerfile b/Dockerfile index e9eedac..6e7ae23 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,17 @@ FROM golang:1.18 as build WORKDIR /go/src/app + +# Copy the entire source code to the container's workspace COPY . . -# Static build requires CGO_ENABLED=0 -RUN mkdir -p /go/bin && CGO_ENABLED=0 go build -ldflags="-w -s" -o /go/bin/app ./... +# Debugging step: Check current directory and contents of the 'cmd' directory +RUN pwd +RUN ls -la /go/src/app/cmd -# Using a distroless image from https://github.com/GoogleContainerTools/distroless -# Image sourced from https://console.cloud.google.com/gcr/images/distroless/global/static +# Static build +RUN CGO_ENABLED=0 go build -ldflags="-w -s" -o /go/bin/app ./cmd FROM gcr.io/distroless/static:nonroot -COPY --from=build /go/bin/app / -# numeric version of user nonroot:nonroot provided in image +COPY --from=build /go/bin/app /app + USER 65532:65532 + CMD ["/app"]