-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
51 lines (41 loc) · 1.75 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 file is using multi-stage builds https://docs.docker.com/develop/develop-images/multistage-build/
### It requires 17.05 or higher to be run
########################################################################
### builder stage : Build the golang application in src folder
FROM golang:1.19-alpine as builder
ARG MODULE_NAME
COPY . /src
WORKDIR /src
RUN go build -o bin/main cmd/$MODULE_NAME/main.go
########################################################################
########################################################################
### app stage : Contains only binary and config and exposes the command
FROM alpine:latest as app
LABEL maintainer="[email protected]"
# Some arguments used for labelling
ARG BUILD_DATE
ARG VCS_REF
ARG BUILD_VERSION
ARG GITLAB_TOKEN
ARG PROJECT_NAME
ARG MODULE_NAME
ARG MODULE_DESCRIPTION
ARG DOCKER_IMAGE
# Labels.
LABEL org.label-schema.schema-version="1.0"
LABEL org.label-schema.build-date=$BUILD_DATE
LABEL org.label-schema.name="$PROJECT_NAME::$MODULE_NAME"
LABEL org.label-schema.description=$MODULE_DESCRIPTION
LABEL org.label-schema.url="https://www.$PROJECT_NAME.com/"
LABEL org.label-schema.vcs-url="https://github.com/$PROJECT_NAME/$MODULE_NAME"
LABEL org.label-schema.vcs-ref=$VCS_REF
LABEL org.label-schema.version=$BUILD_VERSION
LABEL org.label-schema.docker.cmd="docker run -it $DOCKER_IMAGE:$BUILD_VERSION"
# Two files are necessary from the build stage : the configuration and the binary
ENV CONFIGURATION_PATH=/etc/$MODULE_NAME/config.toml
ENV BINARY_PATH=/bin/$MODULE_NAME
COPY --from=builder /src/config.toml ${CONFIGURATION_PATH}
COPY --from=builder /src/bin/main $BINARY_PATH
# Build the main command
CMD .$BINARY_PATH
########################################################################