Skip to content

Commit

Permalink
Docker implementation and documentation (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
LuBuss authored Feb 25, 2019
1 parent 739efcf commit f9dff74
Show file tree
Hide file tree
Showing 11 changed files with 647 additions and 24 deletions.
48 changes: 48 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
FROM node:8
LABEL maintainer "Nitin Goyal <[email protected]>, Luke Busstra <[email protected]>"

ENV NGINX_CODENAME stretch
ENV API_PORT 3001

# install requirements
RUN echo "deb http://nginx.org/packages/debian/ ${NGINX_CODENAME} nginx" >> /etc/apt/sources.list \
&& apt-get update && apt-get install --no-install-recommends --no-install-suggests -y --assume-yes --allow-unauthenticated \
gettext-base\
bash \
zip \
unzip \
wget \
curl \
nano \
ca-certificates \
nginx \
nginx-module-image-filter

# install PM2
RUN npm install pm2 -g

RUN mkdir -p /var/www \
&& cd /var/www \
&& mkdir -p cezerin2

# download project
ADD . /var/www/cezerin2

# Nginx config
COPY nginx/nginx.conf /etc/nginx/
COPY nginx/default.conf.template /etc/nginx/conf.d/

# script to run Nginx and PM2
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x "/usr/local/bin/docker-entrypoint.sh"

# build project
RUN cd /var/www/cezerin2 \
&& npm i

WORKDIR /var/www/cezerin2

EXPOSE 80

# start PM2
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
20 changes: 8 additions & 12 deletions config/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,19 @@ const dbUrl =

module.exports = {
// used by Store (server side)
apiBaseUrl: `http://localhost:3001/api/v1`,

// used by Store (server and client side)
ajaxBaseUrl: `http://localhost:3001/ajax`,
apiBaseUrl: process.env.API_BASE_URL || `http://localhost:3001/api/v1`,

// Access-Control-Allow-Origin
storeBaseUrl: `http://localhost:3000`,
storeBaseUrl: process.env.STORE_URL || `http://localhost:3000`,

// used by API
adminBaseURL: process.env.ADMIN_BASE_URL || 'http://localhost:3003',
adminBaseURL: process.env.ADMIN_BASE_URL || 'http://localhost:3002',
adminLoginPath: process.env.ADMIN_LOGIN_PATH || '/admin/login',

// used by API to service assets
assetsBaseURL: process.env.ASSETS_BASE_URL || '',
assetsBaseURL: process.env.ASSETS_BASE_URL || 'http://localhost:3001',

apiListenPort: 3001,
storeListenPort: process.env.STORE_PORT || 3000,
apiListenPort: process.env.API_PORT || 3001,

// used by API
mongodbServerUrl: dbUrl,
Expand All @@ -44,10 +40,10 @@ module.exports = {
},

// key to sign tokens
jwtSecretKey: '-',
jwtSecretKey: process.env.JWT_SECRET_KEY || '-',

// key to sign store cookies
cookieSecretKey: '-',
cookieSecretKey: process.env.COOKIE_SECRET_KEY || '-',

// path to uploads
categoriesUploadPath: 'public/content/images/categories',
Expand All @@ -62,7 +58,7 @@ module.exports = {
themeAssetsUploadUrl: '/assets/images',

// store UI language
language: 'en',
language: process.env.LANGUAGE || 'en',

// used by API
orderStartNumber: 1000,
Expand Down
6 changes: 0 additions & 6 deletions config/store.js

This file was deleted.

6 changes: 0 additions & 6 deletions config/store.production.js

This file was deleted.

7 changes: 7 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
set -e

envsubst '${API_PORT}' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf

nginx
exec pm2 start process.json --no-daemon
81 changes: 81 additions & 0 deletions docs/single-instance/cezerin2-docker-compse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Single Instance cezerin2 dockerfile and docker-entrypoint.sh

* [dockerfile](#dockerfile)
* [docker-entrypoint.sh](#docker-entrypoint.sh)

## dockerfile
```docker-compose
version: '3'
services:
api:
build:
context: ./cezerin2
env_file: .env
environment:
- DB_HOST=db
- STORE_URL=http://www.exampe.com
- API_BASE_URL=http://api.example.com/api/v1
- AJAX_BASE_URL=http://api.example.com/ajax
- ASSETS_BASE_URL=http://asset.example.com
- ADMIN_BASE_URL=http://admin.example.com
ports:
- 3001:80
volumes:
- ./cezerin2/public/content:/var/www/cezerin2/public/content
depends_on:
- db
restart: always
store:
build:
context: ./cezerin2-store
environment:
- API_BASE_URL=http://api.example.com/api/v1
- AJAX_BASE_URL=http://api.example.com/ajax
ports:
- 3000:80
depends_on:
- db
- api
restart: always
admin:
build:
context: ./cezerin2-admin
environment:
- API_BASE_URL=http://api.example.com/api/v1
- API_WEB_SOCKET_URL=ws://api.example.com
ports:
- 3002:80
depends_on:
- db
- api
restart: always
proxy:
build:
context: ./proxy
environment:
- DOMAIN=example.com
- STORE_HOST=store
- ADMIN_HOST=admin
- API_HOST=api
ports:
- 80:80
depends_on:
- db
- api
- admin
restart: always
db:
image: mongo:3.4
ports:
- 27017:27017
volumes:
- ./db:/data/db
restart: always
```

50 changes: 50 additions & 0 deletions docs/single-instance/cezerin2-proxy-dockerfile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Single Instance cezerin2-proxy dockerfile and docker-entrypoint.sh

* [dockerfile](#dockerfile)
* [docker-entrypoint.sh](#docker-entrypoint.sh)

## dockerfile
```dockerfile
FROM node:8
LABEL maintainer "Luke Busstra <[email protected]>"

ENV NGINX_CODENAME stretch


# install requirements and NGINX
RUN echo "deb http://nginx.org/packages/debian/ ${NGINX_CODENAME} nginx" >> /etc/apt/sources.list \
&& apt-get update && apt-get install --no-install-recommends --no-install-suggests -y --force-yes \
gettext-base\
bash \
zip \
unzip \
wget \
curl \
nano \
ca-certificates \
nginx \
nginx-module-image-filter

# Nginx config
COPY nginx/nginx.conf /etc/nginx/
COPY nginx/default.conf.template /etc/nginx/conf.d/

# script to run Nginx and PM2
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x "/usr/local/bin/docker-entrypoint.sh"

EXPOSE 80

# start env build and Nginx
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
```

## docker-entrypoint.sh
```shell
#!/bin/sh
set -e

envsubst '${DOMAIN} ${STORE_HOST} ${ADMIN_HOST} ${API_HOST} ${ASSET_HOST}' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf

nginx -g "daemon off;"
```
Loading

0 comments on commit f9dff74

Please sign in to comment.