From 4826a810d0d153a307e1bab54a91556c0dbe6b10 Mon Sep 17 00:00:00 2001 From: Filip Johansson Date: Tue, 5 Jan 2021 17:51:24 +0100 Subject: [PATCH 1/2] Missing env file is not fatal --- src/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.go b/src/main.go index f6e5f8b..05b4052 100644 --- a/src/main.go +++ b/src/main.go @@ -36,7 +36,7 @@ func createAdminAccount(Db db.Db) { func main() { err := godotenv.Load() if err != nil { - log.Fatal("Error loading .env file") + log.Warn("Error loading .env file, this could be ok if the env file does not exist") } // Add this line for logging filename and line number! From 223830d3a1111ec1e3a195d94cfbba9e9f360b4a Mon Sep 17 00:00:00 2001 From: Filip Johansson Date: Tue, 5 Jan 2021 17:55:52 +0100 Subject: [PATCH 2/2] Added Dockerfile --- Dockerfile | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2910300 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +FROM golang:1.15.6-alpine AS builder + +# Install missing pkgs +RUN apk add --no-cache git + +# Set necessary environmet variables needed for our image +ENV GO111MODULE=on \ + CGO_ENABLED=0 \ + GOOS=linux \ + GOARCH=amd64 + +# Set workdir in GOPATH +WORKDIR $GOPATH/src/gitlab.larvit.se/power-plan/auth + +# Copy and download dependency using go mod +COPY go.mod . +COPY go.sum . +RUN go mod download + +# Copy the source code +COPY ./src ./src + +# Build the application +RUN go build -o /build/main ./src + +# Move to /dist directory as the place for resulting binary folder +WORKDIR /dist + +# Copy binary from build to main folder +RUN cp /build/main . + +# Build a small image +FROM scratch + +COPY --from=builder /dist/main / + +# Command to run +ENTRYPOINT ["/main"] \ No newline at end of file