Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New docker setup for emission-server #618

Merged
merged 9 commits into from
Dec 21, 2018
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# python 3
FROM continuumio/miniconda3

MAINTAINER Attawit Kittikrairit
shankari marked this conversation as resolved.
Show resolved Hide resolved

# set working directory
WORKDIR /usr/src/app

# clone from repo
RUN git clone https://github.com/e-mission/e-mission-server.git .
RUN git clone https://github.com/alvinalexander/e-mission-server.git .
shankari marked this conversation as resolved.
Show resolved Hide resolved

# 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 @@ -24,14 +22,19 @@ RUN bower update --allow-root
WORKDIR /usr/src/app

# install nano for editing
RUN apt-get -y install nano vim
RUN apt-get -y install nano
shankari marked this conversation as resolved.
Show resolved Hide resolved

# 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
32 changes: 32 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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:
- "27017:27017"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is only if you want to access the DB from the host. Add a note to that effect?

#If you want to persist the data in the DB you need to mount a volume.
#Instructions can be found here: https://docs.docker.com/compose/compose-file/#volume-configuration-reference
shankari marked this conversation as resolved.
Show resolved Hide resolved
networks:
- emission
networks:
emission:
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}
shankari marked this conversation as resolved.
Show resolved Hide resolved
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