generated from rog-golang-buddies/golang-template-repository
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update dockerfile to fix earlier issue with non-existent directory * added docker image workflow to enable build after push on main branch
- Loading branch information
1 parent
122d68c
commit b0e2720
Showing
2 changed files
with
28 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |