Browse Source

Reduce docker image size

master
Joshua Rubingh 2 months ago
parent
commit
f3e80420a4
  1. 6
      .dockerignore
  2. 13
      docker-compose.yaml
  3. 48
      docker/Dockerfile
  4. 6
      docker/project.env

6
.dockerignore

@ -1,2 +1,6 @@
node_modules
npm-debug.log
npm-debug.log
.git*
.env
.drone.yml
.nuxt

13
docker-compose.yaml

@ -9,11 +9,14 @@ services:
# This feels like bad practice....
build:
context: ./
# The args below are just here for reference. For local testing, you cannot use the RUG cache
# But while building with Drones, you can. So Drones has this argument active!
# args:
# DOCKER_CACHE: registry.webhosting.rug.nl/cache/library/
args:
# The args below are just here for reference. For local testing, you cannot use the RUG cache
# But while building with Drones, you can. So Drones has this argument active!
# DOCKER_CACHE: registry.webhosting.rug.nl/cache/library/
- API_URL=https://workspaces.research.rug.nl/
- API_HTTPS=true
dockerfile: ./docker/Dockerfile
ports:
- 3000:3000
- 3000:3000

48
docker/Dockerfile

@ -1,6 +1,6 @@
# build stage
ARG DOCKER_CACHE
FROM ${DOCKER_CACHE}node:lts-alpine
FROM ${DOCKER_CACHE}node:lts-alpine as builder
# Set the build environments based on Docker ARGS
ARG API_URL
@ -16,8 +16,8 @@ ENV NUXT_PORT=3000
RUN apk update && apk upgrade
# Create home folder for app
ENV APP_HOME=/home/app/web
RUN mkdir -p ${APP_HOME}
ENV APP_HOME=/home/app
#RUN mkdir -p ${APP_HOME}
# Change the workdir.
WORKDIR ${APP_HOME}
@ -26,9 +26,47 @@ WORKDIR ${APP_HOME}
COPY . ${APP_HOME}
# Install the libaries and depencies
RUN yarn install
RUN yarn install \
--prefer-offline \
--frozen-lockfile \
--non-interactive \
--production=false
RUN yarn build
RUN rm -rf node_modules && \
NODE_ENV=production yarn install \
--prefer-offline \
--pure-lockfile \
--non-interactive \
--production=true
#ARG DOCKER_CACHE
FROM ${DOCKER_CACHE}node:lts-alpine
# Set the build environments based on Docker ARGS
#ARG API_URL
#ARG API_HTTPS
ENV API_URL=$API_URL
ENV API_HTTPS=$API_HTTPS
# Set the correct NuxtJS environments
ENV NUXT_HOST=0.0.0.0
ENV NUXT_PORT=3000
# Create home folder for app
ENV APP_HOME=/home/app
#RUN mkdir -p ${APP_HOME}
# Change the workdir.
WORKDIR ${APP_HOME}
COPY --from=builder /${APP_HOME} .
# Build the application
RUN NODE_ENV=production yarn build
#RUN NODE_ENV=production yarn build
# Open port for connection
EXPOSE ${NUXT_PORT}

6
docker/project.env

@ -1 +1,5 @@
# Nothing here for now
# Nothing here for now
# The environment variable `API_URL` will be set during image build and can't change afterwards. So set this in the docker-compose.yaml file
# The environment variable `API_HTTPS` will be set during image build and can't change afterwards. So set this in the docker-compose.yaml file
PROXY_URLS=https://workspaces.research.rug.nl/api/;https://workspaces.research.rug.nl/auth/;https://workspaces.research.rug.nl/oidc/
Loading…
Cancel
Save