From 81570b42c0b387c7985d4ef24cf40589157b54e4 Mon Sep 17 00:00:00 2001 From: Paramtamtam <7326800+tarampampam@users.noreply.github.com> Date: Sun, 3 Sep 2023 20:16:50 +0400 Subject: [PATCH] chore: The docker environment is refactored --- Dockerfile | 18 ++++++++++++++---- docker-compose.yml | 7 +++---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5c1e2b2..a882b73 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,17 @@ -# syntax=docker/dockerfile:1.2 +# syntax=docker/dockerfile:1 -# Image page: -FROM golang:1.21-alpine as builder +# this stage is used to build the application +FROM golang:1.21-bullseye as builder + +COPY ./go.* /src/ + +WORKDIR /src + +# burn the modules cache +RUN go mod download + +# this stage is used to compile the application +FROM builder AS compiler # can be passed with any prefix (like `v1.2.3@GITHASH`), e.g.: `docker build --build-arg "APP_VERSION=v1.2.3@GITHASH" .` ARG APP_VERSION="undefined@docker" @@ -13,8 +23,8 @@ COPY . . # arguments to pass on each go tool link invocation ENV LDFLAGS="-s -w -X gh.tarampamp.am/error-pages/internal/version.version=$APP_VERSION" +# build the application RUN set -x \ - && go version \ && CGO_ENABLED=0 go build -trimpath -ldflags "$LDFLAGS" -o ./error-pages ./cmd/error-pages/ \ && ./error-pages --version \ && ./error-pages -h diff --git a/docker-compose.yml b/docker-compose.yml index d62694c..87612ad 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,9 +8,8 @@ volumes: golint-cache: {} services: - app: &app-service - image: golang:1.21-buster # Image page: - working_dir: /src + app: &go + build: {target: builder} environment: HOME: /tmp GOPATH: /tmp @@ -22,7 +21,7 @@ services: security_opt: [no-new-privileges:true] web: - <<: *app-service + <<: *go ports: - "8080:8080/tcp" # Open command: sh -c "go build -buildvcs=false -o /tmp/app ./cmd/error-pages && /tmp/app serve --show-details --proxy-headers=X-Foo,Bar,Baz_blah --catch-all"