Skip to content

Commit

Permalink
Merge pull request #1 from tameeshB/docerize
Browse files Browse the repository at this point in the history
Docerize
  • Loading branch information
tameeshB authored Jun 17, 2020
2 parents 4f1725c + 2620534 commit 7b205e6
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 19 deletions.
12 changes: 6 additions & 6 deletions .env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export MYSQL_DB='evoting'
export MYSQL_User='root'
export MYSQL_Pass='root'
export MYSQL_Host='localhost'
export smtp_sender='[email protected]'
export smtp_pass='password'
MYSQL_DATABASE=evoting_db
MYSQL_PASSWORD=root
MYSQL_ROOT_PASSWORD=root
MYSQL_HOST=db
smtp_sender=your-[email protected]
smtp_pass=password
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM python:3.7
ENV PYTHONUNBUFFERED 1
RUN mkdir /evoting
WORKDIR /evoting
ADD . /evoting/
RUN pip install -r REQUIREMENTS.txt && \
chmod +x init_migrate_db.sh
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@

Polling app with a simple, intuitive UX that also takes care of the complexities like privacy, integrity and security behind the scenes.

## Docker Deployment:
1. `docker-compose --env-file .env build`
2. `docker-compose --env-file .env up -d`
3. `docker-compose exec web bash /evoting/init_migrate_db.sh --load-template-data`


## apt/brew Dependencies
1. Python : >=3.5
2. Chrome : >=68 (for running functional tests)
Expand Down
7 changes: 4 additions & 3 deletions REQUIREMENTS.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
django
pymysql
selenium
django==3.0.2
pymysql==0.9.3
mysqlclient==1.3.13
selenium
26 changes: 26 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: "2.1"
services:
db:
image: mysql:5.7
ports:
- '3306:3306'
env_file:
- .env
restart: on-failure
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
timeout: 20s
retries: 10
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
env_file:
- .env
# volumes:
# - .:/evoting
ports:
- "8000:8000"
restart: on-failure
depends_on:
db:
condition: service_healthy
4 changes: 4 additions & 0 deletions evoting/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import pymysql

# Pre-Docker deploy debug:
# https://stackoverflow.com/a/59591269/2736932
pymysql.version_info = (1, 3, 13, "final", 0)

pymysql.install_as_MySQLdb()
5 changes: 0 additions & 5 deletions evoting/mysql.conf

This file was deleted.

10 changes: 5 additions & 5 deletions evoting/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@
# }
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': os.environ.get('MYSQL_DB'),
'USER': os.environ.get('MYSQL_User'),
'PASSWORD': os.environ.get('MYSQL_Pass'),
'HOST': os.environ.get('MYSQL_Host'),
'ENGINE': 'django.db.backends.mysql',
'NAME': os.environ.get('MYSQL_DATABASE'),
'USER': 'root', # os.environ.get('MYSQL_USER')
'PASSWORD': os.environ.get('MYSQL_ROOT_PASSWORD'),
'HOST': os.environ.get('MYSQL_HOST'),
'PORT': '3306',
}
}
Expand Down
23 changes: 23 additions & 0 deletions init_migrate_db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
set -e

python manage.py makemigrations
python manage.py migrate
if [[ $? -ne 0 ]]; then
echo "Couldn't load migrations into DB."
exit 1
fi
if [ $1 == "--load-template-data" ]; then
if [[ ! -f /evoting/templateMigrationData.lock ]]; then
python manage.py loaddata /evoting/templateMigrationData.json
now="$(date)"
echo "templateMigrationData loaded at $now" > /evoting/templateMigrationData.lock
echo "Loaded templateMigrationData.json data into DB."
else
echo "Unable to load templateMigrationData.json as already loaded once:"
cat /evoting/templateMigrationData.lock
echo "Reloading would result in losing all generated data in the DB."
fi
else
echo "Not loading tempalte data. Use '--load-template-data'."
fi

0 comments on commit 7b205e6

Please sign in to comment.