Skip to content
Snippets Groups Projects
Commit 3a350086 authored by Jussi Mäki-Ikola's avatar Jussi Mäki-Ikola
Browse files

initial idea for multistage builds

parent ec429707
No related branches found
No related tags found
No related merge requests found
......@@ -8,5 +8,6 @@ module.exports = {
parserOptions: {
ecmaVersion: 2018,
sourceType: "module"
}
},
ignorePatterns: ["dist/"],
};
\ No newline at end of file
FROM node:10.16.3-alpine
FROM node:10.16.3-alpine AS builder
RUN apk add --no-cache bash
WORKDIR /usr/src/app
COPY package.json /usr/src/app/
COPY package-lock.json /usr/src/app/
COPY package*.json ./
# install node packages for production
RUN npm set progress=false && npm config set depth 0
RUN npm install --only=production
# copy production node_modules aside
RUN cp -R node_modules prod_node_modules
# install ALL node_modules, including 'devDependencies'
RUN npm install
# Run build
COPY . ./
RUN npm run build
# Development
FROM node:10.16.3-alpine AS dev
RUN apk add --no-cache bash
WORKDIR /usr/src/app
COPY --from=builder node_modules ./node_modules
COPY . /usr/src/app
EXPOSE 4000
CMD ["npm", "run", "dev"]
# Production image.
FROM node:10.16.3-alpine AS prod
WORKDIR /usr/src/app
COPY --from=builder prod_node_modules ./node_modules
COPY --from=builder dist ./dist
COPY package*.json /usr/src/app/
EXPOSE 4000
CMD ["npm", "run", "start"]
\ No newline at end of file
......@@ -4,7 +4,8 @@
"description": "",
"main": "dist/index.js",
"scripts": {
"start": "tsc && NODE_ENV=production node dist/index.js",
"start": "NODE_ENV=production node dist/index.js",
"build": "tsc",
"dev": "concurrently -r \"npm:lint-code:watch\" \"npm:lint-type:watch\" \"npm:dev-init\"",
"dev-init": "NODE_ENV=development nodemon -w ./src --ext .ts --exec ts-node ./src/index.ts",
"lint-type": "tsc --noEmit",
......
......@@ -7,5 +7,7 @@
"sourceMap": true,
"outDir": "dist"
},
"lib": ["es2015"]
"lib": ["es2015"],
"include": ["src"],
"exclude": ["src/__mocks__/", "src/tests/", "node_modules"]
}
......@@ -14,12 +14,16 @@ services:
depends_on:
- postgres
api:
build: ./api
build:
context: ./api
target: dev
volumes:
- ./api:/usr/src/app
command: npm run dev
ui:
build: ./ui
build:
context: ./ui
target: dev
volumes:
- ./ui:/usr/src/app
command: npm run dev
......@@ -2,10 +2,12 @@ version: "3.7"
services:
migrate:
image: ${CI_REGISTRY_IMAGE-local}/migrate:${CI_COMMIT_SHORT_SHA-latest}
build: ./migrate
command: up
env_file: .env
api:
image: ${CI_REGISTRY_IMAGE-local}/api:${CI_COMMIT_SHORT_SHA-latest}
build: ./api
ports:
- "4000:4000"
env_file: .env
......@@ -14,6 +16,7 @@ services:
UI_PORT: 3000
ui:
image: ${CI_REGISTRY_IMAGE-local}/ui:${CI_COMMIT_SHORT_SHA-latest}
build: ./ui
ports:
- "3000:3000"
environment:
......
FROM node:10.16.3-alpine
FROM node:10.16.3-alpine AS base
COPY package*.json ./
# install node packages for production
RUN npm set progress=false && npm config set depth 0
RUN npm install --only=production
# copy production node_modules aside
RUN cp -R node_modules prod_node_modules
# install ALL node_modules, including 'devDependencies'
RUN npm install
# Development image
FROM node:10.16.3-alpine AS dev
RUN apk add --no-cache bash
WORKDIR /usr/src/app
COPY package.json /usr/src/app/
COPY package-lock.json /usr/src/app/
RUN npm install
COPY --from=base node_modules ./node_modules
COPY . /usr/src/app
EXPOSE 3000
CMD ["npm", "run", "dev"]
# Build image
FROM node:10.16.3-alpine AS build
WORKDIR /usr/src/app
COPY --from=base node_modules ./node_modules
COPY . /usr/src/app
RUN npm run build
# Production image
FROM node:10.16.3-alpine AS prod
WORKDIR /usr/src/app
COPY --from=base prod_node_modules ./node_modules
COPY --from=build /usr/src/app/.nuxt .nuxt
COPY package*.json /usr/src/app/
COPY static /usr/src/app/static
COPY assets /usr/src/app/assets
EXPOSE 3000
CMD ["npm", "run", "start"]
......@@ -73,6 +73,7 @@ export default {
});
}
},
hardSource: true,
// analyze: true,
extractCSS: true,
terser: {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment