-
Notifications
You must be signed in to change notification settings - Fork 7
fix(Dockerfile): readability and golang image update #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e912938
f126524
6daad1b
e3287b4
38560e9
5e87c80
452aa49
84afbb1
ed33a5b
4d9a96a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,5 +15,9 @@ bin/ | |
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
# Code editor personal settings | ||
.vscode/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Forgive my persistence here, but why is this needed @mridulganga? I think its quite a given that one should not include the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since .vscode is used for local dev, we should not checkin that folder, so I included the same in .gitignore. |
||
.idea/ | ||
|
||
# Other | ||
.DS_Store |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
FROM golang:1.18 as build | ||
WORKDIR /go/src/app | ||
FROM golang:1.18-alpine as builder | ||
|
||
RUN apk update && apk upgrade && \ | ||
apk add --no-cache make bash | ||
|
||
WORKDIR /src | ||
COPY . . | ||
# Static build requires CGO_ENABLED=0 | ||
RUN mkdir -p /go/bin && CGO_ENABLED=0 go build -ldflags="-w -s" -o /go/bin/app ./... | ||
|
||
# Build executable | ||
RUN make build | ||
|
||
# Using a distroless image from https://github.com/GoogleContainerTools/distroless | ||
# Image sourced from https://console.cloud.google.com/gcr/images/distroless/global/static | ||
FROM gcr.io/distroless/static:nonroot | ||
COPY --from=build /go/bin/app / | ||
# numeric version of user nonroot:nonroot provided in image | ||
|
||
# Copy executable from builder image | ||
COPY --from=builder /src/bin/app / | ||
|
||
# Numeric version of user nonroot:nonroot provided in image | ||
USER 65532:65532 | ||
|
||
# Run the executable | ||
CMD ["/app"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
SHELL=/bin/bash -e -o pipefail | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mridulganga, Not sure if you tested this but this line would cause an error since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added bash now as well |
||
PWD = $(shell pwd) | ||
GO_BUILD= go build | ||
GOFLAGS= CGO_ENABLED=0 | ||
|
||
## help: Print this help message | ||
.PHONY: help | ||
|
@@ -37,4 +39,4 @@ fmt: | |
## build: Build binary into bin/ directory | ||
.PHONY: build | ||
build: | ||
go build -ldflags="-w -s" -o bin/app ./... | ||
$(GOFLAGS) $(GO_BUILD) -a -v -ldflags="-w -s" -o bin/app cmd/main.go | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This won't cross compile since the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed the GOOS variable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need to also think about injecting a global variable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jeffy-mathew yup, it is useful to have but perhaps as a separate issue. Feel free to create one. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,6 @@ sonar.organization=rog-golang-buddies | |
|
||
# Encoding of the source code. Default is default system encoding | ||
#sonar.sourceEncoding=UTF-8 | ||
|
||
# ensure that test files are identified and not used to check coverage | ||
sonar.test.inclusions=**/*_test.go | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we decide to remove this file, we could add an argument in gh sonarcloud workflow: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be beneficial to still keep task, launch, extensions etc? Personally have used this as a reference in the past: https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should not impose anyone's preferences of IDE config on others I think.