Skip to content
This repository was archived by the owner on Jun 28, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
220445d
Rewriting Dockerfile and adding docker-compose support
hammady Oct 30, 2017
ad14741
Splitting API_URL to 2 variables depending on scenario
hammady Oct 30, 2017
095a1bd
Adding a README for docker-compose
hammady Oct 30, 2017
3c6f4bd
More in docker README about other images
hammady Oct 30, 2017
846cc02
Remove dependency on other docker images
hammady Dec 2, 2017
2f4ae16
Get CDN asset host from env ASSET_HOST
hammady Dec 2, 2017
1dba269
Use const instead of var for ASSET_HOST
hammady Dec 4, 2017
c9336a0
Merge remote-tracking branch 'upstream/master'
hammady Dec 17, 2017
7fb3640
Fix asset CDN to get fonts from fonts CDN
hammady Dec 20, 2017
7493bb9
Get asset host from env in production
hammady Dec 21, 2017
4ff388a
Remove .env, now variables loaded in compose
hammady Dec 31, 2017
e396754
Fix config not found in production
hammady Dec 31, 2017
111c0b7
Point assets to localhost till it is working
hammady Dec 31, 2017
7eed854
Setting api urls temporarily
hammady Dec 31, 2017
6aee214
Amend last commit after push :(
hammady Dec 31, 2017
e9870a7
Merge remote-tracking branch 'upstream/master'
hammady Jan 6, 2018
457b828
Fix Javascript errors
hammady Jan 8, 2018
ba42fa9
Fix fonts base URL
hammady Jan 8, 2018
6684f51
Select correct API URL (internal vs public)
hammady Jan 8, 2018
b2ee3ac
Create build-time environment variables for docker
hammady Jan 8, 2018
f107874
Add missing config for ASSET_HOST in prod.config.js
hammady Jan 8, 2018
2248eb3
Replace all page fonts by correct ones from CDN
hammady Jan 8, 2018
10790ba
Combine ASSET_HOST with FONTS_URL into one ASSETS_URL
hammady Jan 8, 2018
b9f07b8
Put correct values for build arguments
hammady Jan 13, 2018
5166da4
Fix eslint errors in metrics and server
hammady Jan 21, 2018
a57a1b2
Fix more eslint errors
hammady Jan 21, 2018
995be7e
Fix eslint error by importing config
hammady Jan 27, 2018
7f39c05
Remove fonts and move to a separate repo
hammady Jan 27, 2018
c3147df
Access fonts from a dedicated FONTS_URL env var
hammady Jan 27, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
10 changes: 0 additions & 10 deletions .env

This file was deleted.

79 changes: 37 additions & 42 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,50 +1,45 @@
FROM node:8.9

ENV NODE_ENV production
ENV API_URL http://api.quran.com:3000
ENV SENTRY_KEY_CLIENT https://app.getsentry.com
ENV SENTRY_KEY_SERVER https://app.getsentry.com

ENV FACEBOOK_APP_ID appid
ENV ONE_QURAN_URL https://one.quran.com
ENV PORT 8000
ENV NODE_PATH "./src"

RUN apt-get -y update && apt-get -y install supervisor ssh rsync

# logrotate
RUN apt-get -y install logrotate
COPY docker/supervisord.conf /etc/supervisor/supervisord.conf
COPY docker/pm2.logrotate.conf /etc/logrotate.d/pm2
RUN cp /etc/cron.daily/logrotate /etc/cron.hourly

# cache npm install when package.json hasn't changed
WORKDIR /tmp
ADD package.json package.json
RUN npm install --silent --no-progress
RUN npm install -g pm2
ARG node_env=production

RUN mkdir /quran
RUN cp -a /tmp/node_modules /quran
ENV NODE_ENV $node_env
ENV NODE_PATH ./src

RUN mkdir /quran
WORKDIR /quran
ADD . /quran/

RUN npm run build:client
RUN npm run build:server

# ssh keys
WORKDIR /root
RUN mv /quran/.ssh /root/
# cache node_modules using docker layers
# any change to package.json will rebuild modules
ADD package.json /quran/package.json
RUN if [ "$NODE_ENV" = "production" ]; then \
npm install --silent --production; \
else \
npm install; \
fi

# upload js and css
WORKDIR /quran/static/dist
RUN rsync --update --progress -raz . [email protected]:zones/assets/

# go back to /quran
WORKDIR /quran

ENV NODE_PATH "./dist"
# you would typically mount ./src:/quran/src during dev
ADD . /quran/

EXPOSE 8000
CMD ["supervisord", "--nodaemon", "-c", "/etc/supervisor/supervisord.conf"]
ARG facebook_app_id
ARG assets_url
ARG fonts_url
ARG public_api_url
ARG one_quran_url
ARG sentry_key_client

ENV FACEBOOK_APP_ID $facebook_app_id
ENV ASSETS_URL $assets_url
ENV FONTS_URL $fonts_url
ENV PUBLIC_API_URL $public_api_url
ENV ONE_QURAN_URL $one_quran_url
ENV SENTRY_KEY_CLIENT $sentry_key_client

RUN if [ "$NODE_ENV" = "production" ]; then \
npm run build:client && \
npm run build:server; \
fi

# port 8080 is needed in dev for the webpack live reload server
EXPOSE 8000 8080

CMD ["bin/server.sh"]
1 change: 0 additions & 1 deletion bin/server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require('dotenv').load();
require('app-module-path').addPath(__dirname);
require('app-module-path').addPath('../src');
require('isomorphic-fetch');
Expand Down
1 change: 0 additions & 1 deletion bin/server.prod.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require('dotenv').load();
require('app-module-path').addPath(__dirname);
require('app-module-path').addPath('../dist');
require('isomorphic-fetch');
Expand Down
13 changes: 13 additions & 0 deletions bin/server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

if [ "$NODE_ENV" == "production" ]; then
node bin/server.prod.js
else
# must add --host 0.0.0.0 to be accessible from outside docker container
# see https://github.com/webpack/webpack-dev-server/issues/183#issuecomment-128436301
node --expose-gc \
./node_modules/webpack-dev-server/bin/webpack-dev-server.js \
--config ./webpack/dev.config.js \
--host 0.0.0.0 --progress &
node --expose-gc ./bin/server.js
fi
23 changes: 23 additions & 0 deletions docker-compose.production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: '3'
services:
frontend:
build:
context: .
args:
- node_env=production
- facebook_app_id=1557596491207315
- assets_url=//azurequrancom-a79c.kxcdn.com/
- fonts_url=//azurequrancom-a79c.kxcdn.com/
- public_api_url=//azure.quran.com
- one_quran_url=//one.quran.com
- sentry_key_client=https://[email protected]/271092
image: frontend-prod:latest
environment:
# - INTERNAL_API_URL=http://api.quran.com
- INTERNAL_API_URL=http://api:3000
- SENTRY_KEY_SERVER=
- PORT=8000
- NODE_PATH=./dist
ports:
- "8000:8000"

29 changes: 29 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: '3'
services:
frontend:
build:
context: .
args:
- node_env=development
- facebook_app_id=appid
- assets_url=/public/
- fonts_url=//localhost:3100/
- public_api_url=http://api.quran.com
- one_quran_url=https://one.quran.com
- sentry_key_client=https://app.getsentry.com
ports:
- "8080:8080"
- "8000:8000"
# volumes:
# - ./src:/quran/src
environment:
- INTERNAL_API_URL=http://api.quran.com
# - INTERNAL_API_URL=http://api:3000
# - SEGMENTS_KEY=
# - SENTRY_KEY_CLIENT=https://app.getsentry.com
# - SENTRY_KEY_SERVER=https://app.getsentry.com
- PORT=8000
fonts:
image: quran/fonts:latest
ports:
- "3100:3000"
17 changes: 17 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Docker instructions

## Development

To build for development:

docker-compose up

Then navigate to `http://localhost:8000`

## Production

To build for production:

docker-compose -f docker-compose.production.yml build

Then tag and push the resulting `frontend-prod:latest` image to a docker registry.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@
"css-loader": "0.26.1",
"cssnano": "3.10.0",
"debug": "2.2.0",
"dotenv": "2.0.0",
"errorhandler": "1.4.3",
"express": "4.14.0",
"express-state": "1.4.0",
Expand Down
8 changes: 5 additions & 3 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ const locales = {
const config = {
host: process.env.HOST || 'localhost',
port: process.env.PORT,
api: process.env.API_URL,
apiInternal: process.env.INTERNAL_API_URL,
apiPublic: process.env.PUBLIC_API_URL,
oneQuran: process.env.ONE_QURAN_URL,
sentryClient: process.env.SENTRY_KEY_CLIENT,
sentryServer: process.env.SENTRY_KEY_SERVER,
facebookAppId: process.env.FACEBOOK_APP_ID,
assetsURL: process.env.ASSETS_URL,
fontsURL: process.env.FONTS_URL,
locales,
defaultLocale: 'en',
Expand Down Expand Up @@ -303,12 +305,12 @@ const config = {
},
{
rel: 'preconnect',
href: 'https://quran-1f14.kxcdn.com',
href: process.env.ASSETS_URL,
crossOrigin: ''
},
{
rel: 'preconnect',
href: 'https://assets-1f14.kxcdn.com',
href: process.env.FONTS_URL,
crossOrigin: ''
},
...Object.keys(locales).map(key => ({
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/ApiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ const formatUrl = (path) => {
return config.oneQuran + adjustedPath.replace('/onequran', '');
}

return `${config.api}${adjustedPath}`;
return `${config.apiInternal}${adjustedPath}`;
}

if (adjustedPath.startsWith('/onequran')) {
return adjustedPath;
}

return `/api${adjustedPath}`;
return `${config.apiPublic}${adjustedPath}`;
};

class ApiClient {
Expand Down
14 changes: 8 additions & 6 deletions src/helpers/buildFontFaces.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/* eslint-disable max-len */

import config from '../config';

export const fontFaceStyle = fontClassName => (
`@font-face {font-family: '${fontClassName}';
src: url('//quran-1f14.kxcdn.com/fonts/compressed/eot/${fontClassName}.eot?#iefix') format('embedded-opentype'),
url('//quran-1f14.kxcdn.com/fonts/ttf/${fontClassName}.ttf') format('truetype'),
url('//quran-1f14.kxcdn.com/fonts/woff/${fontClassName}.woff?-snx2rh') format('woff');}
src: url('${config.fontsURL}fonts/compressed/eot/${fontClassName}.eot?#iefix') format('embedded-opentype'),
url('${config.fontsURL}fonts/ttf/${fontClassName}.ttf') format('truetype'),
url('${config.fontsURL}fonts/woff/${fontClassName}.woff?-snx2rh') format('woff');}
.${fontClassName} {font-family: '${fontClassName}';}
.${fontClassName} {display: none;}`
);
Expand All @@ -25,9 +27,9 @@ export function createFontFacesArray(verses) {
fontFaces.push(font);
fontFacesArray.push(
`@font-face {font-family: '${font}';
src: url('//quran-1f14.kxcdn.com/fonts/compressed/eot/${font}.eot?#iefix') format('embedded-opentype'),
url('//quran-1f14.kxcdn.com/fonts/ttf/${font}.ttf') format('truetype'),
url('//quran-1f14.kxcdn.com/fonts/woff/${font}.woff?-snx2rh') format('woff');}
src: url('${config.fontsURL}fonts/compressed/eot/${font}.eot?#iefix') format('embedded-opentype'),
url('${config.fontsURL}fonts/ttf/${font}.ttf') format('truetype'),
url('${config.fontsURL}fonts/woff/${font}.woff?-snx2rh') format('woff');}
.${font} {font-family: '${font}';}`
);
}
Expand Down
Loading