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

Dockerize #11

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# To make sure DB and media and static files are not tampered for update in container. It would be mounted as a volume
#If static files are updated, RUN python manage.py collectstatic in docker container
db.sqlite3
databases/db.sqlite3
media/
static/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*.pyc
__pycache__/
local_settings.py
databases/db.sqlite3
db.sqlite3
db.sqlite3-journal
media
Expand Down
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#Not using pipenv as docker itself is a container
#username, email and password is hardcoded here. Make sure you chnage this before deploy and to .env/GitHub secrets or any secure way
FROM python:3
ENV PYTHONUNBUFFERED=1
RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/
RUN python manage.py collectstatic
RUN python manage.py migrate
RUN python manage.py makemigrations
RUN python manage.py migrate --run-syncdb
RUN echo "from django.contrib.auth.models import User; User.objects.create_superuser('admin-badge', 'admin@example.com', 'passwordbadge#100')" | python manage.py shell
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
37 changes: 37 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
asgiref = "==3.2.10"
certifi = "==2020.6.20"
cffi = "==1.14.0"
chardet = "==3.0.4"
cryptography = "==2.9.2"
defusedxml = "==0.6.0"
psycopg2 = "==2.8.5"
django-braces = "==1.14.0"
django-cors-headers = "==3.4.0"
django-oauth-toolkit = "==1.3.2"
django-rest-framework-social-oauth2 = "==1.1.0"
djangorestframework = "==3.11.0"
gunicorn = "==20.0.4"
idna = "==2.10"
oauthlib = "==3.1.0"
pycparser = "==2.20"
python-decouple = "==3.3"
python3-openid = "==3.2.0"
pytz = "==2020.1"
requests = "==2.24.0"
requests-oauthlib = "==1.3.0"
six = "==1.15.0"
social-auth-app-django = "==4.0.0"
social-auth-core = "==3.3.3"
sqlparse = "==0.3.1"
urllib3 = "==1.25.9"
Django = "==3.0.7"
Pillow = "==7.1.2"
PyJWT = "==1.7.1"
327 changes: 327 additions & 0 deletions Pipfile.lock

Large diffs are not rendered by default.

Empty file added databases/.none
Empty file.
12 changes: 12 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: "3.8"
services:
api:
build: .
ports:
- "5000:8000"
volumes:
- ./databases:/code/databases
- ./media:/code/media

#Media and Database added a volume mount from a folder on the machine running the image.
#This helps to make sure on docker image update, the data is preserved and only backend code changes
2 changes: 1 addition & 1 deletion omgbadges/settings/development.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
'NAME': os.path.join(BASE_DIR, 'databases', 'db.sqlite3'),
}
}
25 changes: 17 additions & 8 deletions omgbadges/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,23 @@
'http://localhost:8080',
'https://dscomg.com',
]

#Default for production is set to use sqlite
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': config('DB_NAME'),
'USER': config('DB_USER'),
'PASSWORD':config('DB_PASSWORD'),
'HOST': config('DB_HOST'),
'PORT': config('DB_PORT')
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'databases', 'db.sqlite3'),
}
}
}


#Use below one to use postgresql for production
#DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.postgresql_psycopg2',
# 'NAME': config('DB_NAME'),
# 'USER': config('DB_USER'),
# 'PASSWORD':config('DB_PASSWORD'),
# 'HOST': config('DB_HOST'),
# 'PORT': config('DB_PORT')
# }
#}