Skip to content
This repository has been archived by the owner on May 26, 2024. It is now read-only.

Commit

Permalink
build: upgrade Dockerfile from Node 16 to Node 18
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbert committed Feb 8, 2023
1 parent ae512c5 commit 78eb352
Showing 1 changed file with 14 additions and 75 deletions.
89 changes: 14 additions & 75 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,60 +1,26 @@
FROM mhart/alpine-node:16.4

ARG TZ=Europe/Amsterdam
ENV TZ Europe/Amsterdam

# Use `--no-cache` to get a smaller image, by removing unused files afterwards.
# The packages are sorted, one per line, to have better diffs in Git.
RUN \
apk add --no-cache \
bash \
git \
nano \
&& command -v bash \
&& command -v git \
&& command -v nano \
&& echo "$TZ" > /etc/timezone
FROM node:18.14-alpine3.17

ENV SHELL /bin/bash

ARG NPM_REGISTRY
ARG NPM_STRICT_SSL

RUN git config --global credential.helper 'cache' \
&& ( test "${NPM_STRICT_SSL}" && npm config set strict-ssl "${NPM_STRICT_SSL}" || true ) \
&& ( test "${NPM_REGISTRY}" && npm config set registry "${NPM_REGISTRY}" || true ) \
&& ( test "${HTTP_PROXY}" && npm config set proxy "${HTTP_PROXY}" || true ) \
&& ( test "${HTTP_PROXY}" && npm config set http-proxy "${HTTP_PROXY}" || true ) \
&& ( test "${HTTPS_PROXY}" && npm config set https-proxy "${HTTPS_PROXY}" || true ) \
&& npm cache clean --force 2> /dev/null

RUN mkdir -p /var/www \
&& addgroup -g 1000 node \
&& adduser \
-D \
-G node \
-h /var/www \
-s /bin/sh \
-u 1000 \
node \
&& chown -R node:node /var/www
ARG TZ=Europe/Amsterdam
ENV TZ Europe/Amsterdam

USER node

WORKDIR /var/www

COPY --chown=node:node package.json package-lock.json ./

ARG HUSKY_SKIP_INSTALL=true
ARG NODE_ENV
ARG NPM_REGISTRY
ARG NPM_STRICT_SSL
ARG NPM_TOKEN
ARG HUSKY_SKIP_INSTALL=true

ADD --chown=node:node ./ /var/www/

# For development, install `devDependencies`.

RUN if test "$NODE_ENV" = 'development'; \
then \
npm config set "//registry.npmjs.org/:_authToken" "${NPM_TOKEN}" \
&& npm ci \
&& npm ci --no-update-notifier \
&& npm config set "//registry.npmjs.org/:_authToken" "" \
&& npm cache clean --force 2> /dev/null \
; fi
Expand All @@ -63,47 +29,20 @@ then \
# for when NODE_ENV is "production" using a production mode install,
# leaving only the packages needed for production.

ADD --chown=node:node ./ /var/www/

RUN if test "$NODE_ENV" != 'development'; \
then \
npm config set "//registry.npmjs.org/:_authToken" "${NPM_TOKEN}" \
&& NODE_ENV=development npm ci \
&& NODE_ENV=development npm ci --no-update-notifier \
&& npm run build \
&& npm prune \
&& npm config set "//registry.npmjs.org/:_authToken" "" \
&& npm cache clean --force 2> /dev/null \
; fi

# Build and remove the devDependencies in one Docker layer to keep image size small
# For production, install `devDependencies` to be able to execute `npm run build`,
# but remove the `devDependencies` immediately afterwards to keep the Docker layer small.

ARG BUILD_DATE
ARG VCS_REF
ARG VERSION

LABEL \
org.label-schema.build-date="${BUILD_DATE}" \
org.label-schema.description="NL Design System example app with Next.js" \
org.label-schema.name="nl-design-system-with-next.js" \
org.label-schema.schema-version="1.0" \
org.label-schema.url="https://github.com/Robbert/nl-design-system-with-next.js" \
org.label-schema.usage="https://github.com/Robbert/nl-design-system-with-next.js/blob/main/README.md" \
org.label-schema.vcs-ref="${VCS_REF}" \
org.label-schema.vcs-url="https://github.com/Robbert/nl-design-system-with-next.js" \
org.label-schema.vendor="NL Design System Community" \
org.label-schema.version="${VERSION}"

# Add lowercase proxy settings for compatibility,
# but use uppercase exports for shellcheck compatibility.
# https://unix.stackexchange.com/a/212972
ENV \
HTTP_PROXY=$HTTP_PROXY \
HTTPS_PROXY=$HTTPS_PROXY \
NO_PROXY=$NO_PROXY \
http_proxy=$HTTP_PROXY \
https_proxy=$HTTPS_PROXY \
no_proxy=$NO_PROXY
EXPOSE 3000

ENTRYPOINT ["npm", "run"]

CMD ["start"]
CMD ["start"]

0 comments on commit 78eb352

Please sign in to comment.