forked from ardanlabs/service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dockerfile.sales-api
50 lines (42 loc) · 1.73 KB
/
dockerfile.sales-api
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
# Build the Go Binary.
FROM golang:1.14.3 as build_sales-api
ENV CGO_ENABLED 0
ARG VCS_REF
ARG PACKAGE_NAME
ARG PACKAGE_PREFIX
# Create a location in the container for the source code. Using the
# default GOPATH location.
RUN mkdir -p /service
# Copy the module files first and then download the dependencies. If this
# doesn't change, we won't need to do this again in future builds.
# COPY go.* /service/
# WORKDIR /service
# RUN go mod download
# Copy the source code into the container.
WORKDIR /service
COPY . .
# Build the admin tool so we can have it in the container. This should change
# often so do this first.
WORKDIR /service/cmd/${PACKAGE_PREFIX}sales-admin
RUN go build -ldflags "-X main.build=${VCS_REF}"
# Build the service binary. We are doing this last since this will be different
# every time we run through this process.
WORKDIR /service/cmd/${PACKAGE_PREFIX}${PACKAGE_NAME}
RUN go build -ldflags "-X main.build=${VCS_REF}"
# Run the Go Binary in Alpine.
FROM alpine:3.7
ARG BUILD_DATE
ARG VCS_REF
ARG PACKAGE_NAME
ARG PACKAGE_PREFIX
COPY --from=build_sales-api /service/private.pem /app/private.pem
COPY --from=build_sales-api /service/cmd/${PACKAGE_PREFIX}sales-admin/sales-admin /app/admin
COPY --from=build_sales-api /service/cmd/${PACKAGE_PREFIX}${PACKAGE_NAME}/${PACKAGE_NAME} /app/main
WORKDIR /app
CMD ["/app/main"]
LABEL org.opencontainers.image.created="${BUILD_DATE}" \
org.opencontainers.image.title="${PACKAGE_NAME}" \
org.opencontainers.image.authors="William Kennedy <[email protected]>" \
org.opencontainers.image.source="https://github.com/ardanlabs/service/cmd/${PACKAGE_PREFIX}${PACKAGE_NAME}" \
org.opencontainers.image.revision="${VCS_REF}" \
org.opencontainers.image.vendor="Ardan Labs"