codies/Dockerfile

41 lines
1.5 KiB
Docker
Raw Normal View History

2020-05-23 21:51:11 +00:00
FROM node:14 AS JS_BUILD
RUN apt-get update && \
apt-get install -y --no-install-recommends jq moreutils && \
rm -rf /var/lib/apt/lists/*
2020-05-23 21:51:11 +00:00
WORKDIR /frontend
COPY ./frontend/package.json ./frontend/yarn.lock ./
RUN yarn install --frozen-lockfile
COPY ./frontend ./
# If using environment variables (REACT_APP_*) to pass data in at build-time,
# sometimes the values end up in the library code bundles. This means that changing
# the verison (as below) would invalidate everyone's caches even if the actual code
# didn't change. To avoid this, resort to using a JSON file that is edited before build.
ARG version
RUN jq ".version = \"${version}\"" ./src/metadata.json | sponge ./src/metadata.json
2020-05-23 21:51:11 +00:00
RUN yarn build
2020-08-12 23:46:59 +00:00
FROM golang:1.15 as GO_BUILD
2020-05-23 21:51:11 +00:00
WORKDIR /codies
COPY ./go.mod ./go.sum ./
RUN go mod download
# Manually copying the required files to make this image's cache only include Go code.
2020-05-25 05:18:35 +00:00
COPY *.go ./
2020-05-23 21:51:11 +00:00
COPY ./internal ./internal
2020-06-06 21:01:45 +00:00
COPY --from=JS_BUILD /frontend/build ./frontend/build
RUN go run github.com/markbates/pkger/cmd/pkger list && \
go run github.com/markbates/pkger/cmd/pkger -o internal/pkger
2020-05-23 22:14:58 +00:00
ARG version
RUN go build -ldflags="-X github.com/zikaeroh/codies/internal/version.version=${version}" .
2020-05-23 21:51:11 +00:00
# TODO: Use distroless/static and statically compile above. (https://golang.org/issue/26492)
FROM gcr.io/distroless/base:nonroot
2020-06-06 21:01:45 +00:00
COPY --from=GO_BUILD /codies/codies /codies
ENTRYPOINT [ "/codies", "--prod" ]
2020-05-23 21:51:11 +00:00
EXPOSE 5000
# Verify that the binary works.
RUN [ "/codies", "version" ]