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

Docker configuration for production, development and testing #23

Open
wants to merge 14 commits into
base: dev
Choose a base branch
from
Open
14 changes: 6 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
language: python
python:
- "3.5"
language: generic
sudo: required
services:
- docker
before_script:
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
- chmod +x ./cc-test-reporter
- ./cc-test-reporter before-build
script:
- flake8 api_graphql app data_models
- yapf -pdr api_graphql app data_models -e '**/migrations' -e '**/snapshots'
- isort -c -rc api_graphql app data_models
- py.test --cov-report=xml
- docker-compose run test
after_script:
- ./cc-test-reporter after-build
- docker-compose run test ./cc-test-reporter after-build
env:
global:
- GIT_COMMITTED_AT=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then git log -1 --pretty=format:%ct; else git log -1 --skip 1 --pretty=format:%ct; fi)
12 changes: 12 additions & 0 deletions Dockerfile.base
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM alpine:3.7

ENV APP_DIR=/srv/app

RUN mkdir -p $APP_DIR

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

En liten kommentar. Blir ikkje dette automatisk gjort når du setter $APP_DIR til å vere WORKDIR?

WORKDIR $APP_DIR

RUN apk add --update --no-cache git gcc libc-dev python3 python3-dev jpeg-dev zlib-dev
ENV LIBRARY_PATH=/lib:/usr/lib

COPY requirements.txt .
RUN pip3 --no-cache-dir install -r requirements.txt
3 changes: 3 additions & 0 deletions Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM kapina_base:latest

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meir eit spørsmål, men er ikkje det meir anbefalt å bruke Docker sin multi-stage build, for å få til fleire nivå? Usikker korleis dette fungerer rundt docker-compose, men det ser ut til at ein skal kunne referere til target i docker-compose v3.4. Ref. docker/compose#5191 og docker/cli#430


RUN apk add --update --no-cache uwsgi-python3
53 changes: 53 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
version: '3'
services:
base:
image: kapina_base:latest
build:
context: .
dockerfile: Dockerfile.base
test:
build:
context: .
dockerfile: Dockerfile.base
volumes:
- .:/srv/app/
command: ./docker/run_tests.sh
environment:
- GIT_COMMITTED_AT
- CC_TEST_REPORTER_ID
dev:
build:
context: .
dockerfile: Dockerfile.base
volumes:
- .:/srv/app/
command: ./docker/run_dev.sh
ports:
- "8000:8000"
environment:
- REVOLT_DEBUG
- REVOLT_ALLOWED_HOSTS
- REVOLT_STATIC_ROOT
- REVOLT_MEDIA_ROOT
- REVOLT_SECRET_KEY
- REVOLT_RAVEN_DSN
- DATABASE_URL
production:
depends_on:
- base
build:
context: .
dockerfile: Dockerfile.prod
volumes:
- .:/srv/app/
command: ./docker/run_production.sh
ports:
- "8000:8000"
environment:
- REVOLT_DEBUG=false
- REVOLT_ALLOWED_HOSTS
- REVOLT_STATIC_ROOT
- REVOLT_MEDIA_ROOT
- REVOLT_SECRET_KEY
- REVOLT_RAVEN_DSN
- DATABASE_URL
3 changes: 3 additions & 0 deletions docker/run_dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
python3 manage.py migrate
python3 manage.py runserver 0.0.0.0:8000
4 changes: 4 additions & 0 deletions docker/run_production.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
python3 manage.py migrate
python3 manage.py collectstatic --no-input
uwsgi -i uwsgi.ini
5 changes: 5 additions & 0 deletions docker/run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
flake8 api_graphql app data_models
yapf -pdr api_graphql app data_models -e '**/migrations' -e '**/snapshots'
isort -c -rc api_graphql app data_models
py.test --cov-report=xml
8 changes: 8 additions & 0 deletions uwsgi.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[uwsgi]
module = app.wsgi:application
vacuum = True
master = True
http-socket = :8000
static-map = /static=./staticfiles
static-map = /media=./mediafiles
plugins = python3