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.14 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
26
27ARG version
28RUN go build  -ldflags="-X github.com/zikaeroh/codies/internal/version.version=${version}" .
29
30# TODO: Use distroless/static and statically compile above. (https://golang.org/issue/26492)
31FROM gcr.io/distroless/base:nonroot
32WORKDIR /codies
33COPY --from=GO_BUILD /codies/codies ./codies
34COPY --from=JS_BUILD /frontend/build ./frontend/build
35ENTRYPOINT [ "/codies/codies", "--prod" ]
36EXPOSE 5000