Skip to content

Commit 7b205e6

Browse files
authored
Merge pull request #1 from tameeshB/docerize
Docerize
2 parents 4f1725c + 2620534 commit 7b205e6

File tree

9 files changed

+81
-19
lines changed

9 files changed

+81
-19
lines changed

.env

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
export MYSQL_DB='evoting'
2-
export MYSQL_User='root'
3-
export MYSQL_Pass='root'
4-
export MYSQL_Host='localhost'
5-
export smtp_sender='webmail@iitp.ac.in'
6-
export smtp_pass='password'
1+
MYSQL_DATABASE=evoting_db
2+
MYSQL_PASSWORD=root
3+
MYSQL_ROOT_PASSWORD=root
4+
MYSQL_HOST=db
5+
smtp_sender=your-webmail@iitp.ac.in
6+
smtp_pass=password

Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM python:3.7
2+
ENV PYTHONUNBUFFERED 1
3+
RUN mkdir /evoting
4+
WORKDIR /evoting
5+
ADD . /evoting/
6+
RUN pip install -r REQUIREMENTS.txt && \
7+
chmod +x init_migrate_db.sh

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55

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

8+
## Docker Deployment:
9+
1. `docker-compose --env-file .env build`
10+
2. `docker-compose --env-file .env up -d`
11+
3. `docker-compose exec web bash /evoting/init_migrate_db.sh --load-template-data`
12+
13+
814
## apt/brew Dependencies
915
1. Python : >=3.5
1016
2. Chrome : >=68 (for running functional tests)

REQUIREMENTS.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
django
2-
pymysql
3-
selenium
1+
django==3.0.2
2+
pymysql==0.9.3
3+
mysqlclient==1.3.13
4+
selenium

docker-compose.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
version: "2.1"
2+
services:
3+
db:
4+
image: mysql:5.7
5+
ports:
6+
- '3306:3306'
7+
env_file:
8+
- .env
9+
restart: on-failure
10+
healthcheck:
11+
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
12+
timeout: 20s
13+
retries: 10
14+
web:
15+
build: .
16+
command: python manage.py runserver 0.0.0.0:8000
17+
env_file:
18+
- .env
19+
# volumes:
20+
# - .:/evoting
21+
ports:
22+
- "8000:8000"
23+
restart: on-failure
24+
depends_on:
25+
db:
26+
condition: service_healthy

evoting/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
import pymysql
22

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

evoting/mysql.conf

Lines changed: 0 additions & 5 deletions
This file was deleted.

evoting/settings.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@
8282
# }
8383
DATABASES = {
8484
'default': {
85-
'ENGINE': 'django.db.backends.mysql',
86-
'NAME': os.environ.get('MYSQL_DB'),
87-
'USER': os.environ.get('MYSQL_User'),
88-
'PASSWORD': os.environ.get('MYSQL_Pass'),
89-
'HOST': os.environ.get('MYSQL_Host'),
85+
'ENGINE': 'django.db.backends.mysql',
86+
'NAME': os.environ.get('MYSQL_DATABASE'),
87+
'USER': 'root', # os.environ.get('MYSQL_USER')
88+
'PASSWORD': os.environ.get('MYSQL_ROOT_PASSWORD'),
89+
'HOST': os.environ.get('MYSQL_HOST'),
9090
'PORT': '3306',
9191
}
9292
}

init_migrate_db.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
set -e
3+
4+
python manage.py makemigrations
5+
python manage.py migrate
6+
if [[ $? -ne 0 ]]; then
7+
echo "Couldn't load migrations into DB."
8+
exit 1
9+
fi
10+
if [ $1 == "--load-template-data" ]; then
11+
if [[ ! -f /evoting/templateMigrationData.lock ]]; then
12+
python manage.py loaddata /evoting/templateMigrationData.json
13+
now="$(date)"
14+
echo "templateMigrationData loaded at $now" > /evoting/templateMigrationData.lock
15+
echo "Loaded templateMigrationData.json data into DB."
16+
else
17+
echo "Unable to load templateMigrationData.json as already loaded once:"
18+
cat /evoting/templateMigrationData.lock
19+
echo "Reloading would result in losing all generated data in the DB."
20+
fi
21+
else
22+
echo "Not loading tempalte data. Use '--load-template-data'."
23+
fi

0 commit comments

Comments
 (0)