From 3e67b28f4f480f80bc2ee7afdad3a0b6b497520e Mon Sep 17 00:00:00 2001 From: Mauro Scomparin Date: Wed, 26 Feb 2020 22:24:38 +0100 Subject: [PATCH] Created Dockerfile and run tests --- .github/workflows/go.yml | 4 ++-- Dockerfile | 10 ++++++++++ test/server_test.go => server_test.go | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 Dockerfile rename test/server_test.go => server_test.go (94%) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index f4915a4..984a4b7 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -25,7 +25,7 @@ jobs: fi - name: Test - run: go test -v + run: go test -v ./... - name: Build - run: go build -v . + run: go build -v diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4ddf89e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM golang:alpine as builder +RUN mkdir /build +ADD . /build/ +WORKDIR /build +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -v -tags netgo -ldflags '-w' -o server server.go + +FROM scratch +COPY --from=builder /build/server /app/ +WORKDIR /app +CMD ["./server"] diff --git a/test/server_test.go b/server_test.go similarity index 94% rename from test/server_test.go rename to server_test.go index 7d269c3..e94b28e 100644 --- a/test/server_test.go +++ b/server_test.go @@ -19,7 +19,7 @@ func TestReadEnvVarReturnsDefaultValueWhenEnvVarNotSet(t *testing.T) { } func TestReadEnvVarReturnsTheExpectedValueWhenSet(t *testing.T) { - os.SetEnv(envVar, expectedValue) + os.Setenv(envVar, expectedValue) res := ReadEnvVar(envVar, defaultValue) if res != expectedValue { t.Errorf("Did not return the expected value set in the enviroinment variable") -- 2.25.1