Skip to content

Commit

Permalink
Setting up docker; installing sekizai; starting with base templates
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastiaanZ committed Jul 17, 2019
1 parent 84392b6 commit 07989f2
Show file tree
Hide file tree
Showing 18 changed files with 244 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,3 +1,3 @@
.idea
*/__pycache__/*
__pycache__
*test-*.xml
3 changes: 2 additions & 1 deletion Pipfile
Expand Up @@ -5,8 +5,9 @@ verify_ssl = true

[packages]
django = "*"
"django-sekizai" = "*"
"django-simple-bulma" = "*"
psycopg2-binary = "*"
"psycopg2-binary" = "*"

[dev-packages]
"flake8" = "*"
Expand Down
15 changes: 14 additions & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions docker-compose.yml
@@ -0,0 +1,31 @@
version: "3.7"
services:
postgres:
image: postgres:12-alpine
ports:
- "127.0.0.1:7777:5432"
environment:
POSTGRES_DB: minigigs
POSTGRES_PASSWORD: verysecurepassword
POSTGRES_USER: minigigs

web:
build:
context: .
dockerfile: docker/app/Dockerfile.local
command: docker/app/scripts/migrate_and_serve.sh
ports:
- "127.0.0.1:8000:8000"
depends_on:
- postgres
volumes:
- .:/app:ro
- staticfiles:/var/www/static
environment:
DATABASE_URL: postgres://minigigs:verysecurepassword@postgres:5432/minigigs
DEBUG: "true"
SECRET_KEY: suitable-for-development-only
STATIC_ROOT: /var/www/static

volumes:
staticfiles:
49 changes: 49 additions & 0 deletions docker/app/Dockerfile.local
@@ -0,0 +1,49 @@
FROM bitnami/python:3.7-prod

# I have no idea what this does.
STOPSIGNAL SIGQUIT
ARG EXTRAS=deploy

# Create a user.
RUN adduser \
--disabled-login \
--no-create-home \
--uid 1500 \
minigigs

# Install prerequisites needed to complete the dependency installation.
RUN apt-get update -y \
&& \
apt-get install --no-install-recommends -y \
gcc \
libc-dev \
libpq-dev \
git \
&& \
apt-get clean \
&& \
rm -rf /var/lib/apt/lists/*

# Set up the working directory.
WORKDIR /app
COPY Pipfile Pipfile.lock /app/

# Pip install the stuff we'll need.
RUN rm -r /opt/bitnami/python/lib/python3.*/site-packages/setuptools* && \
pip install --no-cache-dir -U setuptools
RUN python3 -m pip install pipenv \
&& python3 -m pipenv install --system --deploy \
&& pip install uwsgi==2.0.18

# Copy everything into the docker environment.
COPY . .

RUN SECRET_KEY=placeholder DATABASE_URL=sqlite:// python3 manage.py collectstatic --no-input --clear --verbosity 0

# Remove the prerequisites, dependency installation is now complete.
RUN apt-get purge -y \
gcc \
libc-dev \
libpq-dev

CMD ["uwsgi", "--ini", "docker/app/uwsgi.ini"]
20 changes: 20 additions & 0 deletions docker/app/scripts/migrate_and_serve.sh
@@ -0,0 +1,20 @@
#!/bin/sh -eu

### NOTE
# This file is intended to be used by local setups.
# You do not want to run the Django development server
# in production. The default Dockerfile command will
# run using uWSGI, this script is provided purely as
# a convenience to run migrations and start a development server.

echo [i] Applying migrations.
python manage.py migrate --verbosity 1

echo [i] Collecting static files.
python manage.py collectstatic --no-input --clear --verbosity 1

echo [i] Creating a superuser.
echo "from django.contrib.auth import get_user_model; User = get_user_model(); User.objects.create_superuser('admin', 'admin', 'admin') if not User.objects.filter(username='admin').exists() else print('Admin user already exists')" | python manage.py shell

echo [i] Starting server.
python manage.py runserver 0.0.0.0:8000
38 changes: 38 additions & 0 deletions docker/app/uwsgi.ini
@@ -0,0 +1,38 @@
[uwsgi]
### Exposed ports
# uWSGI protocol socket
socket = :4000

### File settings
# WSGI application
wsgi = website.wsgi:application
# Directory to move into at startup
chdir = /app

### Concurrency options
# Run a master to supervise the workers
master = true
# Keep a minimum of 1 worker
cheaper = 1
# Allow a maximum of 4 workers
workers = 4
# Automatically set up meanginful process names
auto-procname = true
# Prefix process names with `pydis_site : `
procname-prefix-spaced = minigigs_site :

### Worker options
# Kill workers if they take more than 30 seconds to respond.
harakiri = 30

### Startup settings
# Exit if we can't load the app
need-app = true
# `setuid` to an unprivileged user
uid = 1500
# Do not use multiple interpreters
single-interpreter = true

### Hook setup
# Gracefully kill workers on `SIGQUIT`
hook-master-start = unix_signal:3 gracefully_kill_them_all
Empty file added website/home/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions website/home/admin.py
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
5 changes: 5 additions & 0 deletions website/home/apps.py
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class HomeConfig(AppConfig):
name = 'website.home'
Empty file.
3 changes: 3 additions & 0 deletions website/home/models.py
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
3 changes: 3 additions & 0 deletions website/home/tests.py
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
7 changes: 7 additions & 0 deletions website/home/urls.py
@@ -0,0 +1,7 @@
from django.urls import path

from . import views

urlpatterns = [
path('', views.index, name='index'),
]
5 changes: 5 additions & 0 deletions website/home/views.py
@@ -0,0 +1,5 @@
from django.http import HttpResponse


def index(request):
return HttpResponse("Hello, world. You're at the polls index.")
26 changes: 22 additions & 4 deletions website/settings.py
Expand Up @@ -20,17 +20,26 @@
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '0wvql_dqlc(d&^ft)b=-=%im&yq@v==b9!vcp!boq9060quw^g'
SECRET_KEY = 'suitable-for-development-only'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []
ALLOWED_HOSTS = [
'minigigscyclingteam.local'
]


# Application definition

INSTALLED_APPS = [


# Plugins
'django_simple_bulma',

'sekizai',
# Default apps
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
Expand Down Expand Up @@ -62,6 +71,7 @@
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
"sekizai.context_processors.sekizai",
],
},
},
Expand All @@ -79,8 +89,8 @@
'NAME': 'minigigs',
'USER': 'minigigs',
'PASSWORD': 'verysecurepassword',
'HOST': 'localhost',
'PORT': '',
'HOST': 'postgres',
'PORT': '5432',
}
}

Expand Down Expand Up @@ -122,3 +132,11 @@
# https://docs.djangoproject.com/en/2.2/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = '/var/www/static'

STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',

'django_simple_bulma.finders.SimpleBulmaFinder',
]
39 changes: 39 additions & 0 deletions website/templates/base/base.html
@@ -0,0 +1,39 @@
{% load django_simple_bulma %}
{% load sekizai_tags %}
{% load static %}

<!DOCTYPE html>
<html lang="nl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<meta name="description" content="Website van het Minigigs Cycling Team">
<meta name="keywords" content="Minigigs Cycling Team, Minigigs, Cycling, Wielrennen, Den Haag">
<meta name="author" content="Sebastiaan Zeeff">

<title>Minigigs Cycling Team | {% block title %}Website{% endblock %}</title>

{% bulma %}

{# Font-awesome here is defined explicitly so that we can have Pro #}
<script src="https://kit.fontawesome.com/ae6a3152d8.js"></script>

<link rel="stylesheet" href="{% static "css/base/base.css" %}">
{% block head %}{% endblock %}

{% render_block "css" %}
</head>
<body class="site">
<main class="site-content">
{% block content %}
{{ block.super }}
{% endblock %}
</main>

{% block site_footer %}
{% include "base/footer.html" %}
{% endblock %}

{% render_block "js" %}
</body>
</html>
3 changes: 2 additions & 1 deletion website/urls.py
Expand Up @@ -14,8 +14,9 @@
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.urls import path, include

urlpatterns = [
path('', include('website.home.urls')),
path('admin/', admin.site.urls),
]

0 comments on commit 07989f2

Please sign in to comment.