-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDockerfile-books
49 lines (41 loc) · 1.69 KB
/
Dockerfile-books
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
# Build the Go Binary.
FROM golang:1.22.2 as build_books-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 /book-library
# 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.* /book-library/
WORKDIR /book-library
RUN go mod download
# Copy the source code into the container.
COPY cmd cmd
COPY internal internal
# Build the admin tool so we can have it in the container. This should change
# often so do this first.
WORKDIR /book-library/cmd/${PACKAGE_PREFIX}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 /book-library/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_books-api /book-library/cmd/book-api/oidc /app-library/oidc
COPY --from=build_books-api /book-library/cmd/${PACKAGE_PREFIX}admin/admin /app-library/book-api
COPY --from=build_books-api /book-library/cmd/${PACKAGE_PREFIX}${PACKAGE_NAME}/${PACKAGE_NAME} /app-library/book-api
WORKDIR /app-library
CMD ["./book-api"]
LABEL org.opencontainers.image.created="${BUILD_DATE}" \
org.opencontainers.image.title="book-api" \
org.opencontainers.image.authors="Hergy Fongue" \
org.opencontainers.image.source="https://github.com/rjtch/book-library/cmd/book-api" \
org.opencontainers.image.revision="${VCS_REF}"