From 3078aa0adadc3a70cf18cb8f5e8f8e5a56d13f33 Mon Sep 17 00:00:00 2001 From: ruflin Date: Thu, 12 Sep 2019 15:34:23 +0200 Subject: [PATCH] Fix Docker image to specific Golang version So far the `:latest` image was used for Golang. To be used in production I prefer to tied it to a very specific version so we know what is run and what we test is identical. A file `.go-version` was introduced which long term should serve as the single point of through for the go version, also for CI. At the moment it is only there for documentation purpose. The ENTRYPOINT of the Dockerfile was split up into ENTRYPOINT to make it easier to overwrite parameters. Note: As part of this change I also looked into using the alpine Golang image but it does not have Git included, which makes working with the Golang mod dependency trickier. --- .go-version | 1 + Dockerfile | 6 ++++-- README.md | 6 ++++++ 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 .go-version diff --git a/.go-version b/.go-version new file mode 100644 index 000000000..feaae22ba --- /dev/null +++ b/.go-version @@ -0,0 +1 @@ +1.13.0 diff --git a/Dockerfile b/Dockerfile index 0b2d518ad..638305fa8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,5 @@ -FROM golang:latest +ARG GO_VERSION +FROM golang:${GO_VERSION:-1.13.0} RUN \ apt-get update \ @@ -20,5 +21,6 @@ RUN mage build # If we keep it, it means all packages exist twice. RUN rm -rf dev +ENTRYPOINT ["go", "run", "."] # Make sure it's accessible from outside the container -ENTRYPOINT ["go", "run", ".", "--address=0.0.0.0:8080"] +CMD ["--address=0.0.0.0:8080"] diff --git a/README.md b/README.md index cd49001c3..6aaa404a1 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,12 @@ There are several options to run this. ### Go command +To use the correct golang version, run: + +``` +gvm use $(cat .go-version) +``` + When using the go command, first the example packages must be built: `mage build`