Skip to content

Commit

Permalink
Dockerize Junction (#749)
Browse files Browse the repository at this point in the history
* Initial commit for Dockerization

* Fix review comments and dockerignore

* Update dev.py.sample with runsslserver

* Fixes for using default settings module

* Remove Dockerfile.celery and use image from junction web image

* Update docker-compose.test.yml to not depend on postgres db

* Add static asset compilation in Docker image

* Add docker-compose.prod.yml and update server port configuration in application

* Add social oauth env vars

---------

Co-authored-by: Sanchit Balchandani <[email protected]>
Co-authored-by: Ananya Maiti <[email protected]>
  • Loading branch information
inovizz and Ananya Maiti committed Apr 24, 2023
1 parent ca0bf41 commit 9caf34e
Show file tree
Hide file tree
Showing 20 changed files with 321 additions and 94 deletions.
50 changes: 50 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# .dockerignore

# Ignore Python bytecode files
__pycache__/
*.pyc
*.pyo
*.pyd

# Ignore virtual environment directories
venv/
*.virtualenv/
.env/

# Ignore Django migration files
*/migrations/*.pyc
*/migrations/__pycache__/

# Ignore logs
logs/
*.log

# Ignore configuration files
*.ini

# Ignore user-specific files (e.g., editor settings)
*.swp
*.swo
*.swn
*.bak
*.tmp
*.sublime*
*.vscode/

# Ignore local media files
media/

# Ignore local database files (SQLite)
*.sqlite3
*.sqlite3-journal

# Ignore test coverage reports
.coverage
htmlcov/

# Ignore build artifacts and distribution files
build/
dist/
*.egg-info/
*.egg
*.wheel
24 changes: 24 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
DEBUG=TRUE
POSTGRES_USER=postgres
POSTGRES_PASSWORD=junction
POSTGRES_DB=junction
HOST_NAME=db
DB_PORT=5432
BROKER_URL=redis://redis:6379/0
CELERY_RESULT_BACKEND=redis://redis:6379/0
SITE_NAME=junction
SERVER_PORT=8888
GOOGLE_ANALYTICS_ID=google_analytics_id
FACEBOOK_APP_ID=fb_app_id
EMAIL_HOST_USER=email_host_user
EMAIL_HOST_PASSWORD=email_host_pass
SECRET_KEY=secret_key
GITHUB_CLIENT_ID=github_client_id
GITHUB_CLIENT_SECRET=github_client_secret
GOOGLE_CLIENT_ID=google_oauth_client_id
GOOGLE_CLIENT_SECRET=google_oauth_client_secret
TWITTER_CONSUMER_KEY=twitter_consume_key
TWITTER_CONSUMER_SECRET=twitter_consume_secret
TWITTER_ACCESS_TOKEN_KEY=twitter_access_token
TWITTER_ACCESS_TOKEN_SECRET=twitter_access_token_secret
USE_ASYNC_FOR_EMAIL=boolean
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,7 @@ qr_files/
#VSCode
.vscode/

tmp/
tmp/

# Env
.env
32 changes: 32 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM python:3.10-slim-buster

WORKDIR /code

RUN apt-get update && \
apt-get install -y --no-install-recommends \
gcc \
postgresql-client \
build-essential \
nodejs \
npm \
libpq-dev && \
rm -rf /var/lib/apt/lists/*

COPY requirements.txt /code/
RUN pip install --no-cache-dir -r requirements.txt

# Install requirements for running tests
COPY ./tools/requirements-test.txt /code/
RUN pip install --no-cache-dir -r requirements-test.txt

RUN npm install -g yarn
RUN npm install -g grunt-cli

COPY . /code/

RUN chmod +x bin/install-static.sh
RUN bin/install-static.sh
# not getting used at this moment
RUN chmod +x bin/wait-for-it.sh

ENV PYTHONUNBUFFERED=1
5 changes: 5 additions & 0 deletions bin/install-static.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
cd junction/static
yarn install
grunt less
cd ../..
17 changes: 17 additions & 0 deletions bin/wait-for-it.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
# wait-for-it.sh: Wait for a service to be ready.

set -e

host="$1"
port="$2"
shift 2
cmd="$@"

until PGPASSWORD="$POSTGRES_PASSWORD" psql -h "$host" -U "$POSTGRES_USER" -c '\q'; do
>&2 echo "Postgres is unavailable - sleeping"
sleep 1
done

>&2 echo "Postgres is up - executing command"
exec $cmd
41 changes: 41 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
version: '3.8'

services:
db:
image: postgres:15-alpine
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data/
env_file:
- .env

redis:
image: redis:latest
ports:
- "6379:6379"

web:
image: ananyo2012/junction:1.1
volumes:
- .:/code
ports:
- "${SERVER_PORT}:${SERVER_PORT}"
depends_on:
- db
env_file:
- .env
command: sh -c 'python manage.py migrate && python manage.py collectstatic --noinput --clear && gunicorn -c gunicorn.conf.py'

celery:
image: ananyo2012/junction:1.1
depends_on:
- db
- redis
- web
env_file:
- .env
command: sh -c 'celery -A junction worker -l info -E'

volumes:
postgres_data:
8 changes: 8 additions & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: '3.8'

services:
test:
build:
context: .
dockerfile: Dockerfile
command: sh -c pytest --cov=unit --cov=integrations --cov-report=html -v
44 changes: 44 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
version: '3.8'

services:
db:
image: postgres:15-alpine
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data/
env_file:
- .env

redis:
image: redis:latest
ports:
- "6379:6379"

web:
build:
context: .
dockerfile: Dockerfile
image: junction_local
volumes:
- .:/code
ports:
- "${SERVER_PORT}:${SERVER_PORT}"
depends_on:
- db
env_file:
- .env
command: sh -c 'python manage.py migrate && python manage.py runsslserver 0.0.0.0:${SERVER_PORT}'

celery:
image: junction_local
depends_on:
- db
- redis
- web
env_file:
- .env
command: sh -c 'celery -A junction worker -l info -E'

volumes:
postgres_data:
5 changes: 4 additions & 1 deletion gunicorn.conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import os
port = os.environ.get("SERVER_PORT", "8888")

wsgi_app = "wsgi"
bind = "0.0.0.0:8001"
bind = f"0.0.0.0:{port}"
workers = 2
loglevel = "debug"
2 changes: 1 addition & 1 deletion junction/conferences/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.db import models
from six import python_2_unicode_compatible
from django.utils.timezone import now
from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _
from django_extensions.db.fields import AutoSlugField
from simple_history.models import HistoricalRecords
from slugify import slugify
Expand Down
4 changes: 2 additions & 2 deletions junction/conferences/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-

from django.conf.urls import url
from django.urls import re_path

from . import views

urlpatterns = [url(r"^$", views.get_conference, name="get-conference")]
urlpatterns = [re_path(r"^$", views.get_conference, name="get-conference")]
6 changes: 3 additions & 3 deletions junction/profiles/urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from django.conf.urls import url
from django.urls import re_path

from . import views

app_name = "junction.profiles"

urlpatterns = [
url(r"^$", views.dashboard, name="dashboard"),
url(r"^edit/$", views.profile, name="profile"),
re_path(r"^$", views.dashboard, name="dashboard"),
re_path(r"^edit/$", views.profile, name="profile"),
]
43 changes: 22 additions & 21 deletions junction/proposals/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,32 @@
from __future__ import absolute_import, unicode_literals

from django.conf.urls import include, url
from django.urls import re_path

from . import comments_views, dashboard, views, votes_views

comment_urls = [
url(
re_path(
r"^(?P<proposal_slug>[\w-]+)/create/$",
comments_views.create_proposal_comment,
name="proposal-comment-create",
),
url(
re_path(
r"^(?P<proposal_slug>[\w-]+)/comments/(?P<proposal_comment_id>\d+)/up-vote/$",
votes_views.proposal_comment_up_vote,
name="proposal-comment-up-vote",
),
url(
re_path(
r"^(?P<proposal_slug>[\w-]+)/comments/(?P<proposal_comment_id>\d+)/down-vote/$",
votes_views.proposal_comment_down_vote,
name="proposal-comment-down-vote",
),
url(
re_path(
r"^(?P<proposal_slug>[\w-]+)/comments/(?P<proposal_comment_id>\d+)/mark_spam/$",
comments_views.mark_comment_as_spam,
name="comment_mark_spam",
),
url(
re_path(
r"^(?P<proposal_slug>[\w-]+)/comments/(?P<proposal_comment_id>\d+)/unmark_spam/$",
comments_views.unmark_comment_as_spam,
name="comment_unmark_spam",
Expand All @@ -35,56 +36,56 @@

urlpatterns = [
# proposal urls
url(r"^$", views.list_proposals, name="proposals-list"),
url(r"^create/$", views.create_proposal, name="proposal-create"),
url(r"^to_review/$", views.proposals_to_review, name="proposals-to-review"),
url(
re_path(r"^$", views.list_proposals, name="proposals-list"),
re_path(r"^create/$", views.create_proposal, name="proposal-create"),
re_path(r"^to_review/$", views.proposals_to_review, name="proposals-to-review"),
re_path(
r"^second_phase_voting/$",
dashboard.second_phase_voting,
name="second-phase-voting",
),
url(r"^(?P<slug>[\w-]+)/$", views.detail_proposal, name="proposal-detail"),
url(
re_path(r"^(?P<slug>[\w-]+)/$", views.detail_proposal, name="proposal-detail"),
re_path(
r"^(?P<slug>[\w-]+)~(?P<hashid>.*)/$",
views.detail_proposal,
name="proposal-detail",
),
url(r"^(?P<slug>[\w-]+)/delete/$", views.delete_proposal, name="proposal-delete"),
url(r"^(?P<slug>[\w-]+)/update/$", views.update_proposal, name="proposal-update"),
url(
re_path(r"^(?P<slug>[\w-]+)/delete/$", views.delete_proposal, name="proposal-delete"),
re_path(r"^(?P<slug>[\w-]+)/update/$", views.update_proposal, name="proposal-update"),
re_path(
r"^(?P<slug>[\w-]+)/upload-content/$",
views.proposal_upload_content,
name="proposal-upload-content",
),
url(
re_path(
r"^(?P<slug>[\w-]+)/change-proposal-review-state/$",
views.review_proposal,
name="proposal-review",
),
# comment urls
url(r"^comment/", include(comment_urls)),
re_path(r"^comment/", include(comment_urls)),
# Voting
url(
re_path(
r"^(?P<proposal_slug>[\w-]+)/down-vote/$",
votes_views.proposal_vote_down,
name="proposal-vote-down",
),
url(
re_path(
r"^(?P<proposal_slug>[\w-]+)/up-vote/$",
votes_views.proposal_vote_up,
name="proposal-vote-up",
),
url(
re_path(
r"^(?P<proposal_slug>[\w-]+)/remove-vote/$",
votes_views.proposal_vote_remove,
name="proposal-vote-remove",
),
url(
re_path(
r"^(?P<proposal_slug>[\w-]+)/vote/$",
votes_views.proposal_reviewer_vote,
name="proposal-reviewer-vote",
),
url(
re_path(
r"^(?P<proposal_slug>[\w-]+)/second-vote/$",
votes_views.proposal_reviewer_secondary_vote,
name="proposal-reviewer-secondary-vote",
Expand Down
Loading

0 comments on commit 9caf34e

Please sign in to comment.