-
Notifications
You must be signed in to change notification settings - Fork 2
/
Dockerfile
51 lines (40 loc) · 1.59 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# This dockerfile uses extends image https://hub.docker.com/sinlov/GoLang-PlayGround
# VERSION 1
# Author: sinlov
# dockerfile offical document https://docs.docker.com/engine/reference/builder/
# https://hub.docker.com/_/golang
FROM golang:1.19.12-bullseye as builder
ARG GO_ENV_PACKAGE_NAME=github.com/sinlov/GoLang-PlayGround
ARG GO_ENV_ROOT_BUILD_BIN_NAME=GoLang-PlayGround
ARG GO_ENV_ROOT_BUILD_BIN_PATH=build/${GO_ENV_ROOT_BUILD_BIN_NAME}
ARG GO_ENV_ROOT_BUILD_ENTRANCE=cmd/GoLang-PlayGround/main.go
ARG GO_PATH_SOURCE_DIR=/go/src
WORKDIR ${GO_PATH_SOURCE_DIR}
RUN mkdir -p ${GO_PATH_SOURCE_DIR}/${GO_ENV_PACKAGE_NAME}
COPY $PWD ${GO_PATH_SOURCE_DIR}/${GO_ENV_PACKAGE_NAME}
RUN cd ${GO_PATH_SOURCE_DIR}/${GO_ENV_PACKAGE_NAME} && \
go mod download -x
RUN cd ${GO_PATH_SOURCE_DIR}/${GO_ENV_PACKAGE_NAME} && \
CGO_ENABLED=0 \
go build \
-a \
-installsuffix cgo \
-ldflags '-w -s --extldflags "-static -fpic"' \
-tags netgo \
-o ${GO_ENV_ROOT_BUILD_BIN_PATH} \
${GO_ENV_ROOT_BUILD_ENTRANCE}
# https://hub.docker.com/_/alpine
FROM alpine:3.17
ARG DOCKER_CLI_VERSION=${DOCKER_CLI_VERSION}
ARG GO_ENV_PACKAGE_NAME=github.com/sinlov/GoLang-PlayGround
ARG GO_ENV_ROOT_BUILD_BIN_NAME=GoLang-PlayGround
ARG GO_ENV_ROOT_BUILD_BIN_PATH=build/${GO_ENV_ROOT_BUILD_BIN_NAME}
ARG GO_PATH_SOURCE_DIR=/go/src
#RUN apk --no-cache add \
# ca-certificates mailcap curl \
# && rm -rf /var/cache/apk/* /tmp/*
RUN mkdir /app
WORKDIR /app
COPY --from=builder ${GO_PATH_SOURCE_DIR}/${GO_ENV_PACKAGE_NAME}/${GO_ENV_ROOT_BUILD_BIN_PATH} .
ENTRYPOINT [ "/app/GoLang-PlayGround" ]
# CMD ["/app/GoLang-PlayGround", "--help"]