From 90f6a07d4af4863165a827895a6d2a01ab948bde Mon Sep 17 00:00:00 2001 From: Luiz Felipe F M Costa Date: Fri, 6 Sep 2019 20:00:00 -0700 Subject: [PATCH] refactored Dockerfile --- .dockerignore | 16 +++---- Dockerfile | 60 ++++++++++++++++++++----- build/readme.md | 4 +- common/assets.js | 2 +- {build => common}/generate_asset_map.js | 0 common/readme.md | 6 ++- docs/docker.md | 9 +--- webpack.config.js | 4 +- 8 files changed, 68 insertions(+), 33 deletions(-) rename {build => common}/generate_asset_map.js (100%) diff --git a/.dockerignore b/.dockerignore index 3c90104a..f91dc6a9 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,10 +1,8 @@ -node_modules -.git -.tox -.DS_Store -firefox -assets -docs -test -coverage +.circleci .nyc_output +.vscode +.DS_Store +coverage +docs +firefox +node_modules \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 92b3e9d3..5570c2f2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,59 @@ -FROM node:10 AS builder -RUN addgroup --gid 10001 app && adduser --disabled-password --gecos '' --gid 10001 --home /app --uid 10001 app -COPY package*.json /app/ -WORKDIR /app -RUN npm install --production +## +# Firefox Send - Mozilla +# +# License https://github.com/mozilla/send/blob/master/LICENSE +## -FROM node:10-slim -RUN addgroup --gid 10001 app && adduser --disabled-password --gecos '' --gid 10001 --home /app --uid 10001 app + +# Build project +FROM node:10 AS builder +RUN set -x \ + # Add user + && addgroup --gid 10001 app \ + && adduser --disabled-password \ + --gecos '' \ + --gid 10001 \ + --home /app \ + --uid 10001 \ + app +COPY --chown=app:app . /app USER app WORKDIR /app -COPY --chown=app:app --from=builder /app . -COPY --chown=app:app . . +RUN ls -la +RUN set -x \ + # Build + && npm ci \ + && npm run build + + +# Main image +FROM node:10-slim +RUN set -x \ + # Add user + && addgroup --gid 10001 app \ + && adduser --disabled-password \ + --gecos '' \ + --gid 10001 \ + --home /app \ + --uid 10001 \ + app +RUN apt-get update && apt-get -y install git-core +USER app +WORKDIR /app +COPY --chown=app:app package*.json ./ +COPY --chown=app:app app app +COPY --chown=app:app common common +COPY --chown=app:app public/locales public/locales +COPY --chown=app:app server server +COPY --chown=app:app --from=builder /app/dist dist + +RUN ls -la +RUN npm ci --production && npm cache clean --force RUN mkdir -p /app/.config/configstore RUN ln -s dist/version.json version.json ENV PORT=1443 -EXPOSE $PORT + +EXPOSE ${PORT} CMD ["node", "server/bin/prod.js"] diff --git a/build/readme.md b/build/readme.md index 5055bfdf..b8fc18d7 100644 --- a/build/readme.md +++ b/build/readme.md @@ -1,8 +1,8 @@ # Custom Loaders -## Generate Asset Map +## Android Index Plugin -This loader enumerates all the files in `assets/` so that `common/assets.js` can provide mappings from the source filename to the hashed filename used on the site. +Generates the `index.html` page for the native android client ## Version Plugin diff --git a/common/assets.js b/common/assets.js index 9bbced6f..f1a4657e 100644 --- a/common/assets.js +++ b/common/assets.js @@ -1,4 +1,4 @@ -const genmap = require('../build/generate_asset_map'); +const genmap = require('./generate_asset_map'); const isServer = typeof genmap === 'function'; let prefix = ''; let manifest = {}; diff --git a/build/generate_asset_map.js b/common/generate_asset_map.js similarity index 100% rename from build/generate_asset_map.js rename to common/generate_asset_map.js diff --git a/common/readme.md b/common/readme.md index cbfe0ae2..0aaad7ac 100644 --- a/common/readme.md +++ b/common/readme.md @@ -1,3 +1,7 @@ # Common Code -This directory contains code loaded by both the frontend `app` and backend `server`. The code here can be challenging to understand at first because the contexts for the two (three counting the dev server) environments that include them are quite different, but the purpose of these modules are quite simple, to provide mappings from the source assets (`copy-16.png`) to the concrete production assets (`copy-16.db66e0bf.svg`). \ No newline at end of file +This directory contains code loaded by both the frontend `app` and backend `server`. The code here can be challenging to understand at first because the contexts for the two (three counting the dev server) environments that include them are quite different, but the purpose of these modules are quite simple, to provide mappings from the source assets (`copy-16.png`) to the concrete production assets (`copy-16.db66e0bf.svg`). + +## Generate Asset Map + +This loader enumerates all the files in `assets/` so that `common/assets.js` can provide mappings from the source filename to the hashed filename used on the site. \ No newline at end of file diff --git a/docs/docker.md b/docs/docker.md index d230558a..975a95b2 100644 --- a/docs/docker.md +++ b/docs/docker.md @@ -1,13 +1,6 @@ ## Setup -Before building the Docker image, you must build the production assets: - -```sh -npm run build -``` - -Then you can run either `docker build` or `docker-compose up`. - +Run `docker build -t send:latest .` to create an image or `docker-compose up` to run a full testable stack. *We don't recommend using docker-compose for production.* ## Environment variables: diff --git a/webpack.config.js b/webpack.config.js index 59bd140c..de203880 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -67,7 +67,7 @@ const serviceWorker = { }, { // loads all assets from assets/ for use by common/assets.js - test: require.resolve('./build/generate_asset_map.js'), + test: require.resolve('./common/generate_asset_map.js'), use: ['babel-loader', 'val-loader'] } ] @@ -176,7 +176,7 @@ const web = { }, { // loads all assets from assets/ for use by common/assets.js - test: require.resolve('./build/generate_asset_map.js'), + test: require.resolve('./common/generate_asset_map.js'), use: ['babel-loader', 'val-loader'] } ]