Skip to content

Commit

Permalink
Dockerize GenCyberCoin, include redis but comment it out if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalyford committed May 12, 2019
1 parent cf12d63 commit 0d31340
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 3 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Expand Up @@ -2,9 +2,6 @@ __pycache__/
.env
.dockerignore
.elasticbeanstalk/
Dockerfile
convox.yml
docker-compose.yml
# Elastic Beanstalk Files
Expand Down
11 changes: 11 additions & 0 deletions README.md
Expand Up @@ -17,6 +17,17 @@ A 10-minute summary video on GenCyberCoin platform is available here:

[![Watch the video](instructions/img-readme/homepage.png)](https://arcadia.hosted.panopto.com/Panopto/Pages/Embed.aspx?id=4a2d137e-e80f-4dd3-bc5e-aa1e00f7b4b7&v=1)

# Docker instructions

GenCyberCoin is dockerized (runs on nginx + gunicorn + postgresql + python3.7 + Django) and to run GenCyberCoin through Docker, you would need to install:
- Docker,
- Docker Compose,
- and if you have Mac or Windows, you would need to install Docker Machine.

After installing the above-mentioned software, open the Docker Terminal and navigate to this project's main directory (a place where `build.sh` is located). Then, run `build.sh` from the Docker Terminal (by typing `./build.sh`) and it will build and run the containers. Upon successful execution, the GenCyberCoin will be running on your IP address, port 80. You can navigate to it in your browser and go straight to [creating administrators](#creating-administrators) section.

To stop the containers, type `docker-compose down` from the same place (where `build.sh` is located). All your data will be saved even after stopping and starting the containers back up again.

# Local setup instructions

The instructions for setting up a local version of the GenCyberCoin project can be found [here](instructions/Local_setup.MD).
Expand Down
32 changes: 32 additions & 0 deletions build.sh
@@ -0,0 +1,32 @@
#!/bin/bash

# bring the stuff down just in case if it has not been down yet
docker-compose down

echo Building and running the containers...
docker-compose up -d --build

echo Waiting for 15 sec for postgres database to start up...
docker-compose exec postgres sleep 15

echo Creating postgres user...
docker-compose exec postgres psql -U postgres -c "CREATE USER coin_admin PASSWORD 'go-figure-me-cow'"
echo If you see an ERROR here, no big deal

echo Creating postgres DB...
docker-compose exec postgres psql -U postgres -c "CREATE DATABASE coin_db OWNER coin_admin"
echo If you see an ERROR here, no big deal

echo Making migrations...
docker-compose exec web python manage.py makemigrations --noinput

echo Migrating to the database...
docker-compose exec web python manage.py migrate --noinput

echo Setting up defaults...
docker-compose exec web python manage.py setdefaults

echo Collecting static files like Javascript, CSS, background image, etc...
docker-compose exec web python manage.py collectstatic --noinput

echo Done! The server should be running on your IP address, port 80
9 changes: 9 additions & 0 deletions cryptocoin/Dockerfile
@@ -0,0 +1,9 @@
FROM python:3.7-slim

WORKDIR /code

RUN python -m pip install --upgrade pip

COPY . /code/

RUN python -m pip install -r /code/requirements.txt
11 changes: 11 additions & 0 deletions cryptocoin/cryptocoin/settings.py
Expand Up @@ -84,6 +84,17 @@
'PORT': os.environ['RDS_PORT'],
}
}
elif 'RUN_IN_DOCKER' in os.environ:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'coin_db',
'USER': 'coin_admin',
'PASSWORD': 'go-figure-me-cow',
'HOST': 'postgres',
'PORT': '5432',
}
}
else:
DATABASES = {
'default': {
Expand Down
2 changes: 2 additions & 0 deletions cryptocoin/requirements.txt
Expand Up @@ -5,6 +5,7 @@ Django>=2.1.2
django-import-export
django-storages
et-xmlfile
gunicorn
jdcal
odfpy
openpyxl
Expand All @@ -13,6 +14,7 @@ pip-review
psycopg2-binary
pytz
PyYAML
# redis
reportlab
tablib
unicodecsv
Expand Down
54 changes: 54 additions & 0 deletions docker-compose.yml
@@ -0,0 +1,54 @@
version: '3'

services:
web:
restart: always
build: ./cryptocoin
expose:
- "8000"
links:
- postgres:postgres
# - redis:redis
volumes:
- web-django:/code
- web-static:/code/cryptocoin/static
- web-media:/code/cryptocoin/media
# env_file: .env
environment:
- DEBUG='True'
- RUN_IN_DOCKER='True'
command: /usr/local/bin/gunicorn cryptocoin.wsgi:application -w 2 -b :8000

nginx:
restart: always
build: ./nginx/
ports:
- "80:80"
volumes:
- web-static:/code/cryptocoin/static
- web-media:/code/cryptocoin/media
links:
- web:web

postgres:
restart: always
image: postgres:latest
# ports:
# - "5432:5432"
volumes:
- pgdata:/var/lib/postgresql/data/

# redis:
# restart: always
# image: redis:latest
# ports:
# - "6379:6379"
# volumes:
# - redisdata:/data

volumes:
web-django:
web-static:
web-media:
pgdata:
# redisdata:
5 changes: 5 additions & 0 deletions nginx/Dockerfile
@@ -0,0 +1,5 @@
FROM tutum/nginx

RUN rm /etc/nginx/sites-enabled/default

COPY sites-enabled/ /etc/nginx/sites-enabled
22 changes: 22 additions & 0 deletions nginx/sites-enabled/django_project
@@ -0,0 +1,22 @@
server {

listen 80;
server_name localhost;
charset utf-8;

location /static/ {
alias /code/cryptocoin/static/;
}

location /media/ {
alias /code/cryptocoin/media/;
}

location / {
proxy_pass http://web:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

}

0 comments on commit 0d31340

Please sign in to comment.