Dockerfile

 1FROM node:14 AS JS_BUILD
 2RUN apt-get update && \
 3    apt-get install -y --no-install-recommends jq moreutils && \
 4    rm -rf /var/lib/apt/lists/*
 5
 6WORKDIR /frontend
 7COPY ./frontend/package.json ./frontend/yarn.lock ./
 8RUN yarn install --frozen-lockfile
 9COPY ./frontend ./
10
11# If using environment variables (REACT_APP_*) to pass data in at build-time,
12# sometimes the values end up in the library code bundles. This means that changing
13# the verison (as below) would invalidate everyone's caches even if the actual code
14# didn't change. To avoid this, resort to using a JSON file that is edited before build.
15ARG version
16RUN jq ".version = \"${version}\"" ./src/metadata.json | sponge ./src/metadata.json
17RUN yarn build
18
19FROM golang:1.15 as GO_BUILD
20WORKDIR /codies
21COPY ./go.mod ./go.sum ./
22RUN go mod download
23# Manually copying the required files to make this image's cache only include Go code.
24COPY *.go ./
25COPY ./internal ./internal
26COPY --from=JS_BUILD /frontend/build ./frontend/build
27RUN go run github.com/markbates/pkger/cmd/pkger list && \
28    go run github.com/markbates/pkger/cmd/pkger -o internal/pkger
29
30ARG version
31RUN go build  -ldflags="-X github.com/zikaeroh/codies/internal/version.version=${version}" .
32
33# TODO: Use distroless/static and statically compile above. (https://golang.org/issue/26492)
34FROM gcr.io/distroless/base:nonroot
35COPY --from=GO_BUILD /codies/codies /codies
36ENTRYPOINT [ "/codies", "--prod" ]
37EXPOSE 5000
38
39# Verify that the binary works.
40RUN [ "/codies", "version" ]