Skip to content

Commit

Permalink
Enabled Docker for Heroku
Browse files Browse the repository at this point in the history
  • Loading branch information
gusbemacbe committed Jun 20, 2021
1 parent 357cf6c commit 14aae06
Show file tree
Hide file tree
Showing 17 changed files with 256 additions and 37 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__pycache__
*.pyc
env/
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,6 @@ dist
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
.pnp.*

.env
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM python:3.9.5

ENV PYTHONUNBUFFERED=1

WORKDIR /code

COPY backup/docker-requirements.txt /code/
RUN pip install -r docker-requirements.txt

COPY . /code/

RUN chmod au+x release
RUN ./release
9 changes: 6 additions & 3 deletions Procfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
release: chmod au+x release && ./release
web: gunicorn gusbemacbe.wsgi --log-file -
# Traditional
# release: chmod au+x release && ./release
# web: gunicorn gusbemacbe.wsgi --log-file -

# Docker
# worker: python manage.py rqworker default
release: chmod au+x release && ./release
web: gunicorn gusbemacbe.wsgi --log-file -
worker: python manage.py rqworker default
20 changes: 20 additions & 0 deletions backup/docker-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
asgiref==3.3.4
dj-database-url==0.5.0
Django==3.2.4
django-dbbackup==3.3.0
django-extensions==3.1.3
django-heroku==0.3.1
django-redis-cache==3.0.0
django-rq==2.4.1
django-smuggler==1.0.2
django-sslserver==0.22
djangorestframework==3.12.4
forex-python==1.6
gunicorn==20.1.0
pandas==1.2.4
psycopg2-binary==2.9.1
pymdown-extensions==8.2
python-decouple==3.4
pytz==2021.1
sqlparse==0.4.1
whitenoise==5.2.0
4 changes: 2 additions & 2 deletions backup/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# ipychart
dj-database-url
Django
# django-chartjs
Expand All @@ -11,7 +10,8 @@ django-sslserver
djangorestframework
forex-python
gunicorn
# pandas
# ipychart
pandas
# psycopg2
psycopg2-binary
pymdown-extensions
Expand Down
2 changes: 1 addition & 1 deletion contrib/env_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
CONFIG_STRING = """
DEBUG = True
SECRET_KEY = %s
ALLOWED_HOSTS = 127.0.0.1, localhost, localhost:1984, 0.0.0.0
ALLOWED_HOSTS = *, 127.0.0.1, localhost, localhost:1980, localhost:1984, 0.0.0.0
DATABASE_URL = sqlite:https:///db.sqlite3
# POSTGRES_DB_URL = postgres:https://USER:PASSWORD@HOST:PORT/NAME
Expand Down
Binary file modified db.sqlite3
Binary file not shown.
40 changes: 40 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
version: '3.9'

services:
db:
image: postgres
restart: always
volumes:
- pgdata:/var/lib/postgresql/data/
environment:
- POSTGRES_DB=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
environment:
DEBUG: 1
volumes:
- .:/app
ports:
- 8000:8000
depends_on:
- db
- redis

worker:
build: .
command: python manage.py rqworker default
environment:
DEBUG: 1
volumes:
- .:/app
depends_on:
- web

redis:
image: redis:latest

volumes:
pgdata:
11 changes: 4 additions & 7 deletions docker/dockerfiles/arch
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Pull base image
FROM archlinux/archlinux:latest

# Install psql so that "python manage.py dbshell" works
RUN yes | pacman -Syu
RUN yes | pacman -Syyu

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
Expand All @@ -12,12 +11,10 @@ ENV PYTHONUNBUFFERED 1
WORKDIR /app

# Install dependencies
RUN yes | pacman -S neofetch postgresql postgresql-libs python python-pip python-psycopg2 python-pytz tidy
RUN neofetch
RUN python --version
RUN yes | pacman -S --needed gcc postgresql postgresql-libs python python-pip

COPY requirements.txt /app/requirements.txt
RUN pip install --user -r /app/requirements.txt
COPY pyproject.toml /app/pyproject.toml
RUN poetry install

# Copy project
COPY . /app/
42 changes: 36 additions & 6 deletions gusbemacbe/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
# third-party apps
# 'chartjs',
'dbbackup',
'django_rq',
'django_extensions',
'smuggler',
'sslserver',
Expand All @@ -75,7 +76,7 @@
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
# 'tidy.middleware.TidyMiddleware',
# 'tidy.middleware.TidyMiddleware'
]

# ROOT_URLCONF = '{{ project_name }}.urls'
Expand Down Expand Up @@ -110,11 +111,13 @@
# }
# }

default_dburl = 'sqlite:https:///' + str(BASE_DIR / 'db.sqlite3')

DATABASES = {
'default': config('DATABASE_URL', default = default_dburl, cast = dburl),
}
# DATABASES = {
# # If DATABASE_URL environment variable isn't set, use Docker Compose Postgres database.
# 'default': dj_database_url.config(
# default = 'postgres:https://postgres:postgres@db:5432/gusbemacbe',
# conn_max_age = 600,
# )
# }

# DATABASES = {
# 'default': {
Expand All @@ -127,6 +130,12 @@
# }
# }

default_dburl = 'sqlite:https:///' + str(BASE_DIR / 'db.sqlite3')

DATABASES = {
'default': config('DATABASE_URL', default = default_dburl, cast = dburl),
}

DBBACKUP_STORAGE = 'django.core.files.storage.FileSystemStorage'
DBBACKUP_STORAGE_OPTIONS = {'location': 'backup/'}

Expand Down Expand Up @@ -193,6 +202,27 @@
# Add configuration for static files storage using whitenoise
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

# Configure Redis cache and Django-RQ.

# https://django-redis-cache.readthedocs.io/en/latest/intro_quick_start.html#quick-start
CACHES = {
'default': {
'BACKEND': 'redis_cache.RedisCache',
# By default use Docker Compose Redis instance.
'LOCATION': os.getenv('REDIS_URL', 'redis:6379'),
},
}

# https://github.com/rq/django-rq#support-for-django-redis-and-django-redis-cache
RQ_QUEUES = {
'default': {
'USE_REDIS_CACHE': 'default',
'DEFAULT_TIMEOUT': 360,
},
}

RQ_SHOW_ADMIN_LINK = True

# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
Expand Down
Empty file.
Empty file.
1 change: 1 addition & 0 deletions gusbemacbe/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
path('admin/', include('smuggler.urls')), # before admin url patterns!
path('', home_view, name = 'home'),
path('admin/', admin.site.urls),
path('django-rq/', include('django_rq.urls')),

# Pages
path('aparecida-covid-19-tracker/', include('AparecidaCovidTracker.urls')),
Expand Down
3 changes: 3 additions & 0 deletions heroku.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build:
docker:
web: Dockerfile
Loading

0 comments on commit 14aae06

Please sign in to comment.