From 72fafa2470b49f84ffafb587705170bfe2b92a6d Mon Sep 17 00:00:00 2001 From: Ludvig Hozman Date: Sun, 15 Jan 2023 20:35:50 +0100 Subject: [PATCH] Update to node 16 & fix some build errors - Rewrite Dockerfile to use multi-stage build - The html template did not get included in the build. - There was some incorrect configuration in the client webpack config with the outputPath did not get put in the dist folder --- .drone.yml | 12 ++++++------ Dockerfile | 18 +++++++++++++++--- app/digital/template.html | 2 +- app/errors/index.ts | 3 +++ global.d.ts | 5 +++++ webpack.config.js | 2 +- webpack.server.js | 1 + 7 files changed, 32 insertions(+), 11 deletions(-) diff --git a/.drone.yml b/.drone.yml index 3fc31b41..29d2ce45 100644 --- a/.drone.yml +++ b/.drone.yml @@ -5,7 +5,7 @@ name: default steps: - name: setup - image: node:14 + image: node:16-alpine when: event: - push @@ -13,7 +13,7 @@ steps: - yarn install --frozen-lockfile --ignore-scripts - name: lint - image: node:14 + image: node:16-alpine when: event: - push @@ -23,7 +23,7 @@ steps: - yarn lint - name: test - image: node:14 + image: node:16-alpine when: event: - push @@ -33,7 +33,7 @@ steps: - MONGO_URL=mongodb://mongodb:27017/vote-test REDIS_URL=redis yarn mocha - name: coverage - image: node:14 + image: node:16-alpine when: event: - push @@ -49,7 +49,7 @@ steps: COVERALLS_SERVICE_NUMBER: ${DRONE_BUILD_NUMBER} - name: build - image: node:14 + image: node:16-alpine when: event: - push @@ -137,4 +137,4 @@ services: --- kind: signature -hmac: 21eea9888fa631a87ec5a02ee2d6f8f5c2b41767ecbe7f9fe0ee4d66e03325c6 +hmac: 1ec26cb4fae5d5b6f779d65ff5bd4dd4063ec3770e5527ef8c3447e0c700c9f8 diff --git a/Dockerfile b/Dockerfile index eeb74e06..9ec703ee 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ -FROM node:14-slim -MAINTAINER Abakus Webkom +FROM node:16-alpine as builder +LABEL org.opencontainers.image.authors="Abakus Webkom " # Create app directory RUN mkdir -p /app @@ -11,7 +11,19 @@ EXPOSE 3000 COPY . /app # Build image -RUN yarn --production +RUN yarn --ignore-scripts +ENV NODE_ENV production +RUN yarn build + +FROM node:16-alpine + +WORKDIR /app + +COPY --from=builder /app/bin bin +COPY --from=builder /app/public public +COPY --from=builder /app/dist dist +COPY --from=builder /app/package.json . +COPY --from=builder /app/node_modules node_modules ARG RELEASE ENV RELEASE ${RELEASE} diff --git a/app/digital/template.html b/app/digital/template.html index 14b592a2..56b54cf4 100644 --- a/app/digital/template.html +++ b/app/digital/template.html @@ -218,7 +218,7 @@

{{title}}

{{/if}} {{#unless new}}
-

Du har allerede motatt en bruker, og vi har registrert at du har klart å logge inn. Det vil si at du ikke vi få tilsendt en nytt brukernavn og passord. Ta kontakt med webkom dersom du mener dette er feil. +

Du har allerede motatt en bruker, og vi har registrert at du har klart å logge inn. Det vil si at du ikke vil få tilsendt et nytt brukernavn og passord. Ta kontakt med webkom dersom du mener dette er feil.


{{/unless}} diff --git a/app/errors/index.ts b/app/errors/index.ts index bda6c0c7..21250a46 100644 --- a/app/errors/index.ts +++ b/app/errors/index.ts @@ -287,6 +287,9 @@ export const handleError = ( status?: number ): Response => { const statusCode = status || err.status || 500; + if (statusCode >= 500) { + console.error(err); + } return res.status(statusCode).json( err.payload || { name: err.name, diff --git a/global.d.ts b/global.d.ts index 76516121..8c5c7f1c 100644 --- a/global.d.ts +++ b/global.d.ts @@ -3,3 +3,8 @@ declare module '*.yml' { const data: any; export default data; } + +declare module '*.html' { + const content: string; + export default content; +} diff --git a/webpack.config.js b/webpack.config.js index 8e87b511..0da78501 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -4,7 +4,7 @@ const path = require('path'); module.exports = { mode: 'none', output: { - path: path.resolve(__dirname, '../', 'public'), + path: path.resolve(__dirname, 'dist', 'public'), filename: '[name].js', publicPath: '/static/', }, diff --git a/webpack.server.js b/webpack.server.js index 61f3cd2a..a71fe7d5 100644 --- a/webpack.server.js +++ b/webpack.server.js @@ -41,6 +41,7 @@ module.exports = { patterns: [ { from: 'app/views', to: 'app/views' }, { from: 'public', to: 'public' }, + { from: 'app/digital/template.html', to: './template.html' }, ], }), ],