Dockerfile improvements

- Add missing build dependencies for `sharp` node module (dependency of
  `gatsby-plugin-sharp`).
- Add ARG instructions for firebase variables, allowing them to be set
  via --build-arg flags when building the image.
- Use `npm ci` instead of `npm install`, and execute it after copying
  only package*.json. This prevents having to fetch all dependencies if
  package*.json hasn't changed between builds.
- Use `node:alpine` instead of `node` - not an improvement per-se,
  but I happen to be more familiar with adding build dependecies in the
  alpine based node image.
This commit is contained in:
Matt Low
2021-02-13 23:29:23 -07:00
parent f1a911560d
commit d6ae8309b4

View File

@ -1,12 +1,32 @@
FROM node as builder
FROM node:alpine as builder
WORKDIR /app
COPY ./ /app/
RUN npm install
RUN apk update \
&& apk add --no-cache \
g++ \
yasm \
make \
automake \
autoconf \
libtool \
vips-dev
COPY package*.json ./
RUN npm ci
ARG FIREBASE_APIKEY
ARG FIREBASE_APPID
ARG FIREBASE_AUTHDOMAIN
ARG FIREBASE_DATABASEURL
ARG FIREBASE_MEASUREMENTID
ARG FIREBASE_MESSAGINGSENDERID
ARG FIREBASE_PROJECTID
ARG FIREBASE_STORAGEBUCKET
COPY . ./
RUN npm run build
FROM nginx:alpine
RUN rm -rf /usr/share/nginx/html
COPY --from=builder /app/public/ /usr/share/nginx/html
COPY server.conf /etc/nginx/conf.d/default.conf
COPY server.conf /etc/nginx/conf.d/default.conf