This repository has been archived by the owner on Oct 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Emulates blossom deployment with docker-compose (#130)
* Emulates blossom deployment with docker-compose * Allow for passing other commands to blossom container image * Ignore `docker/` misc bin. We move them on build anyway. Anything in `docker/` is going to be mounted in a different spot, so things like "I'm unable to find this import you're referencing" mean nothing. * Adds hat-tip in README for docker-compose method The docker approach helps with manual testing, but is not (currently) built for running automated tests. That would need more effort put into it, if it's even feasible.
- Loading branch information
1 parent
e00af9f
commit 9ebdd8d
Showing
9 changed files
with
172 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
version: '3' | ||
services: | ||
db: | ||
image: postgres:11.5-alpine | ||
environment: | ||
POSTGRES_DB: 'local_blossom' | ||
POSTGRES_PASSWORD: 'this-is-not-prod-so-why-do-we-care' | ||
POSTGRES_USER: 'blossom_is_the_best' | ||
volumes: | ||
- ./docker/init.sql:/docker-entrypoint-initdb.d/init.sql:ro | ||
ports: | ||
- 5432:5432 | ||
|
||
blossom: | ||
depends_on: | ||
- db | ||
build: | ||
context: . | ||
dockerfile: ./docker/blossom.Dockerfile | ||
environment: | ||
ENVIRONMENT: local | ||
PORT: '8000' | ||
BLOSSOM_SECRET_KEY: 'imhenrytheeigthiam.henrytheeigthiamiam.igotmarriedtothewidownextdoor.shesbeenmarriedseventimesbefore' | ||
BLOSSOM_DB_DATABASE: 'local_blossom' | ||
BLOSSOM_DB_USERNAME: 'blossom_is_the_best' | ||
BLOSSOM_DB_PASSWORD: 'this-is-not-prod-so-why-do-we-care' | ||
BLOSSOM_DB_HOST: db # Funky DNS stuff with docker-compose. See above service. | ||
BLOSSOM_DB_PORT: '5432' | ||
DJANGO_LOG_LEVEL: INFO | ||
volumes: | ||
- static:/app/blossom/static | ||
- ./blossom/settings:/app/blossom/settings:ro | ||
- ./docker/local_settings.py:/app/blossom/settings/local.py:ro | ||
|
||
http: | ||
depends_on: | ||
- blossom # Because DNS needs to be there or this container fails | ||
image: nginx:alpine | ||
volumes: | ||
- ./docker/nginx.conf:/etc/nginx/conf.d/default.conf | ||
- static:/data/static:ro | ||
ports: | ||
- 8080:80 | ||
|
||
volumes: | ||
static: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
|
||
if [ "$1" = "runserver" ]; then | ||
python manage.py migrate | ||
python manage.py bootstrap_site | ||
python manage.py collectstatic --noinput -v 0 | ||
|
||
exec gunicorn -c ./blossom/instrumentation.py --access-logfile - --workers 3 --bind "0.0.0.0:${PORT}" blossom.wsgi:application | ||
# python manage.py runserver "0.0.0.0:${PORT}" | ||
else | ||
exec "$@" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
FROM python:3-slim as base | ||
|
||
# Ensures output from python is sent straight to the terminal without buffering it first | ||
ENV PYTHONUNBUFFERED 1 | ||
|
||
# It's a container and we know pip should be upgraded. Shaddup | ||
ENV PIP_DISABLE_PIP_VERSION_CHECK 1 | ||
|
||
# hadolint ignore=DL3013,DL3042 | ||
RUN pip install --upgrade pip | ||
|
||
WORKDIR /app | ||
|
||
FROM base as builder | ||
|
||
# hadolint ignore=DL3013,DL3042 | ||
RUN pip install poetry | ||
|
||
COPY ./pyproject.toml /app | ||
COPY ./poetry.lock /app | ||
|
||
RUN poetry export --format=requirements.txt --output=requirements.txt | ||
|
||
FROM base as runtime | ||
|
||
ENV PORT 8080 | ||
EXPOSE 8080 | ||
|
||
COPY . /app | ||
|
||
COPY ./docker/blossom-entrypoint.sh /docker-entrypoint.sh | ||
|
||
COPY --from=builder /app/requirements.txt /app/requirements.txt | ||
|
||
# hadolint ignore=DL3013,DL3042 | ||
RUN pip install -r requirements.txt | ||
|
||
ENTRYPOINT ["bash", "/docker-entrypoint.sh"] | ||
CMD ["runserver"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
-- | ||
-- Here's where you would write some initial SQL prior to | ||
-- running DB migrations. Perhaps activating a pg extension? | ||
-- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# noinspection PyUnresolvedReferences | ||
from blossom.settings.base import * | ||
|
||
ENVIRONMENT = "local" | ||
|
||
DEBUG = True | ||
ENABLE_SLACK = False | ||
|
||
ALLOWED_HOSTS = ["*"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# upstream blossom { | ||
# server blossom resolve; | ||
# } | ||
|
||
server { | ||
listen 80; | ||
listen [::]:80; | ||
server_name localhost blossom.localhost; | ||
|
||
#access_log /var/log/nginx/host.access.log main; | ||
|
||
location /static/ { | ||
root /data; | ||
index index.html index.htm; | ||
} | ||
|
||
location / { | ||
proxy_pass http://blossom:8000; | ||
} | ||
|
||
#error_page 404 /404.html; | ||
|
||
# redirect server error pages to the static page /50x.html | ||
# | ||
error_page 500 502 503 504 /50x.html; | ||
location = /50x.html { | ||
root /usr/share/nginx/html; | ||
} | ||
|
||
# proxy the PHP scripts to Apache listening on 127.0.0.1:80 | ||
# | ||
#location ~ \.php$ { | ||
# proxy_pass http://127.0.0.1; | ||
#} | ||
|
||
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 | ||
# | ||
#location ~ \.php$ { | ||
# root html; | ||
# fastcgi_pass 127.0.0.1:9000; | ||
# fastcgi_index index.php; | ||
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; | ||
# include fastcgi_params; | ||
#} | ||
|
||
# deny access to .htaccess files, if Apache's document root | ||
# concurs with nginx's one | ||
# | ||
#location ~ /\.ht { | ||
# deny all; | ||
#} | ||
} | ||
|