Skip to content

Commit

Permalink
refactored Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
thenets authored and dannycoates committed Sep 7, 2019
1 parent 8f4a53d commit 90f6a07
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 29 deletions.
14 changes: 6 additions & 8 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
node_modules
.git
.tox
.circleci
.nyc_output
.vscode
.DS_Store
firefox
assets
docs
test
coverage
.nyc_output
docs
firefox
node_modules
54 changes: 47 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,59 @@
##
# Firefox Send - Mozilla
#
# License https://github.com/mozilla/send/blob/master/LICENSE
##


# Build project
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/
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
RUN npm install --production
RUN ls -la
RUN set -x \
# Build
&& npm ci \
&& npm run build


# Main image
FROM node:10-slim
RUN addgroup --gid 10001 app && adduser --disabled-password --gecos '' --gid 10001 --home /app --uid 10001 app
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 --from=builder /app .
COPY --chown=app: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"]
4 changes: 2 additions & 2 deletions build/readme.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion common/assets.js
Original file line number Diff line number Diff line change
@@ -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 = {};
Expand Down
File renamed without changes.
6 changes: 5 additions & 1 deletion common/readme.md
Original file line number Diff line number Diff line change
@@ -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`).
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.
9 changes: 1 addition & 8 deletions docs/docker.md
Original file line number Diff line number Diff line change
@@ -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:

Expand Down
4 changes: 2 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']
}
]
Expand Down Expand Up @@ -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']
}
]
Expand Down

0 comments on commit 90f6a07

Please sign in to comment.