Skip to content

Commit

Permalink
feat: add docker / docker-compose (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
evereq committed Jun 26, 2019
1 parent a816d6f commit a25492c
Show file tree
Hide file tree
Showing 27 changed files with 311 additions and 142 deletions.
43 changes: 43 additions & 0 deletions .deploy/api/Dockerfile
@@ -0,0 +1,43 @@
# API

FROM node:alpine

RUN apk update

RUN npm i -g npm

RUN apk add libexecinfo libexecinfo-dev

RUN apk --no-cache add --virtual builds-deps build-base \
snappy g++ snappy-dev gcc libgcc libstdc++ linux-headers autoconf automake make nasm python git && \
npm install --quiet node-gyp -g

RUN npm config set python /usr/bin/python

RUN npm install yarn -g

RUN npm install pm2 -g --unsafe-perm

# Make our app folder (empty for now)
RUN mkdir -p /usr/src/app

# Provides cached layer for node_modules and bower_components
ADD package.json /tmp/package.json
ADD apps/api/package.json /tmp/apps/api/package.json
# COPY .snyk /tmp/.snyk
COPY yarn.lock /tmp/yarn.lock
RUN cd /tmp/ && yarn install
RUN cp -a /tmp/node_modules /usr/src/app/
RUN cd /usr/src/app

WORKDIR /usr/src/app

# Bundle app source
ADD . /usr/src/app

EXPOSE 3000

ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.5.0/wait /wait
RUN chmod +x /wait

CMD /wait && yarn run api:seedData && yarn run start:api:prod
Empty file added .deploy/nginx/error.log
Empty file.
23 changes: 23 additions & 0 deletions .deploy/nginx/nginx.conf
@@ -0,0 +1,23 @@
events {
worker_connections 1024;
}

http {

error_log /etc/nginx/error.log warn;
client_max_body_size 20m;

upstream webapp {
server webapp:4200;
}

server {
server_name gauzy.dev;

location / {
proxy_pass http://webapp;
}

listen 8080;
}
}
42 changes: 42 additions & 0 deletions .deploy/webapp/Dockerfile
@@ -0,0 +1,42 @@
# Webapp

FROM node:alpine

RUN apk update

RUN npm i -g npm

RUN apk add libexecinfo libexecinfo-dev

RUN apk --no-cache add --virtual builds-deps build-base \
snappy g++ snappy-dev gcc libgcc libstdc++ linux-headers autoconf automake make nasm python git && \
npm install --quiet node-gyp -g

RUN npm config set python /usr/bin/python

RUN npm install yarn -g

RUN npm install pm2 -g --unsafe-perm

# Make our app folder (empty for now)
RUN mkdir -p /usr/src/app

# Provides cached layer for node_modules and bower_components
ADD package.json /tmp/package.json
# COPY .snyk /tmp/.snyk
COPY yarn.lock /tmp/yarn.lock
RUN cd /tmp/ && yarn install
RUN cp -a /tmp/node_modules /usr/src/app/
RUN cd /usr/src/app

WORKDIR /usr/src/app

# Bundle app source
ADD . /usr/src/app

EXPOSE 4200

ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.5.0/wait /wait
RUN chmod +x /wait

CMD /wait && yarn run start:gauzy:prod
28 changes: 28 additions & 0 deletions .dockerignore
@@ -0,0 +1,28 @@
dist
tmp
.github
.npmrc
.travis.yml
greenkeeper.json
docker-compose.yml
*.md
.deploy
.git/
.gitignore
node_modules

# IDEs and editors
.idea
.vscode
.project
.classpath
*.launch
.settings/

# e2e
e2e/*.js
e2e/*.map

#System Files
.DS_Store
Thumbs.db
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -7,7 +7,7 @@

# dependencies
/node_modules

/apps/api/node_modules
# IDEs and editors
/.idea
.project
Expand Down
3 changes: 2 additions & 1 deletion angular.json
Expand Up @@ -93,7 +93,8 @@
},
"configurations": {
"production": {
"browserTarget": "gauzy:build:production"
"browserTarget": "gauzy:build:production",
"proxyConfig": "apps/gauzy/proxy.prod.conf.json"
}
}
},
Expand Down
15 changes: 0 additions & 15 deletions apps/api/node_modules/.bin/nodemon

This file was deleted.

7 changes: 0 additions & 7 deletions apps/api/node_modules/.bin/nodemon.cmd

This file was deleted.

18 changes: 0 additions & 18 deletions apps/api/node_modules/.bin/nodemon.ps1

This file was deleted.

15 changes: 0 additions & 15 deletions apps/api/node_modules/.bin/typeorm

This file was deleted.

7 changes: 0 additions & 7 deletions apps/api/node_modules/.bin/typeorm.cmd

This file was deleted.

18 changes: 0 additions & 18 deletions apps/api/node_modules/.bin/typeorm.ps1

This file was deleted.

15 changes: 0 additions & 15 deletions apps/api/node_modules/.bin/web-push

This file was deleted.

7 changes: 0 additions & 7 deletions apps/api/node_modules/.bin/web-push.cmd

This file was deleted.

18 changes: 0 additions & 18 deletions apps/api/node_modules/.bin/web-push.ps1

This file was deleted.

19 changes: 10 additions & 9 deletions apps/api/package.json
Expand Up @@ -4,16 +4,17 @@
"description": "Gauzy API",
"license": "AGPL-3.0",
"scripts": {
"typeorm": "ts-node -r tsconfig-paths/register --project apps/api/tsconfig.app.json node_modules/.bin/typeorm",
"typeorm:sync": "typeorm schema:sync",
"typeorm:seeds": "typeorm migration:run",
"typeorm:flush": "typeorm migration:revert",
"typeorm:create": "typeorm migration:create",
"typeorm": "yarn ts-node -r tsconfig-paths/register --project apps/api/tsconfig.app.json node_modules/.bin/typeorm",
"typeorm:sync": "yarn typeorm schema:sync",
"typeorm:seeds": "yarn typeorm migration:run",
"typeorm:flush": "yarn typeorm migration:revert",
"typeorm:create": "yarn typeorm migration:create",
"typeorm:preserve": "yarn typeorm:sync -- -f=ormconfig && yarn typeorm:seeds -- -f=ormconfig",
"start": "ts-node -r tsconfig-paths/register --project apps/api/tsconfig.app.json src/main.ts",
"build": "ng build api",
"build:prod": "ng build api --prod",
"seedData": "ts-node -r tsconfig-paths/register --project tsconfig.app.json src/app/core/seeds/index.ts"
"start": "yarn ts-node -r tsconfig-paths/register --project apps/api/tsconfig.app.json src/main.ts",
"build": "yarn ng build api",
"build:prod": "yarn ng build api --prod",
"seedData": "yarn ts-node -r tsconfig-paths/register --project tsconfig.app.json src/app/core/seeds/index.ts",
"seedData:prod": "yarn ts-node -r tsconfig-paths/register --project tsconfig.app.json src/app/core/seeds/index.ts -c=production"
},
"dependencies": {
"@nestjs/common": "^6.3.1",
Expand Down
12 changes: 10 additions & 2 deletions apps/api/src/app/config/config.service.ts
Expand Up @@ -18,7 +18,12 @@ export class ConfigService {
for (const [key, value] of Object.entries(environment.env)) {
process.env[key] = value;
}
console.log('is prod? ', environment.production);

this.logger.log('Is Production: ' + environment.production);

if (packageJson) {
this.logger.log('Package.json version: ' + packageJson.version)
}
}

get(key: keyof IEnvironment): IEnvironment[keyof IEnvironment] {
Expand All @@ -27,8 +32,11 @@ export class ConfigService {

getVersion(): string {
if (!process.env.APP_VERSION) {
process.env.APP_VERSION = packageJson.version;
if (packageJson && packageJson.version) {
process.env.APP_VERSION = packageJson.version;
}
}

return process.env.APP_VERSION;
}

Expand Down
28 changes: 26 additions & 2 deletions apps/api/src/environments/environment.prod.ts
@@ -1,3 +1,27 @@
export const environment = {
production: true
import { IEnvironment } from './ienvironment';

export const environment : IEnvironment = {
production: true,
envName: 'prod',
env: {
LOG_LEVEL: 'debug'
},
USER_PASSWORD_BCRYPT_SALT_ROUNDS: 12,
JWT_SECRET: 'secretKey',
database: {
type: 'postgres',
host: 'db',
port: 5432,
database: 'postgres',
username: 'postgres',
password: 'root',
keepConnectionAlive: true,
logging: true,
synchronize: true,
uuidExtension: 'pgcrypto',
},
defaultAdmin: {
email: 'admin@ever.co',
password: "admin"
}
};
6 changes: 6 additions & 0 deletions apps/gauzy/proxy.prod.conf.json
@@ -0,0 +1,6 @@
{
"/api": {
"target": "http://api:3000",
"secure": false
}
}

0 comments on commit a25492c

Please sign in to comment.