Skip to content

Commit

Permalink
Merge pull request #6 from rog-golang-buddies/fix-dockerfile-issue-pa…
Browse files Browse the repository at this point in the history
…llasite99

Fix: Update Dockerfile
  • Loading branch information
pallasite99 authored Aug 13, 2023
2 parents 122d68c + b0e2720 commit 368115a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -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)
16 changes: 10 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit 368115a

Please sign in to comment.