From 6d207c8817fa12cf674da1809735672034414043 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Pedersen?= Date: Tue, 30 May 2023 13:59:24 +0200 Subject: [PATCH] MLZ: use own dockerfile Change-Id: Ic983082ae1842af4566e61f9f3a1d6ce014f6b7a --- CI/MLZ/Dockerfile | 85 +++++++++++++++++++++++++++------------------- CI/MLZ/Jenkinsfile | 2 +- Dockerfile | 1 - 3 files changed, 51 insertions(+), 37 deletions(-) diff --git a/CI/MLZ/Dockerfile b/CI/MLZ/Dockerfile index 919f7ca7f..60f4d1cd7 100644 --- a/CI/MLZ/Dockerfile +++ b/CI/MLZ/Dockerfile @@ -1,38 +1,53 @@ -# gives a docker image below 200 MB -FROM node:18 +FROM node:18-alpine AS dev + +# Prepare app directory +WORKDIR /home/node/app +COPY . . +RUN cp ./CI/MLZ/frontend.config.ts ./src/config/ +RUN mv ./CI/MLZ/MLZ-access-group-service-factory.ts ./src/auth/access-group-provider/access-group-service-factory.ts + +# Set up local user +RUN mkdir /home/node/app/dist +RUN chown -R node:node /home/node/app +USER node + +# Install dependencies +RUN npm install glob rimraf +RUN npm install + +FROM node:18-alpine AS builder -ENV NODE_ENV "development" -ENV PORT 3000 -EXPOSE 3000 -# create local user to avoid running as root -RUN addgroup mygroup -RUN useradd -ms /bin/bash myuser -RUN mkdir -p /usr/src/app && chown -R myuser /usr/src/app # Prepare app directory WORKDIR /usr/src/app -COPY package*.json /usr/src/app/ -COPY CI/MLZ/frontend.config.json /usr/src/app/src/config/ -COPY CI/MLZ/migrate-mongo-config.js /usr/src/app/ -# RUN npm config set -g production false -# USER myuser -# Install our packages -RUN npm ci - -# patch for loopback-component-passport -# RUN sed -i "s|relations: modelDefinition.relations,|relations: modelDefinition.relations,acls: modelDefinition.acls|" node_modules/loopback-component-passport/lib/index.js - -# Copy the rest of our application, node_modules is ignored via .dockerignore -COPY . /usr/src/app -COPY CI/MLZ/envfiles/config.local.js /usr/src/app/server/ -COPY CI/MLZ/envfiles/providers.json /usr/src/app/server/ -COPY CI/MLZ/envfiles/datasources.json /usr/src/app/server/ -COPY CI/MLZ/component-config.json /usr/src/app/server/ -COPY CI/MLZ/envfiles/settings.json /usr/src/app/test/config/ -COPY CI/MLZ/start.sh /usr/src/app/start.sh -COPY CI/MLZ/frontend.config.json /usr/src/app/src/config/ -RUN mv /usr/src/app/CI/MLZ/MLZ-access-group-service-factory.ts /usr/src/auth/access-group-provider/access-group-service-factory.ts && \ - -# Start the app -RUN cat /usr/src/app/server/datasources.json -RUN echo "Running startup script" -CMD ./start.sh + +# Set up local user +# Copy files from dev image +COPY --from=dev /home/node/app . + +# Build app +RUN npm run build + +# Remove development dependencies +RUN npm prune --production + +FROM node:18-alpine + +# Prepare app directory +WORKDIR /home/node/app + +# Set up local user +RUN chown -R node:node /home/node/app +USER node + +# Copy files from builder image +COPY --from=builder --chown=node:node /usr/src/app/dist ./dist +COPY --from=builder --chown=node:node /usr/src/app/node_modules ./node_modules + +# Copy migration scripts so we can run them directly in the container if needed +COPY ./migrations ./migrations +COPY ./CI/MLZ/migrate-mongo-config.js ./migrate-mongo-config.js +COPY ./package.json ./package.json + +EXPOSE 3000 + +CMD ["node", "dist/src/main"] diff --git a/CI/MLZ/Jenkinsfile b/CI/MLZ/Jenkinsfile index 4c2f8b745..b3424be02 100644 --- a/CI/MLZ/Jenkinsfile +++ b/CI/MLZ/Jenkinsfile @@ -53,7 +53,7 @@ yaml: ''' stage('Build release') { ansiColor('xterm') { sh ''' - /kaniko/executor --context `pwd` --destination docker.ictrl.frm2.tum.de:5443/mlz/scicatv2:${tag} + /kaniko/executor --context `pwd` --dockerfile CI/MLZ/Dockerfile --destination docker.ictrl.frm2.tum.de:5443/mlz/scicatv2:${tag} ''' } } diff --git a/Dockerfile b/Dockerfile index 3a9767bbf..19391dad7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,6 @@ FROM node:18-alpine AS dev # Prepare app directory WORKDIR /home/node/app COPY . . -RUN cp ./CI/MLZ/frontend.config.ts ./src/config/ # Set up local user RUN mkdir /home/node/app/dist