Skip to content

Commit

Permalink
New docker setup for emission-server (#618)
Browse files Browse the repository at this point in the history
* Resolve conflict in start_script.sh

* Resolve conflict in Dockerfile

* Add composefile

* Update docker README.md and Dockerfile

* Update README

* Moved everything into Dockerfile and deleted Dockerfile-base

* Add Maintainer

* Mount volume to store db data by default

* Pull from emssion-server repo and install Vim
  • Loading branch information
alvinalexander authored and shankari committed Dec 21, 2018
1 parent 004a5d4 commit e76681b
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 52 deletions.
16 changes: 10 additions & 6 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# python 3
FROM continuumio/miniconda3

MAINTAINER Attawit Kittikrairit

MAINTAINER K. Shankari ([email protected])
# set working directory
WORKDIR /usr/src/app

# clone from repo
RUN git clone https://github.com/e-mission/e-mission-server.git .

# setup python environment
# setup python environment.
RUN conda env update --name emission --file setup/environment36.yml
RUN /bin/bash -c "source activate emission; pip install six --upgrade"

Expand All @@ -23,15 +22,20 @@ WORKDIR /usr/src/app/webapp
RUN bower update --allow-root
WORKDIR /usr/src/app

# install nano for editing
# install nano and vim for editing
RUN apt-get -y install nano vim

# cleanup
RUN apt-get -y remove --purge build-essential
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# start the server
ADD docker/start_script.sh /usr/src/app/start_script.sh
#declare environment variables
ENV DB_HOST=''
ENV WEB_SERVER_HOST=''

#add start script.
WORKDIR /usr/src/app
ADD start_script.sh /usr/src/app/start_script.sh
RUN chmod u+x /usr/src/app/start_script.sh

EXPOSE 8080
Expand Down
63 changes: 18 additions & 45 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -1,67 +1,40 @@
# Docker Instructions

## Docker usage instructions
# Docker usage instructions
This project is now published on dockerhub!
https://hub.docker.com/r/emission/e-mission-server/
and https://hub.docker.com/r/emission/e-mission-server-base/

Instructions on re-building the image are at [in the build instructions](#Docker_Build_Instructions)
Instructions on re-building the image are [in the build instructions](#Docker_Build_Instructions)

1. Create docker network
1. Initialize Swarm
```
docker swarm init
```
For more details on how to do manage a swarm please see the official documentation: https://docs.docker.com/get-started/part4/

We will be creating network name `e-mission` which will allows any docker container in the network refer to each other by its `name` instead of IP Address which can be changed over time.

```
docker network create e-mission --driver=bridge
```

2. Run MongoDB

We will be using Official MongoDB Docker image, so no need to build one.
2. Configure the compose file.
* Update the port mappings and environment variables if necessary.
For more details on how to configure compose files please see the official documentation: https://docs.docker.com/compose/compose-file/#service-configuration-reference

3. Deploy to swarm
```
docker stack deploy -c docker-compose.yml emission
```
docker run -d \
--name=e-mission-mongo-1 \
--net="e-mission" \
--restart=always \
--mount source=e-mission-mongo-1_data,target=/data/db \
--mount source=e-mission-mongo-1_config,target=/data/configdb \
mongo:latest \
--bind_ip_all
```

FOR ADVANCED USER: If you would like to access to MongoDB directly for debugging purpose, you can add the line

```
-p 27017:27017 \
```

and access it like MongoDB is running on your host machine.

3. Run the server

```
docker run -d \
-p 8080:8080 \
--name=e-mission-server-1 \
--net="e-mission" \
--restart=always \
--mount type=bind,source="$(pwd)"/conf/storage/db.conf.docker.sample,target=/usr/src/app/conf/storage/db.conf,readonly \
--mount type=bind,source="$(pwd)"/conf/net/api/webserver.conf.docker.sample,target=/usr/src/app/conf/net/api/webserver.conf,readonly \
emission/e-mission-server:latest
```
There are many ways you can manage your deployment. Again, please see the official documentation for more details: https://docs.docker.com/get-started/part4/

1. Test your connection to the server
4. Test your connection to the server
* Using a web browser, go to [http://localhost:8080](http://localhost:8080)
* Using safari in the iOS emulator, go to [http://localhost:8080](http://localhost:8080)
* Using chrome in the android emulator, go to [http://10.0.2.2:8080](http://10.0.2.2:8080)
This is the [special IP for the current host in the android emulator](https://developer.android.com/tools/devices/emulator.html#networkaddresses)

### Docker Build Instructions
#### emission-server image

1. Build local docker image

```
docker build -f docker/Dockerfile -t emission/e-mission-server:latest .
docker build -f docker/Dockerfile -t emission/e-mission-server:latest ./docker
```

1. Tag the release (make sure you are in the owners group for emission, or
Expand Down
42 changes: 42 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
version: "3"
services:
web-server:
image: emission-server
depends_on:
- db
environment:
- DB_HOST=db
- WEB_SERVER_HOST=0.0.0.0
deploy:
replicas: 1
restart_policy:
condition: on-failure
ports:
#This is a default port mapping. In production you might want to use 80:8080,
- "8080:8080"
networks:
- emission
db:
image: mongo:latest
deploy:
replicas: 1
restart_policy:
condition: on-failure
ports:
#This port binding allows you to access the database server outside the host machine. Remove this is you don't need this
#functionality
- "27017:27017"

#Volumes is the preferred way to persist data generated by a container. In this case we use a volume to persist the contents
#of the data base. Learn more about how to use volumes here: https://docs.docker.com/storage/volumes/
# And learn how to configure volumes in your compose file here: https://docs.docker.com/compose/compose-file/#volume-configuration-reference
volumes:
- mongo-data:/data/db
networks:
- emission

networks:
emission:

volumes:
mongo-data:
24 changes: 23 additions & 1 deletion docker/start_script.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
#!bin/bash
#!/usr/bin/env bash
#Configure web server

#set database URL using environment variable
echo ${DB_HOST}
if [ -z ${DB_HOST} ] ; then
local_host=`hostname -i`
sed "s_localhost_${local_host}_" conf/storage/db.conf.sample > conf/storage/db.conf
else
sed "s_localhost_${DB_HOST}_" conf/storage/db.conf.sample > conf/storage/db.conf
fi
cat conf/storage/db.conf

#set Web Server host using environment variable
echo ${WEB_SERVER_HOST}
if [ -z ${WEB_SERVER_HOST}} ] ; then
local_host=`hostname -i`
sed "s_localhost_${local_host}_" conf/net/api/webserver.conf.sample > conf/net/api/webserver.conf
else
sed "s_localhost_${WEB_SERVER_HOST}_" conf/net/api/webserver.conf.sample > conf/net/api/webserver.conf
fi
cat conf/net/api/webserver.conf

#TODO: start cron jobs
# change python environment
source activate emission

Expand Down

0 comments on commit e76681b

Please sign in to comment.