From 10a021075062471a1ed9e70562a5ce366afe5144 Mon Sep 17 00:00:00 2001 From: Christian Duvholt Date: Mon, 9 Apr 2018 19:23:17 +0200 Subject: [PATCH 01/14] Dockerfile and docker-compose for running tests --- Dockerfile.test | 12 ++++++++++++ docker-compose.test.yml | 9 +++++++++ run_tests.sh | 5 +++++ 3 files changed, 26 insertions(+) create mode 100644 Dockerfile.test create mode 100644 docker-compose.test.yml create mode 100755 run_tests.sh diff --git a/Dockerfile.test b/Dockerfile.test new file mode 100644 index 0000000..45db21b --- /dev/null +++ b/Dockerfile.test @@ -0,0 +1,12 @@ +FROM python:3.5-alpine + +ENV APP_DIR=/srv/app + +RUN mkdir -p $APP_DIR +WORKDIR $APP_DIR + +RUN apk add --update --no-cache git build-base python-dev py-pip jpeg-dev zlib-dev +ENV LIBRARY_PATH=/lib:/usr/lib + +COPY requirements.txt . +RUN pip install -r requirements.txt diff --git a/docker-compose.test.yml b/docker-compose.test.yml new file mode 100644 index 0000000..57e2178 --- /dev/null +++ b/docker-compose.test.yml @@ -0,0 +1,9 @@ +version: '3' +services: + backend: + build: + context: . + dockerfile: Dockerfile.test + volumes: + - .:/srv/app/ + command: /srv/app/run_tests.sh diff --git a/run_tests.sh b/run_tests.sh new file mode 100755 index 0000000..78e6848 --- /dev/null +++ b/run_tests.sh @@ -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 From ea2ed8851698dcc1df42612450dacdbf9882aa74 Mon Sep 17 00:00:00 2001 From: Christian Duvholt Date: Mon, 9 Apr 2018 19:25:24 +0200 Subject: [PATCH 02/14] Use docker-compose to run tests --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0adf597..4ee4fe6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,6 @@ +sudo: required +services: + - docker language: python python: - "3.5" @@ -6,10 +9,7 @@ before_script: - 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 -f docker-compose.test.yml up after_script: - ./cc-test-reporter after-build env: From 76a97d17575a7f8f81b6539ede4b0f9d7b651493 Mon Sep 17 00:00:00 2001 From: Christian Duvholt Date: Mon, 9 Apr 2018 20:02:31 +0200 Subject: [PATCH 03/14] Run coverage report in docker too --- .travis.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4ee4fe6..cdb413a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,6 @@ sudo: required services: - docker -language: python -python: - - "3.5" before_script: - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter - chmod +x ./cc-test-reporter @@ -11,7 +8,7 @@ before_script: script: - docker-compose -f docker-compose.test.yml up after_script: - - ./cc-test-reporter after-build + - docker-compose -f docker-compose.test.yml run backend ./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) From f14cc48dc585e65a13e4bdcf85461aeb4f405763 Mon Sep 17 00:00:00 2001 From: Christian Duvholt Date: Mon, 9 Apr 2018 20:08:20 +0200 Subject: [PATCH 04/14] Pass CI env vars to docker --- docker-compose.test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 57e2178..b1b62c8 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -7,3 +7,6 @@ services: volumes: - .:/srv/app/ command: /srv/app/run_tests.sh + environment: + - GIT_COMMITTED_AT + - CC_TEST_REPORTER_ID From 6bc3aba0dbe6f3a667aa376ca094c032dd3370a7 Mon Sep 17 00:00:00 2001 From: Christian Duvholt Date: Mon, 9 Apr 2018 20:08:46 +0200 Subject: [PATCH 05/14] Set language to generic for Travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index cdb413a..cbdb53c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ +language: generic sudo: required services: - docker From a1ba26a66a9be93a89dadd8ed8a696b4cad35801 Mon Sep 17 00:00:00 2001 From: Christian Duvholt Date: Mon, 9 Apr 2018 21:24:02 +0200 Subject: [PATCH 06/14] Add docker-compose conf for development --- .travis.yml | 4 ++-- Dockerfile.test => Dockerfile.base | 1 + docker-compose.test.yml | 12 ----------- docker-compose.yml | 32 ++++++++++++++++++++++++++++++ run_dev.sh | 3 +++ 5 files changed, 38 insertions(+), 14 deletions(-) rename Dockerfile.test => Dockerfile.base (95%) delete mode 100644 docker-compose.test.yml create mode 100644 docker-compose.yml create mode 100755 run_dev.sh diff --git a/.travis.yml b/.travis.yml index cbdb53c..f6e8bb7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,9 +7,9 @@ before_script: - chmod +x ./cc-test-reporter - ./cc-test-reporter before-build script: - - docker-compose -f docker-compose.test.yml up + - docker-compose run test after_script: - - docker-compose -f docker-compose.test.yml run backend ./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) diff --git a/Dockerfile.test b/Dockerfile.base similarity index 95% rename from Dockerfile.test rename to Dockerfile.base index 45db21b..4820741 100644 --- a/Dockerfile.test +++ b/Dockerfile.base @@ -10,3 +10,4 @@ ENV LIBRARY_PATH=/lib:/usr/lib COPY requirements.txt . RUN pip install -r requirements.txt +EXPOSE 8000 diff --git a/docker-compose.test.yml b/docker-compose.test.yml deleted file mode 100644 index b1b62c8..0000000 --- a/docker-compose.test.yml +++ /dev/null @@ -1,12 +0,0 @@ -version: '3' -services: - backend: - build: - context: . - dockerfile: Dockerfile.test - volumes: - - .:/srv/app/ - command: /srv/app/run_tests.sh - environment: - - GIT_COMMITTED_AT - - CC_TEST_REPORTER_ID diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..8dd8e52 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,32 @@ +version: '3' +services: + base: + build: + context: . + dockerfile: Dockerfile.base + test: + build: + context: . + dockerfile: Dockerfile.base + volumes: + - .:/srv/app/ + command: /srv/app/run_tests.sh + environment: + - GIT_COMMITTED_AT + - CC_TEST_REPORTER_ID + dev: + build: + context: . + dockerfile: Dockerfile.base + volumes: + - .:/srv/app/ + command: ./run_dev.sh + ports: + - "8000:8000" + environment: + - REVOLT_DEBUG + - REVOLT_ALLOWED_HOSTS + - REVOLT_STATIC_ROOT + - REVOLT_MEDIA_ROOT + - REVOLT_SECRET_KEY + - REVOLT_RAVEN_DSN diff --git a/run_dev.sh b/run_dev.sh new file mode 100755 index 0000000..8ddb5c1 --- /dev/null +++ b/run_dev.sh @@ -0,0 +1,3 @@ +#!/bin/sh +python manage.py migrate +python manage.py runserver 0.0.0.0:8000 From 4a8ddafd09c0f40cc852e6dee46e88669c2a1d72 Mon Sep 17 00:00:00 2001 From: Christian Duvholt Date: Mon, 9 Apr 2018 21:26:19 +0200 Subject: [PATCH 07/14] Move docker scripts --- docker-compose.yml | 4 ++-- run_dev.sh => docker/run_dev.sh | 0 run_tests.sh => docker/run_tests.sh | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename run_dev.sh => docker/run_dev.sh (100%) rename run_tests.sh => docker/run_tests.sh (100%) diff --git a/docker-compose.yml b/docker-compose.yml index 8dd8e52..e9dff7d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,7 @@ services: dockerfile: Dockerfile.base volumes: - .:/srv/app/ - command: /srv/app/run_tests.sh + command: ./docker/run_tests.sh environment: - GIT_COMMITTED_AT - CC_TEST_REPORTER_ID @@ -20,7 +20,7 @@ services: dockerfile: Dockerfile.base volumes: - .:/srv/app/ - command: ./run_dev.sh + command: ./docker/run_dev.sh ports: - "8000:8000" environment: diff --git a/run_dev.sh b/docker/run_dev.sh similarity index 100% rename from run_dev.sh rename to docker/run_dev.sh diff --git a/run_tests.sh b/docker/run_tests.sh similarity index 100% rename from run_tests.sh rename to docker/run_tests.sh From d8c63d0c3d6ff1e7a111725adb566b9539976c80 Mon Sep 17 00:00:00 2001 From: Christian Duvholt Date: Mon, 9 Apr 2018 23:01:24 +0200 Subject: [PATCH 08/14] Add dockerfile for production using uwsgi --- Dockerfile.base | 3 +-- Dockerfile.prod | 4 ++++ docker-compose.yml | 21 +++++++++++++++++++++ docker/run_production.sh | 4 ++++ uwsgi.ini | 7 +++++++ 5 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 Dockerfile.prod create mode 100755 docker/run_production.sh create mode 100644 uwsgi.ini diff --git a/Dockerfile.base b/Dockerfile.base index 4820741..fe243ae 100644 --- a/Dockerfile.base +++ b/Dockerfile.base @@ -5,9 +5,8 @@ ENV APP_DIR=/srv/app RUN mkdir -p $APP_DIR WORKDIR $APP_DIR -RUN apk add --update --no-cache git build-base python-dev py-pip jpeg-dev zlib-dev +RUN apk add --update --no-cache git build-base python3-dev py-pip jpeg-dev zlib-dev ENV LIBRARY_PATH=/lib:/usr/lib COPY requirements.txt . RUN pip install -r requirements.txt -EXPOSE 8000 diff --git a/Dockerfile.prod b/Dockerfile.prod new file mode 100644 index 0000000..28d05dc --- /dev/null +++ b/Dockerfile.prod @@ -0,0 +1,4 @@ +FROM kapina_base:latest + +RUN apk add --update --no-cache linux-headers +RUN pip install uwsgi diff --git a/docker-compose.yml b/docker-compose.yml index e9dff7d..6247be4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,7 @@ version: '3' services: base: + image: kapina_base:latest build: context: . dockerfile: Dockerfile.base @@ -30,3 +31,23 @@ services: - 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 diff --git a/docker/run_production.sh b/docker/run_production.sh new file mode 100755 index 0000000..9f32ef1 --- /dev/null +++ b/docker/run_production.sh @@ -0,0 +1,4 @@ +#!/bin/sh +python manage.py migrate +python manage.py collectstatic --no-input +uwsgi -i uwsgi.ini diff --git a/uwsgi.ini b/uwsgi.ini new file mode 100644 index 0000000..fa32db5 --- /dev/null +++ b/uwsgi.ini @@ -0,0 +1,7 @@ +[uwsgi] +module = app.wsgi:application +vacuum = True +master = True +http-socket = :8000 +static-map = /static=./staticfiles +static-map = /media=./mediafiles From 0359d21a1637b7328c7f6b0d41e8621be8fa2c14 Mon Sep 17 00:00:00 2001 From: Christian Duvholt Date: Mon, 9 Apr 2018 23:38:50 +0200 Subject: [PATCH 09/14] Optimize dockerfile size --- Dockerfile.base | 6 +++--- Dockerfile.prod | 3 +-- docker/run_dev.sh | 4 ++-- docker/run_production.sh | 4 ++-- uwsgi.ini | 1 + 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Dockerfile.base b/Dockerfile.base index fe243ae..9ee1681 100644 --- a/Dockerfile.base +++ b/Dockerfile.base @@ -1,12 +1,12 @@ -FROM python:3.5-alpine +FROM alpine:3.7 ENV APP_DIR=/srv/app RUN mkdir -p $APP_DIR WORKDIR $APP_DIR -RUN apk add --update --no-cache git build-base python3-dev py-pip jpeg-dev zlib-dev +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 pip install -r requirements.txt +RUN pip3 --no-cache-dir install -r requirements.txt diff --git a/Dockerfile.prod b/Dockerfile.prod index 28d05dc..1b255e5 100644 --- a/Dockerfile.prod +++ b/Dockerfile.prod @@ -1,4 +1,3 @@ FROM kapina_base:latest -RUN apk add --update --no-cache linux-headers -RUN pip install uwsgi +RUN apk add --update --no-cache uwsgi-python3 diff --git a/docker/run_dev.sh b/docker/run_dev.sh index 8ddb5c1..cef3595 100755 --- a/docker/run_dev.sh +++ b/docker/run_dev.sh @@ -1,3 +1,3 @@ #!/bin/sh -python manage.py migrate -python manage.py runserver 0.0.0.0:8000 +python3 manage.py migrate +python3 manage.py runserver 0.0.0.0:8000 diff --git a/docker/run_production.sh b/docker/run_production.sh index 9f32ef1..d5fa9ad 100755 --- a/docker/run_production.sh +++ b/docker/run_production.sh @@ -1,4 +1,4 @@ #!/bin/sh -python manage.py migrate -python manage.py collectstatic --no-input +python3 manage.py migrate +python3 manage.py collectstatic --no-input uwsgi -i uwsgi.ini diff --git a/uwsgi.ini b/uwsgi.ini index fa32db5..4bb4090 100644 --- a/uwsgi.ini +++ b/uwsgi.ini @@ -5,3 +5,4 @@ master = True http-socket = :8000 static-map = /static=./staticfiles static-map = /media=./mediafiles +plugins = python3 From 974c839f23efd503df77106830a09dca014fa0e7 Mon Sep 17 00:00:00 2001 From: Christian Duvholt Date: Mon, 16 Apr 2018 18:52:01 +0200 Subject: [PATCH 10/14] Use multi-stage Docker builds --- Dockerfile | 15 +++++++++++++++ Dockerfile.base | 12 ------------ Dockerfile.prod | 3 --- docker-compose.yml | 18 +++++++----------- 4 files changed, 22 insertions(+), 26 deletions(-) create mode 100644 Dockerfile delete mode 100644 Dockerfile.base delete mode 100644 Dockerfile.prod diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..62f194b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM alpine:3.7 as base + +WORKDIR /srv/app + +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 + +FROM alpine:3.7 as production + +WORKDIR /srv/app +COPY --from=base /usr/lib/python3.6/site-packages /usr/lib/python3.6/site-packages +RUN apk add --update --no-cache uwsgi-python3 diff --git a/Dockerfile.base b/Dockerfile.base deleted file mode 100644 index 9ee1681..0000000 --- a/Dockerfile.base +++ /dev/null @@ -1,12 +0,0 @@ -FROM alpine:3.7 - -ENV APP_DIR=/srv/app - -RUN mkdir -p $APP_DIR -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 diff --git a/Dockerfile.prod b/Dockerfile.prod deleted file mode 100644 index 1b255e5..0000000 --- a/Dockerfile.prod +++ /dev/null @@ -1,3 +0,0 @@ -FROM kapina_base:latest - -RUN apk add --update --no-cache uwsgi-python3 diff --git a/docker-compose.yml b/docker-compose.yml index 6247be4..4217e71 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,14 +1,10 @@ -version: '3' +version: '3.6' services: - base: - image: kapina_base:latest - build: - context: . - dockerfile: Dockerfile.base test: build: context: . - dockerfile: Dockerfile.base + target: base + dockerfile: Dockerfile volumes: - .:/srv/app/ command: ./docker/run_tests.sh @@ -18,7 +14,8 @@ services: dev: build: context: . - dockerfile: Dockerfile.base + target: base + dockerfile: Dockerfile volumes: - .:/srv/app/ command: ./docker/run_dev.sh @@ -33,11 +30,10 @@ services: - REVOLT_RAVEN_DSN - DATABASE_URL production: - depends_on: - - base build: context: . - dockerfile: Dockerfile.prod + target: production + dockerfile: Dockerfile volumes: - .:/srv/app/ command: ./docker/run_production.sh From 40dcbe433691394847dbf1a08ebdac247e7c7684 Mon Sep 17 00:00:00 2001 From: Christian Duvholt Date: Mon, 16 Apr 2018 19:50:13 +0200 Subject: [PATCH 11/14] Create multi-stage builds for dev and test Also use wheel to copy packages --- Dockerfile | 37 ++++++++++++++++++++++++++++++++++--- docker-compose.yml | 7 ++----- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 62f194b..aa2bade 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,4 @@ +# Base FROM alpine:3.7 as base WORKDIR /srv/app @@ -6,10 +7,40 @@ RUN apk add --update --no-cache git gcc libc-dev python3 python3-dev jpeg-dev zl ENV LIBRARY_PATH=/lib:/usr/lib COPY requirements.txt . -RUN pip3 --no-cache-dir install -r requirements.txt +RUN pip3 install --no-cache-dir wheel && pip3 wheel -r requirements.txt --wheel-dir=/srv/wheels + +# Development +FROM alpine:3.7 as dev + +WORKDIR /srv/app +RUN apk add --update --no-cache python3 git jpeg zlib +COPY --from=base /srv/wheels /srv/wheels +COPY requirements.txt . +RUN pip3 install --no-index --no-cache-dir --find-links=/srv/wheels -r requirements.txt + +EXPOSE 8000 +CMD ["./docker/run_dev.sh"] + +# Testing +FROM alpine:3.7 as test + +WORKDIR /srv/app +RUN apk add --update --no-cache python3 git jpeg zlib +COPY --from=base /srv/wheels /srv/wheels +COPY requirements.txt . +RUN pip3 install --no-index --no-cache-dir --find-links=/srv/wheels -r requirements.txt + +CMD ["./docker/run_tests.sh"] + +# Production FROM alpine:3.7 as production WORKDIR /srv/app -COPY --from=base /usr/lib/python3.6/site-packages /usr/lib/python3.6/site-packages -RUN apk add --update --no-cache uwsgi-python3 +RUN apk add --update --no-cache python3 git jpeg zlib uwsgi-python3 +COPY --from=base /srv/wheels /srv/wheels +COPY requirements.txt . +RUN pip3 install --no-index --no-cache-dir --find-links=/srv/wheels -r requirements.txt + +EXPOSE 8000 +CMD ["./docker/run_production.sh"] diff --git a/docker-compose.yml b/docker-compose.yml index 4217e71..319f6dc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,22 +3,20 @@ services: test: build: context: . - target: base + target: test dockerfile: Dockerfile volumes: - .:/srv/app/ - command: ./docker/run_tests.sh environment: - GIT_COMMITTED_AT - CC_TEST_REPORTER_ID dev: build: context: . - target: base + target: dev dockerfile: Dockerfile volumes: - .:/srv/app/ - command: ./docker/run_dev.sh ports: - "8000:8000" environment: @@ -36,7 +34,6 @@ services: dockerfile: Dockerfile volumes: - .:/srv/app/ - command: ./docker/run_production.sh ports: - "8000:8000" environment: From a6e10a10df8d42fe5673f11a53febfddd1f2fcec Mon Sep 17 00:00:00 2001 From: Christian Duvholt Date: Mon, 16 Apr 2018 19:57:43 +0200 Subject: [PATCH 12/14] Split test requirements into new file --- Dockerfile | 2 ++ requirements-test.txt | 12 ++++++++++++ requirements.txt | 13 ------------- 3 files changed, 14 insertions(+), 13 deletions(-) create mode 100644 requirements-test.txt diff --git a/Dockerfile b/Dockerfile index aa2bade..11df5f6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,7 +29,9 @@ WORKDIR /srv/app RUN apk add --update --no-cache python3 git jpeg zlib COPY --from=base /srv/wheels /srv/wheels COPY requirements.txt . +COPY requirements-test.txt . RUN pip3 install --no-index --no-cache-dir --find-links=/srv/wheels -r requirements.txt +RUN pip3 install --no-cache-dir -r requirements-test.txt CMD ["./docker/run_tests.sh"] diff --git a/requirements-test.txt b/requirements-test.txt new file mode 100644 index 0000000..ca5ee38 --- /dev/null +++ b/requirements-test.txt @@ -0,0 +1,12 @@ +# Testing +pytest==3.4.1 +pytest-django==3.1.2 +snapshottest==0.5.0 + +# Coverage +pytest-cov==2.5.1 + +# Linting +yapf==0.20.2 +flake8==3.5.0 +isort==4.3.4 diff --git a/requirements.txt b/requirements.txt index b987eff..943d2bd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,16 +20,3 @@ python-decouple==3.1 # Error reporting raven==6.5.0 - -# Testing -pytest==3.4.1 -pytest-django==3.1.2 -snapshottest==0.5.0 - -# Coverage -pytest-cov==2.5.1 - -# Linting -yapf==0.20.2 -flake8==3.5.0 -isort==4.3.4 From 114922dc8ae9b0318b1e5771873c28023a74dcf0 Mon Sep 17 00:00:00 2001 From: Christian Duvholt Date: Mon, 16 Apr 2018 20:07:32 +0200 Subject: [PATCH 13/14] Downgrade docker-compose format to 3.4 Travis does not run latest docker-compose --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 319f6dc..1f207e6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,4 @@ -version: '3.6' +version: '3.4' services: test: build: From 500a74f31a0bf5d8417592e6d9e0c7198460236f Mon Sep 17 00:00:00 2001 From: Christian Duvholt Date: Mon, 16 Apr 2018 20:47:36 +0200 Subject: [PATCH 14/14] Add documentation about Docker in readme --- README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/README.md b/README.md index 7d85261..67da383 100644 --- a/README.md +++ b/README.md @@ -19,11 +19,27 @@ By default settings are configured for development and should just work, but som |REVOLT_SECRET_KEY|replace_this_secret_key|[See Django SECRET_KEY](https://docs.djangoproject.com/en/2.0/ref/settings/#std:setting-SECRET_KEY). **It is important that this is changed in production.** |REVOLT_RAVEN_DSN|(Empty)|Sentry DSN using this format: https://user:pass@sentry.io/project| +## Testing and linting + +The projects uses flake8, yapf, and isort to lint the project. + +The easiest way to run the tests is to use Docker: `docker-compose run test`. +Alternatively use the docker script: `./docker/run_tests.sh`. ## Setup - Development +### Docker + +To start the project using Docker run `docker-compose up dev` which runs on http://localhost:8000 +To update requirements run `docker-compose up --build dev`. +Migrations are automatically applied on start up. + +No further changes are needed to run the backend for development. + ### Virtualenv +To run the project without using Docker virtualenv is recommended. + ```bash pip install virtualenv virtualenv -p python3 venv @@ -56,6 +72,14 @@ python manage.py runserver ## Setup - Deployment +### Docker + +Docker can be used to run the backend in production. +It is configured to use uwsgi on port 800. +Staticfiles and mediafiles are served from local folders with the same name. + +Start the backend using `docker-compose up production`. + ### Nginx ```bash