From 27c718894a2f16acd57167a2c8a49510903f2bfb Mon Sep 17 00:00:00 2001 From: Adam Sven Johnson Date: Wed, 21 Sep 2022 14:14:29 +1200 Subject: [PATCH 1/3] Pin golang image to alpine go 1.17 Rely on the .dockerignore file to prevent adding unnecessary files to the context, then the COPY command can just add everything in the workspace. --- .dockerignore | 7 +++++-- Dockerfile | 9 ++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.dockerignore b/.dockerignore index fa0072ab..05d6ce42 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,5 +1,8 @@ .git -docs -contrib Dockerfile Makefile +bramble +contrib +docs +examples +testsrv diff --git a/Dockerfile b/Dockerfile index f8341387..5c6d98da 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,8 @@ -FROM golang:1.17 AS builder +FROM golang:1.17-alpine3.15 AS builder ARG VERSION=SNAPSHOT ENV GO111MODULE=on +ENV CGO_ENABLED=0 WORKDIR /workspace @@ -9,9 +10,7 @@ COPY go.mod go.sum /workspace/ RUN go mod download -COPY *.go /workspace/ -COPY cmd /workspace/cmd -COPY plugins /workspace/plugins +COPY . /workspace/ RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-X 'github.com/movio/bramble.Version=$VERSION'" -o bramble ./cmd/bramble @@ -23,4 +22,4 @@ EXPOSE 8082 EXPOSE 8083 EXPOSE 8084 -CMD [ "/bramble", "-conf", "/config.json" ] +CMD [ "/bramble", "-config", "/config.json" ] From f852508c1268d4c820f85077db0f215f0e8ffb0a Mon Sep 17 00:00:00 2001 From: Adam Sven Johnson Date: Wed, 21 Sep 2022 14:15:47 +1200 Subject: [PATCH 2/3] Pin example services to set versions on alpine golang:1.17 for the go services node:18 for the js service --- examples/gqlgen-service/Dockerfile | 4 +++- examples/graph-gophers-service/Dockerfile | 4 +++- examples/nodejs-service/Dockerfile | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/examples/gqlgen-service/Dockerfile b/examples/gqlgen-service/Dockerfile index b247a91b..50f31e5a 100644 --- a/examples/gqlgen-service/Dockerfile +++ b/examples/gqlgen-service/Dockerfile @@ -1,4 +1,6 @@ -FROM golang +FROM golang:1.17-alpine3.15 + +ENV CGO_ENABLED=0 WORKDIR /go/src/app diff --git a/examples/graph-gophers-service/Dockerfile b/examples/graph-gophers-service/Dockerfile index b7fa7e0a..dbf7b7cb 100644 --- a/examples/graph-gophers-service/Dockerfile +++ b/examples/graph-gophers-service/Dockerfile @@ -1,4 +1,6 @@ -FROM golang +FROM golang:1.17-alpine3.15 + +ENV CGO_ENABLED=0 WORKDIR /go/src/app diff --git a/examples/nodejs-service/Dockerfile b/examples/nodejs-service/Dockerfile index adf27e55..260b1029 100644 --- a/examples/nodejs-service/Dockerfile +++ b/examples/nodejs-service/Dockerfile @@ -1,4 +1,4 @@ -FROM node +FROM node:18-alpine3.15 COPY . . From 8c8f08fec4ccb5a447dd71d72ce853648d25a17a Mon Sep 17 00:00:00 2001 From: Adam Sven Johnson Date: Wed, 21 Sep 2022 14:16:46 +1200 Subject: [PATCH 3/3] Use wget for healthcheck curl is not present by default on alpine --- docker-compose.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index 35cefa1e..59ffafeb 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -4,7 +4,7 @@ services: build: context: examples/gqlgen-service healthcheck: - test: curl --fail http://localhost:8080/health || exit 1 + test: wget -qO - http://localhost:8080/health interval: 5s timeout: 1s retries: 5 @@ -12,7 +12,7 @@ services: - 8080 gophers-server: healthcheck: - test: curl --fail http://localhost:8080/health || exit 1 + test: wget -qO - http://localhost:8080/health interval: 5s timeout: 1s retries: 5 @@ -22,7 +22,7 @@ services: - 8080 nodejs-server: healthcheck: - test: curl --fail http://localhost:8080/health || exit 1 + test: wget -qO - http://localhost:8080/health interval: 5s timeout: 1s retries: 5