use multi stage build for website to slim down the image

This commit is contained in:
Karol Wypchlo 2022-04-22 14:45:44 +02:00
parent 5d33b79f69
commit 5bde83fc19
No known key found for this signature in database
GPG Key ID: B515DE9EEBE241E1
1 changed files with 17 additions and 7 deletions

View File

@ -1,15 +1,15 @@
FROM node:16.14.2-alpine # builder stage - use debian base image to avoid needing to install missing packages
FROM node:16.14.2-bullseye as builder
RUN apk add --no-cache autoconf=2.71-r0 automake=1.16.4-r1 build-base=0.5-r2 libtool=2.4.6-r7 nasm=2.15.05-r0 pkgconf=1.8.0-r0
WORKDIR /usr/app WORKDIR /usr/app
# disable gatsby telemetry and installing cypress binary
ENV GATSBY_TELEMETRY_DISABLED 1
ENV CYPRESS_INSTALL_BINARY 0
COPY packages/website/package.json \ COPY packages/website/package.json \
packages/website/yarn.lock \ packages/website/yarn.lock \
./ ./
ENV GATSBY_TELEMETRY_DISABLED 1
ENV CYPRESS_INSTALL_BINARY 0
RUN yarn --frozen-lockfile RUN yarn --frozen-lockfile
COPY packages/website/data ./data COPY packages/website/data ./data
@ -22,6 +22,16 @@ COPY packages/website/gatsby-*.js \
RUN yarn build RUN yarn build
# main stage - use alpine base image to minimise the resulting image footprint
FROM node:16.14.2-alpine
WORKDIR /usr/app
# install http server for serving website files
RUN npm install --global http-server@14.1.0
COPY --from=builder /usr/app/public /usr/app/public
EXPOSE 9000 EXPOSE 9000
CMD ["sh", "-c", "yarn serve --host 0.0.0.0"] CMD http-server /usr/app/public -s -p 9000