Skip to content

Commit

Permalink
MLZ: use own dockerfile
Browse files Browse the repository at this point in the history
Change-Id: Ic983082ae1842af4566e61f9f3a1d6ce014f6b7a
  • Loading branch information
bpedersen2 committed Sep 8, 2023
1 parent 547531d commit 6d207c8
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 37 deletions.
85 changes: 50 additions & 35 deletions CI/MLZ/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
2 changes: 1 addition & 1 deletion CI/MLZ/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -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}
'''
}
}
Expand Down
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6d207c8

Please sign in to comment.