From d4ba8872c29f90b1a71022885134bc8bca5be1ff Mon Sep 17 00:00:00 2001 From: Osma Suominen Date: Wed, 20 Sep 2023 09:01:12 +0300 Subject: [PATCH] install Node dependencies in docker image using a multi-stage build --- .dockerignore | 2 +- dockerfiles/Dockerfile.ubuntu | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.dockerignore b/.dockerignore index afda011b8..76b3c7c9f 100644 --- a/.dockerignore +++ b/.dockerignore @@ -6,7 +6,7 @@ components plugins/* composer.phar composer.lock -tests/jena-fuseki* +node_modules .vagrant .project .DS_Store diff --git a/dockerfiles/Dockerfile.ubuntu b/dockerfiles/Dockerfile.ubuntu index 623fabd9d..cc60050e8 100644 --- a/dockerfiles/Dockerfile.ubuntu +++ b/dockerfiles/Dockerfile.ubuntu @@ -1,3 +1,13 @@ +# Stage 0: install Node dependencies +FROM node:18-alpine AS npm-installer + +WORKDIR /usr/src/app +COPY package.json ./ + +# install node.js dependencies e.g. Vue (but not the development dependencies) +RUN npm install --omit=dev + +# Stage 1: runtime image FROM ubuntu:22.04 LABEL maintainer="National Library of Finland" @@ -6,7 +16,6 @@ LABEL description="A Docker image for Skosmos with Apache httpd." ARG DEBIAN_FRONTEND=noninteractive -# git is necessary for some composer packages e.g. davidstutz/bootstrap-multiselect RUN apt-get update && apt-get install -y \ apache2 \ curl \ @@ -76,6 +85,8 @@ RUN php composer.phar install --no-dev --no-autoloader COPY . /var/www/html RUN php composer.phar install --no-dev +# install Node modules (from npm-installer stage) +COPY --from=npm-installer /usr/src/app/node_modules /var/www/html/node_modules # Configure Skosmos COPY dockerfiles/config/config-docker.ttl /var/www/html/config.ttl