Skip to content
Permalink
Browse files

chore: much more efficient Docker files

  • Loading branch information...
evereq committed Sep 26, 2019
1 parent 7c84b21 commit fc549ceb02ff9ccff83729d37d339eeee2ef29a9
Showing with 70 additions and 61 deletions.
  1. +27 −27 .deploy/api/Dockerfile
  2. +26 −26 .deploy/webapp/Dockerfile
  3. +4 −1 .dockerignore
  4. +3 −0 .vscode/settings.json
  5. +10 −7 docker-compose.yml
@@ -1,48 +1,48 @@
# API

FROM node:alpine
FROM node:alpine AS development

RUN apk update
RUN apk update \
&& apk add libexecinfo libexecinfo-dev \
&& npm i -g npm \
&& apk --no-cache add --virtual builds-deps build-base \
snappy g++ snappy-dev gcc libgcc libstdc++ linux-headers autoconf automake make nasm python git \
&& npm install --quiet node-gyp -g \
&& npm config set python /usr/bin/python \
&& npm install yarn -g

RUN npm i -g npm
RUN mkdir /srv/gauzy && chown node:node /srv/gauzy

RUN apk add libexecinfo libexecinfo-dev
USER node

RUN apk --no-cache add --virtual builds-deps build-base \
snappy g++ snappy-dev gcc libgcc libstdc++ linux-headers autoconf automake make nasm python git && \
npm install --quiet node-gyp -g
WORKDIR /srv/gauzy

RUN npm config set python /usr/bin/python
COPY --chown=node:node package.json yarn.lock ./
COPY --chown=node:node apps/api/package.json ./apps/api/package.json
# COPY .snyk /tmp/.snyk
RUN yarn install

RUN npm install yarn -g
FROM node:alpine AS production

RUN npm install cross-env -g
ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.6.0/wait /wait

RUN npm install pm2 -g --unsafe-perm
RUN npm install cross-env -g \
&& npm install pm2 -g --unsafe-perm \
&& chmod +x /wait

# Make our app folder (empty for now)
RUN mkdir -p /usr/src/app
USER node

# Provides cached layer for node_modules and bower_components
COPY package.json /tmp/package.json
COPY apps/api/package.json /tmp/apps/api/package.json
# COPY .snyk /tmp/.snyk
COPY yarn.lock /tmp/yarn.lock
RUN cd /tmp/ && yarn install
RUN cp -a /tmp/node_modules /usr/src/app/
RUN cd /usr/src/app
WORKDIR /srv/gauzy

WORKDIR /usr/src/app
ARG NODE_OPTIONS="--max-old-space-size=2048"
ENV NODE_OPTIONS $NODE_OPTIONS
ENV NODE_ENV production

# Bundle app source
ADD . /usr/src/app
COPY --from=development --chown=root:root /srv/gauzy/node_modules ./node_modules
COPY --from=development --chown=root:root /srv/gauzy/apps/api/node_modules ./apps/api/node_modules

EXPOSE 3000
COPY . .

ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.6.0/wait /wait
RUN chmod +x /wait
EXPOSE 3000

CMD /wait && cross-env NODE_ENV=production NODE_OPTIONS=--max_old_space_size=2048 yarn ng serve api --host 0.0.0.0 -c=production --prod
@@ -1,47 +1,47 @@
# Webapp

FROM node:alpine
FROM node:alpine AS development

RUN apk update
RUN apk update \
&& apk add libexecinfo libexecinfo-dev \
&& npm i -g npm \
&& apk --no-cache add --virtual builds-deps build-base \
snappy g++ snappy-dev gcc libgcc libstdc++ linux-headers autoconf automake make nasm python git \
&& npm install --quiet node-gyp -g \
&& npm config set python /usr/bin/python \
&& npm install yarn -g

RUN npm i -g npm
RUN mkdir /srv/gauzy && chown node:node /srv/gauzy

RUN apk add libexecinfo libexecinfo-dev
USER node

RUN apk --no-cache add --virtual builds-deps build-base \
snappy g++ snappy-dev gcc libgcc libstdc++ linux-headers autoconf automake make nasm python git && \
npm install --quiet node-gyp -g
WORKDIR /srv/gauzy

RUN npm config set python /usr/bin/python
COPY --chown=node:node package.json yarn.lock ./
COPY --chown=node:node apps/api/package.json ./apps/api/package.json
# COPY .snyk /tmp/.snyk
RUN yarn install

RUN npm install yarn -g
FROM node:alpine AS production

RUN npm install cross-env -g
ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.6.0/wait /wait

RUN npm install pm2 -g --unsafe-perm
RUN npm install cross-env -g \
&& npm install pm2 -g --unsafe-perm \
&& chmod +x /wait

# Make our app folder (empty for now)
RUN mkdir -p /usr/src/app
USER node

# Provides cached layer for node_modules and bower_components
COPY package.json /tmp/package.json
# COPY .snyk /tmp/.snyk
COPY yarn.lock /tmp/yarn.lock
RUN cd /tmp/ && yarn install
RUN cp -a /tmp/node_modules /usr/src/app/
RUN cd /usr/src/app
WORKDIR /srv/gauzy

WORKDIR /usr/src/app
ARG NODE_OPTIONS="--max-old-space-size=2048"
ENV NODE_OPTIONS $NODE_OPTIONS
ENV NODE_ENV production

# Bundle app source
ADD . /usr/src/app
COPY --from=development --chown=root:root /srv/gauzy/node_modules ./node_modules

EXPOSE 4200
COPY . .

ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.6.0/wait /wait
RUN chmod +x /wait
EXPOSE 4200

CMD /wait && cross-env NODE_ENV=production NODE_OPTIONS=--max_old_space_size=2048 yarn run config:prod && yarn ng serve gauzy --disable-host-check --host 0.0.0.0 -c=production --prod
@@ -1,15 +1,18 @@
dist
tmp
.github
.circle
.npmrc
.travis.yml
greenkeeper.json
docker-compose.yml
docker-compose*.yml
*.md
.deploy
.git/
.gitignore

node_modules
apps/api/node_modules

# IDEs and editors
.idea
@@ -11,9 +11,11 @@
"envalid",
"fastify",
"healthcheck",
"letsencrypt",
"microservices",
"nestjs",
"nestjsx",
"nginx",
"nrwl",
"ormconfig",
"pgsql",
@@ -23,6 +25,7 @@
"toastr",
"typeorm",
"uploader",
"webapp",
"websockets"
],
"vsicons.presets.angular": true
@@ -1,4 +1,4 @@
version: '3.1'
version: '3.7'

services:
nginx:
@@ -130,9 +130,11 @@ services:
links:
- db
volumes:
- api:/usr/src/app
- .:/srv/gauzy
- webapp_node_modules:/srv/gauzy/node_modules
- api_node_modules:/srv/gauzy/apps/api/node_modules
ports:
- 3000:3000
- '3000:3000'
networks:
- overlay

@@ -153,16 +155,17 @@ services:
- db
- api
volumes:
- webapp:/usr/src/app
- .:/srv/gauzy
- webapp_node_modules:/srv/gauzy/node_modules
ports:
- 4200:4200
- '4200:4200'
networks:
- overlay

volumes:
webapp_node_modules:
api_node_modules:
postgres_data:
webapp:
api:
certificates:

networks:

0 comments on commit fc549ce

Please sign in to comment.
You can’t perform that action at this time.