got docker to work

This commit is contained in:
David Baldwynn 2016-11-30 16:29:44 -08:00
parent cc15911379
commit d08749a6b4
9 changed files with 61 additions and 85 deletions

1
.gitignore vendored
View file

@ -3,6 +3,7 @@ docs/Oscar_Credentials.md
scripts/test_oscarhost.js
scripts/oscarhost/private/
coverage/
e2e_coverage/
uploads/
app/e2e_tests/screeshots/*
tmp

View file

@ -7,68 +7,65 @@
# Compose:
# docker-compose up -d
FROM ubuntu:latest
FROM ubuntu:latest
MAINTAINER David Baldwynn <team@tellform.com>
WORKDIR ~/Documents/tellform
# 80 = HTTP, 443 = HTTPS, 3000 = TellForm server, 35729 =livereload, 8080 = node-inspector, 6379 = redis, 27017 = mongo
EXPOSE 80 443 3000 35729 8080
# Set development environment as default
ENV NODE_ENV development
# Install Utilities
RUN apt-get update -q
RUN apt-get install -yqq python wget aptitude htop vim git traceroute dnsutils curl ssh sudo tree tcpdump nano psmisc gcc make build-essential libfreetype6 libfontconfig libkrb5-dev
RUN apt-get update -q \
&& apt-get install -yqq \
curl \
git \
gcc \
make \
build-essential \
libkrb5-dev \
python \
sudo \
apt-utils \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
ENV python /usr/bin/python
# Install gem sass for grunt-contrib-sass
RUN apt-get install -y ruby
RUN gem install sass
# Install NodeJS
RUN curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
RUN sudo apt-get install -yq nodejs
# Install nodejs
RUN curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
RUN sudo apt-get install -yq nodejs \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Install MEAN.JS Prerequisites
RUN npm install --quiet -g grunt-cli gulp bower mocha karma-cli pm2
RUN npm install --quiet -g grunt bower mocha karma-cli pm2 && npm cache clean
RUN mkdir /opt/mean.js
RUN mkdir -p /opt/mean.js/public/lib
WORKDIR /opt/mean.js
RUN mkdir -p /opt/tellform/public/lib
WORKDIR /opt/tellform
# Copies the local package.json file to the container
# and utilities docker container cache to not needing to rebuild
# and install node_modules/ everytime we build the docker, but only
# when the local package.json file changes.
# Install npm packages
ADD package.json /opt/mean.js/package.json
RUN npm install --quiet
# Add npm package.json
COPY package.json /opt/tellform/package.json
#RUN npm install --quiet && npm cache clean
RUN npm install --production
RUN mv ./node_modules ./node_modules.tmp && mv ./node_modules.tmp ./node_modules && npm install
# Install bower packages
ADD bower.json /opt/mean.js/bower.json
ADD .bowerrc /opt/mean.js/.bowerrc
RUN bower install --quiet --allow-root --config.interactive=false
# Add bower.json
COPY bower.json /opt/tellform/bower.json
COPY .bowerrc /opt/tellform/.bowerrc
#RUN bower install --quiet --allow-root --config.interactive=false
# Share local directory on the docker container
ADD . /opt/mean.js
COPY ./app /opt/tellform/app
COPY ./public /opt/tellform/public
COPY ./config /opt/tellform/config
COPY ./gruntfile.js /opt/tellform/gruntfile.js
COPY ./server.js /opt/tellform/server.js
COPY ./.env /opt/tellform/.env
# Machine cleanup
RUN npm cache clean
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Set development environment as default
ENV NODE_ENV development
# Ports generic
EXPOSE 80:80
EXPOSE 443:443
# Port 3000 for MEAN.JS server
EXPOSE 3000:3000
# Port 5858 for node debug
EXPOSE 5858:5858
# Port 35729 for livereload
EXPOSE 35729:35729
# Run MEAN.JS server
CMD ["npm", "start"]
# Run TellForm server
CMD npm start

View file

@ -97,6 +97,18 @@ Set ```NODE_ENV=production``` in .env file
Your application should run on port 3000 or the port you specified in your .env file, so in your browser just go to [http://localhost:3000](http://localhost:3000)
##Deploying with Docker
To deploy with docker, first install docker [https://docs.docker.com/engine/installation/](here).
Then run these commands
```
$ docker build -t tellform .
$ docker run -p 27017:27017 -d --name some-mongo mongo
$ docker run -p 6379:6379 -d --name some-redis redis
$ docker run --rm -p 3000:3000 --link some-redis:redis-db --link some-mongo:db tellform
```
## Testing Your Application
You can run the full test suite included with MEAN.JS with the test task:

4
config/env/all.js vendored
View file

@ -8,13 +8,13 @@ module.exports = {
keywords: process.env.APP_KEYWORDS || 'typeform, pdfs, forms, opensource, formbuilder, google forms, nodejs'
},
db: {
uri: 'mongodb://'+(process.env.DB_HOST || 'localhost')+'/mean',
uri: 'mongodb://'+ (process.env.DB_PORT_27017_TCP_ADDR || process.env.DB_HOST || 'localhost')+'/mean',
options: {
user: '',
pass: ''
}
},
port: process.env.PORT || 3000,
socketPort: process.env.SOCKET_PORT || 20523,

View file

@ -3,7 +3,7 @@
module.exports = {
baseUrl: process.env.BASE_URL || 'http://localhost:5000',
db: {
uri: 'mongodb://'+(process.env.DB_HOST || 'localhost')+'/mean',
uri: 'mongodb://'+( process.env.DB_PORT_27017_TCP_ADDR || process.env.DB_HOST || 'localhost') +'/mean',
options: {
user: '',
pass: ''

View file

@ -12,7 +12,7 @@ module.exports = function (app, db) {
var io = socketio(config.socketPort, { transports: ['websocket', 'polling'] });
var redis = require('socket.io-redis');
io.adapter(redis(process.env.REDIS_URL || { host: '127.0.0.1', port: 6379 }));
io.adapter(redis( process.env.REDIS_URL || { host: process.env.REDIS_DB_PORT_6379_TCP_ADDR || '127.0.0.1' , port: process.env.REDIS_DB_PORT_6379_TCP_PORT || 6379 }));
// Add an event listener to the 'connection' event
io.on('connection', function (socket) {

View file

@ -1,9 +0,0 @@
version: '2'
services:
web:
environment:
- MAILER_SERVICE_PROVIDER=Gmail
- MAILER_EMAIL_ID=test@example.com
- MAILER_PASSWORD=password
- HOST=http://localhost:3000

View file

@ -1,24 +0,0 @@
web:
restart: always
build: .
container_name: tellform
command: npm start
links:
- db
ports:
- "3000:3000"
- "5858:5858"
- "35729:35729"
environment:
- NODE_ENV=development
volumes:
- ./:/opt/mean.js
- /opt/mean.js/node_modules
- /opt/mean.js/public
- /opt/mean.js/uploads
db:
image: mongo:3.2
container_name: db_1
restart: always
ports:
- "27017:27017"

View file

@ -46,7 +46,6 @@ exports = module.exports = app;
// Logging initialization
console.log('--');
console.log(chalk.green(config.app.title + ' application started'));
console.log(chalk.green('Environment:\t\t\t' + process.env.NODE_ENV));
console.log(chalk.green('Port:\t\t\t\t' + config.port));
console.log(chalk.green('Database:\t\t\t' + config.db.uri));