From 922498114a60016a29bdf457e4725968195fe196 Mon Sep 17 00:00:00 2001 From: Johannes Christ Date: Thu, 16 Aug 2018 22:43:34 +0200 Subject: Make test user superuser. --- api/tests/base.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/api/tests/base.py b/api/tests/base.py index aa8157bc..06f7233c 100644 --- a/api/tests/base.py +++ b/api/tests/base.py @@ -3,9 +3,13 @@ from rest_framework.authtoken.models import Token from rest_framework.test import APIClient, APITestCase -test_user = User.objects.get(username='test') -if test_user is None: - test_user = User.objects.create_user('test', 'test@example.com', 'testpass') +test_user, _created = User.objects.get_or_create( + username='test', + email='test@example.com', + password='testpass', + is_superuser=True, + is_staff=True +) class APISubdomainTestCase(APITestCase): @@ -13,6 +17,12 @@ class APISubdomainTestCase(APITestCase): Configures the test client to use the proper subdomain for requests and forces authentication for the test user. + The test user is considered staff and superuser. + If you want to test for a custom user (for example, to test model permissions), + create the user, assign the relevant permissions, and use + `self.client.force_authenticate(user=created_user)` to force authentication + through the created user. + Using this performs the following niceties for you which ease writing tests: - setting the `HTTP_HOST` request header to `api.pythondiscord.local:8000`, and - forcing authentication for the test user. -- cgit v1.2.3 From d342c54fc2a04f58c83aa1131c7180a2995ada59 Mon Sep 17 00:00:00 2001 From: Johannes Christ Date: Mon, 27 Aug 2018 19:32:12 +0200 Subject: Update lockfile. --- Pipfile.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Pipfile.lock b/Pipfile.lock index 647516ac..628d072a 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -102,10 +102,10 @@ }, "bandit": { "hashes": [ - "sha256:cb977045497f83ec3a02616973ab845c829cdab8144ce2e757fe031104a9abd4", - "sha256:de4cc19d6ba32d6f542c6a1ddadb4404571347d83ef1ed1e7afb7d0b38e0c25b" + "sha256:45bf1b361004e861e5b423b36ff5c700d21442753c841013c87f14a4639b1d74", + "sha256:a3aa04802194ec1fd290849e02b915824f9c3234623d7dcea6a33b1605ddb0ac" ], - "version": "==1.4.0" + "version": "==1.5.0" }, "flake8": { "hashes": [ -- cgit v1.2.3 From 2d629a4aadda827984b5699a21611fe2fa134c35 Mon Sep 17 00:00:00 2001 From: Johannes Christ Date: Mon, 27 Aug 2018 19:32:19 +0200 Subject: Add a `Dockerfile`. --- Dockerfile | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..a4c8e73e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM python:3.7-alpine + +RUN apk add python3-dev git libpq postgresql-dev gcc cmake autoconf automake musl-dev +RUN python3 -m pip install pipenv + +ENV PIPENV_HIDE_EMOJIS=1 +ENV PIPENV_IGNORE_VIRTUALENVS=1 +ENV PIPENV_MAX_SUBPROCESS=2 +ENV PIPENV_NOSPIN=1 +ENV PIPENV_VENV_IN_PROJECT=1 + +COPY . /app +WORKDIR /app + +RUN pipenv install --deploy --system + +CMD ["gunicorn", "--workers", "4", "--bind", "0.0.0.0:4000", "pysite:wsgi"] \ No newline at end of file -- cgit v1.2.3 From fe844edc625d4110c44f4de6e6bda79cf1ef18fc Mon Sep 17 00:00:00 2001 From: Johannes Christ Date: Mon, 27 Aug 2018 19:36:59 +0200 Subject: Remove unused `libsass` dependency. --- Pipfile | 1 - Pipfile.lock | 24 +----------------------- 2 files changed, 1 insertion(+), 24 deletions(-) diff --git a/Pipfile b/Pipfile index 8a019869..b54539ca 100644 --- a/Pipfile +++ b/Pipfile @@ -17,7 +17,6 @@ djangorestframework = "*" "flake8-import-order" = "*" "flake8-tidy-imports" = "*" "flake8-string-format" = "*" -libsass = "*" [requires] python_version = "3.7" diff --git a/Pipfile.lock b/Pipfile.lock index 628d072a..528bb20a 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "8fee16876d03bf40515412046685b94bab4153c6e691e3837908cec81fa29689" + "sha256": "778f93720794c8cea0740eee96a5069e38ae2825830578964227c8ef085d8c8b" }, "pipfile-spec": 6, "requires": { @@ -176,28 +176,6 @@ ], "version": "==2.1.11" }, - "libsass": { - "hashes": [ - "sha256:0f2e421d3e5a53833243e0a5f2cf7ebe9812725a7f27a797c38f3c7190ce2a82", - "sha256:1b74aff85f1560d629a070552ec67f9f0ff9a47446ffafddafad9944f7589ae1", - "sha256:1cf80c04a77d36fd77f00b1ae0a269eee780d971fabd9d493b15d30de9857ae5", - "sha256:1d55dfe8e91a15a7d72d7f8aca16e74da36899e70d911af66d7184f1c82e2b39", - "sha256:23755425149fe0f576fd0ab7bcd151fe09400b2d980fe176c28f6c19e053c830", - "sha256:4a434d5b713b97c4141fb71c59341d4ebff8669114b14c626af51e145a48710e", - "sha256:4dcd5b546bed977276f97eb7a2a13cb7cbf0a38d672e7b5525b7587c8cabcf27", - "sha256:62771c8ead9227579891814dd714be645243741aa23e5cb232ac0c245cf29a37", - "sha256:727fb84326ffa930bc09fad8b706e77ada4d13b3adf35cce134962a434d7eccb", - "sha256:7b9e7179b5f4fc32bc716f86e9ccaeb48ab90e7eb6648b339440346733af8828", - "sha256:a0ffca466b35fb57f2afe1f1c5fd39b4c51a4107596d28ef8c0d3bb0962244b5", - "sha256:bb9735066391189b3c0383254d20d59aaafb438d632d7de551c264f16486e773", - "sha256:cbd5ee83d3603a2b2c2937d8f06acc07b30fd22642ea2460c966d4fd6217f1d0", - "sha256:de1eae502764b3dde294d6652a0046489cf31008de190c4dd8d05e7f4b5e0d71", - "sha256:e00b6c6d75a6e912990cbc23d48ddfdbfefc3e400c20be6593988839292248c5", - "sha256:ed8beef197efc6e6ab0ad03cea0885b31cc11f226290783649b4dafe1fb2ea27" - ], - "index": "pypi", - "version": "==0.14.5" - }, "mccabe": { "hashes": [ "sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42", -- cgit v1.2.3 From 4731804df24cf1c34ee275f56c372bd98c971f3c Mon Sep 17 00:00:00 2001 From: Johannes Christ Date: Mon, 27 Aug 2018 19:43:10 +0200 Subject: Add GitLab CI linting. --- .gitlab-ci.yml | 86 ++++++---------------------------------------------------- 1 file changed, 8 insertions(+), 78 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 144260ff..93253cc5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,78 +1,8 @@ -image: pythondiscord/site-ci:latest - -variables: - RABBITMQ_HOST: rabbit - RETHINKDB_HOST: rethinkdb - -stages: -# - build - - test -# - deploy -# -#build: -# before_script: -# - docker info -# -# image: docker:stable-git -# -# only: -# - master -# -# services: -# - docker:dind -# -# stage: build -# -# script: -# - sh scripts/deploy-ci.sh -# -# tags: -# - docker -# -# variables: -# DOCKER_DRIVER: overlay2 - -test: - tags: - - docker - - stage: test -# services: -# - name: rabbitmq:3.7.5-alpine -# alias: rabbit -# -# - name: rethinkdb:2.3.6 -# alias: rethinkdb - - cache: - paths: - - ".venv" - - ".gem" - - script: - - pipenv sync --dev - - - pipenv run lint -# - pipenv run lintjs -# - pipenv run lintscss -# -# - pipenv run python gunicorn_config.py -# - pipenv run test -# -#deploy: -# tags: -# - docker -# -# only: -# - master -# -# services: -# - docker:dind -# -# stage: deploy -# script: -# - sh scripts/deploy.sh -# -# environment: -# name: Production -# url: https://pythondiscord.com +build: + script: + - docker build -t "gitlab_pysite_$CI_JOB_ID" + +lint: + script: + - pipenv install --system --dev + - flake8 -- cgit v1.2.3 From 15b0ba27cfb8ce7c29711d809d58f56ea4be99ba Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Wed, 13 Jun 2018 13:19:49 +0100 Subject: Push site base image on CI. --- .gitlab-ci.yml | 7 ++++++- Dockerfile | 18 +----------------- docker/Dockerfile.base | 25 ------------------------- docker/base.Dockerfile | 17 +++++++++++++++++ docker/ci.Dockerfile | 23 ----------------------- scripts/deploy-ci.sh | 23 +++++++++++++++++++++++ 6 files changed, 47 insertions(+), 66 deletions(-) delete mode 100644 docker/Dockerfile.base create mode 100644 docker/base.Dockerfile delete mode 100644 docker/ci.Dockerfile create mode 100644 scripts/deploy-ci.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 93253cc5..7e026ce6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,8 +1,13 @@ build: + image: docker + tags: docker + only: + - master script: - - docker build -t "gitlab_pysite_$CI_JOB_ID" + - scripts/deploy-ci.sh lint: + image: pythondiscord/django-site-ci:latest script: - pipenv install --system --dev - flake8 diff --git a/Dockerfile b/Dockerfile index a4c8e73e..b62eb93d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1 @@ -FROM python:3.7-alpine - -RUN apk add python3-dev git libpq postgresql-dev gcc cmake autoconf automake musl-dev -RUN python3 -m pip install pipenv - -ENV PIPENV_HIDE_EMOJIS=1 -ENV PIPENV_IGNORE_VIRTUALENVS=1 -ENV PIPENV_MAX_SUBPROCESS=2 -ENV PIPENV_NOSPIN=1 -ENV PIPENV_VENV_IN_PROJECT=1 - -COPY . /app -WORKDIR /app - -RUN pipenv install --deploy --system - -CMD ["gunicorn", "--workers", "4", "--bind", "0.0.0.0:4000", "pysite:wsgi"] \ No newline at end of file +FROM pythondiscord/django-site-ci:latest diff --git a/docker/Dockerfile.base b/docker/Dockerfile.base deleted file mode 100644 index 7119d770..00000000 --- a/docker/Dockerfile.base +++ /dev/null @@ -1,25 +0,0 @@ -FROM python:3.6-alpine3.7 - -RUN apk add --update tini -RUN apk add --update git -RUN apk add --update build-base -RUN apk add --update gcc -RUN apk add --update cmake -RUN apk add --update autoconf -RUN apk add --update automake -RUN apk add --update libtool - -ENV PIPENV_VENV_IN_PROJECT=1 -ENV PIPENV_IGNORE_VIRTUALENVS=1 -ENV PIPENV_NOSPIN=1 -ENV PIPENV_HIDE_EMOJIS=1 - -RUN pip install pipenv - -RUN mkdir -p /site -COPY Pipfile /site -COPY Pipfile.lock /site -WORKDIR /site -ENV PYTHONPATH=/site - -RUN pipenv sync diff --git a/docker/base.Dockerfile b/docker/base.Dockerfile new file mode 100644 index 00000000..7252598d --- /dev/null +++ b/docker/base.Dockerfile @@ -0,0 +1,17 @@ +FROM python:3.7-alpine + +RUN apk add python3-dev git libpq postgresql-dev gcc cmake autoconf automake musl-dev +RUN python3 -m pip install pipenv + +ENV PIPENV_HIDE_EMOJIS=1 +ENV PIPENV_IGNORE_VIRTUALENVS=1 +ENV PIPENV_MAX_SUBPROCESS=2 +ENV PIPENV_NOSPIN=1 +ENV PIPENV_VENV_IN_PROJECT=1 + +COPY . /app +WORKDIR /app + +RUN pipenv install --deploy --system + +CMD ["gunicorn", "--workers", "4", "--bind", "0.0.0.0:4000", "pysite:wsgi"] diff --git a/docker/ci.Dockerfile b/docker/ci.Dockerfile deleted file mode 100644 index 0153696a..00000000 --- a/docker/ci.Dockerfile +++ /dev/null @@ -1,23 +0,0 @@ -FROM python:3.6-alpine3.7 - -# Install base packages -RUN apk add --update autoconf automake \ - build-base \ - cmake curl \ - docker \ - gcc git \ - libtool \ - nodejs nodejs-npm \ - ruby ruby-dev ruby-irb ruby-rdoc \ - tini - -# Set up env vars -ENV PIPENV_VENV_IN_PROJECT=1 -ENV PIPENV_IGNORE_VIRTUALENVS=1 -ENV PIPENV_NOSPIN=1 -ENV PIPENV_HIDE_EMOJIS=1 - -# Install toolchain -RUN pip install pipenv -RUN gem install scss_lint -RUN npm install -g eslint gulp-cli diff --git a/scripts/deploy-ci.sh b/scripts/deploy-ci.sh new file mode 100644 index 00000000..1bf8ce00 --- /dev/null +++ b/scripts/deploy-ci.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# Build and deploy on master branch +if [[ $CI_COMMIT_REF_SLUG == 'master' ]]; then + echo "Connecting to docker hub" + echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin + + changed_lines=$(git diff HEAD~1 HEAD docker/base.Dockerfile | wc -l) + + if [ $changed_lines != '0' ]; then + echo "base.Dockerfile was changed" + + echo "Building CI container" + docker build -t pythondiscord/django-site-ci:latest -f docker/base.Dockerfile . + + echo "Pushing image to Docker Hub" + docker push pythondiscord/django-site-ci:latest + else + echo "base.Dockerfile was not changed, not building" + fi +else + echo "Skipping CI Docker build" +fi -- cgit v1.2.3 From 5489bc670b936ee7732154e62688f085adfd5af8 Mon Sep 17 00:00:00 2001 From: Johannes Christ Date: Thu, 30 Aug 2018 19:35:24 +0200 Subject: Add CI build script. --- .gitlab-ci.yml | 13 ++++++++----- docker/base.Dockerfile | 1 + scripts/deploy-ci.sh | 24 ++++++++++-------------- 3 files changed, 19 insertions(+), 19 deletions(-) mode change 100644 => 100755 scripts/deploy-ci.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7e026ce6..fe86b32c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,10 +1,13 @@ -build: - image: docker - tags: docker +build base image: + image: docker:stable-git + script: + - sh scripts/deploy-ci.sh + tags: + - docker only: - master - script: - - scripts/deploy-ci.sh + - django + - django+add-gitlab-ci lint: image: pythondiscord/django-site-ci:latest diff --git a/docker/base.Dockerfile b/docker/base.Dockerfile index 7252598d..c90ee5dc 100644 --- a/docker/base.Dockerfile +++ b/docker/base.Dockerfile @@ -1,3 +1,4 @@ +# Base image used for building the site. FROM python:3.7-alpine RUN apk add python3-dev git libpq postgresql-dev gcc cmake autoconf automake musl-dev diff --git a/scripts/deploy-ci.sh b/scripts/deploy-ci.sh old mode 100644 new mode 100755 index 1bf8ce00..f5c965ca --- a/scripts/deploy-ci.sh +++ b/scripts/deploy-ci.sh @@ -1,23 +1,19 @@ #!/bin/bash # Build and deploy on master branch -if [[ $CI_COMMIT_REF_SLUG == 'master' ]]; then - echo "Connecting to docker hub" - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin +echo "Connecting to docker hub" +echo "$GITLAB_DOCKER_PASSWORD" | docker login --username "$GITLAB_DOCKER_USERNAME" --password-stdin registry.gitlab.com - changed_lines=$(git diff HEAD~1 HEAD docker/base.Dockerfile | wc -l) +changed_lines=$(git diff HEAD~1 HEAD docker/base.Dockerfile | wc -l) - if [ $changed_lines != '0' ]; then - echo "base.Dockerfile was changed" +if [ $changed_lines != '0' ]; then + echo "base.Dockerfile was changed" - echo "Building CI container" - docker build -t pythondiscord/django-site-ci:latest -f docker/base.Dockerfile . + echo "Building CI container" + docker build -t registry.gitlab.com/python-discord/projects/site/django-base:latest -f docker/base.Dockerfile . - echo "Pushing image to Docker Hub" - docker push pythondiscord/django-site-ci:latest - else - echo "base.Dockerfile was not changed, not building" - fi + echo "Pushing image to GitLab registry" + docker push registry.gitlab.com/python-discord/projects/site/django-base:latest else - echo "Skipping CI Docker build" + echo "base.Dockerfile was not changed, not building" fi -- cgit v1.2.3 From 37ff9fe6cdc6fff84ccda6c5d610a521288d99ce Mon Sep 17 00:00:00 2001 From: Johannes Christ Date: Thu, 30 Aug 2018 20:02:09 +0200 Subject: Proeprly set up lint and test stages. --- .gitlab-ci.yml | 24 ++++++++++++++++++++++-- Dockerfile | 2 +- api/admin.py | 2 +- home/admin.py | 2 +- home/models.py | 2 +- home/views.py | 2 +- pysite/hosts.py | 8 ++++---- pysite/settings.py | 2 +- wiki/admin.py | 2 +- wiki/models.py | 2 +- wiki/tests.py | 2 +- wiki/views.py | 2 +- 12 files changed, 36 insertions(+), 16 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fe86b32c..c8bcb91e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,11 @@ +stages: + - build + - lint + - test + build base image: image: docker:stable-git + stage: build script: - sh scripts/deploy-ci.sh tags: @@ -10,7 +16,21 @@ build base image: - django+add-gitlab-ci lint: - image: pythondiscord/django-site-ci:latest + image: registry.gitlab.com/python-discord/projects/site/django-base:latest + stage: lint script: - - pipenv install --system --dev + - pipenv install --dev --system - flake8 + +test: + image: registry.gitlab.com/python-discord/projects/site/django-base:latest + stage: test + services: + - postgres:10-alpine + script: + - pipenv run manage.py test + variables: + DATABASE_URL: postgres://django:supersecret@postgres/pysite + POSTGRES_DB: pysite + POSTGRES_PASSWORD: supersecret + POSTGRES_USER: django diff --git a/Dockerfile b/Dockerfile index b62eb93d..c4489027 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1 +1 @@ -FROM pythondiscord/django-site-ci:latest +FROM registry.gitlab.com/python-discord/projects/site/django-base:latest diff --git a/api/admin.py b/api/admin.py index 8c38f3f3..4185d360 100644 --- a/api/admin.py +++ b/api/admin.py @@ -1,3 +1,3 @@ -from django.contrib import admin +# from django.contrib import admin # Register your models here. diff --git a/home/admin.py b/home/admin.py index 8c38f3f3..4185d360 100644 --- a/home/admin.py +++ b/home/admin.py @@ -1,3 +1,3 @@ -from django.contrib import admin +# from django.contrib import admin # Register your models here. diff --git a/home/models.py b/home/models.py index 71a83623..0b4331b3 100644 --- a/home/models.py +++ b/home/models.py @@ -1,3 +1,3 @@ -from django.db import models +# from django.db import models # Create your models here. diff --git a/home/views.py b/home/views.py index 91ea44a2..fd0e0449 100644 --- a/home/views.py +++ b/home/views.py @@ -1,3 +1,3 @@ -from django.shortcuts import render +# from django.shortcuts import render # Create your views here. diff --git a/pysite/hosts.py b/pysite/hosts.py index 827f49c3..67fc2451 100644 --- a/pysite/hosts.py +++ b/pysite/hosts.py @@ -4,10 +4,10 @@ from django_hosts import host, patterns host_patterns = patterns( '', # > | Subdomain | URL Module | Host entry name | - #host(r"admin", "admin", name="admin"), + # host(r"admin", "admin", name="admin"), host(r'api', 'api.urls', name='api'), - #host(r"staff", "staff", name="staff"), - #host(r"wiki", "wiki", name="wiki"), - #host(r"ws", "ws", name="ws"), + # host(r"staff", "staff", name="staff"), + # host(r"wiki", "wiki", name="wiki"), + # host(r"ws", "ws", name="ws"), host(r'.*', 'home.urls', name=settings.DEFAULT_HOST) ) diff --git a/pysite/settings.py b/pysite/settings.py index 3392426d..16235e09 100644 --- a/pysite/settings.py +++ b/pysite/settings.py @@ -11,7 +11,7 @@ https://docs.djangoproject.com/en/2.1/ref/settings/ """ import os -import sys +# import sys import environ diff --git a/wiki/admin.py b/wiki/admin.py index 8c38f3f3..4185d360 100644 --- a/wiki/admin.py +++ b/wiki/admin.py @@ -1,3 +1,3 @@ -from django.contrib import admin +# from django.contrib import admin # Register your models here. diff --git a/wiki/models.py b/wiki/models.py index 71a83623..0b4331b3 100644 --- a/wiki/models.py +++ b/wiki/models.py @@ -1,3 +1,3 @@ -from django.db import models +# from django.db import models # Create your models here. diff --git a/wiki/tests.py b/wiki/tests.py index 7ce503c2..a79ca8be 100644 --- a/wiki/tests.py +++ b/wiki/tests.py @@ -1,3 +1,3 @@ -from django.test import TestCase +# from django.test import TestCase # Create your tests here. diff --git a/wiki/views.py b/wiki/views.py index 91ea44a2..fd0e0449 100644 --- a/wiki/views.py +++ b/wiki/views.py @@ -1,3 +1,3 @@ -from django.shortcuts import render +# from django.shortcuts import render # Create your views here. -- cgit v1.2.3 From caca113e0b9a724899dde2158f0f4605d9c3f3e5 Mon Sep 17 00:00:00 2001 From: Johannes Christ Date: Thu, 30 Aug 2018 20:10:29 +0200 Subject: Use system Python interpreter. --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c8bcb91e..131e2089 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -28,7 +28,7 @@ test: services: - postgres:10-alpine script: - - pipenv run manage.py test + - python manage.py test variables: DATABASE_URL: postgres://django:supersecret@postgres/pysite POSTGRES_DB: pysite -- cgit v1.2.3 From 5087d128637f70e10879d1d9c3f8f7fd4673cc39 Mon Sep 17 00:00:00 2001 From: Johannes Christ Date: Thu, 30 Aug 2018 20:14:45 +0200 Subject: Properly configure Django project. --- .gitlab-ci.yml | 1 + SETUP.md | 1 - pysite/settings.py | 8 +++++--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 131e2089..b455fa0c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -28,6 +28,7 @@ test: services: - postgres:10-alpine script: + - python manage.py migrate - python manage.py test variables: DATABASE_URL: postgres://django:supersecret@postgres/pysite diff --git a/SETUP.md b/SETUP.md index 2a8c64e9..dd974338 100644 --- a/SETUP.md +++ b/SETUP.md @@ -6,7 +6,6 @@ - `psql -c 'CREATE DATABASE pysite OWNER pysite;'` - `echo 'DEBUG=1' >> .env` - `echo 'DATABASE_URL=postgres://pysite:@localhost/pysite' >> .env` -- `echo 'BOT_API_KEY=123456' >> .env` - `pipenv shell` - `python manage.py migrate` - `python manage.py runserver` diff --git a/pysite/settings.py b/pysite/settings.py index 16235e09..c7a21083 100644 --- a/pysite/settings.py +++ b/pysite/settings.py @@ -40,6 +40,11 @@ if DEBUG: 'wiki.pythondiscord.local' ] SECRET_KEY = "+_x00w3e94##2-qm-v(5&-x_@*l3t9zlir1etu+7$@4%!it2##" + +elif 'CI' in os.environ: + ALLOWED_HOSTS = ['*'] + SECRET_KEY = "{©ø¬½.Þ7&Ñ`Q^Kº*~¢j Date: Thu, 30 Aug 2018 20:40:19 +0200 Subject: Remove no longer needed conditional. --- .gitlab-ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b455fa0c..4b413115 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -13,7 +13,6 @@ build base image: only: - master - django - - django+add-gitlab-ci lint: image: registry.gitlab.com/python-discord/projects/site/django-base:latest -- cgit v1.2.3 From f7fadfd8e7800545ab89accf0f650f8d546d4350 Mon Sep 17 00:00:00 2001 From: Johannes Christ Date: Thu, 30 Aug 2018 21:23:35 +0200 Subject: Add coverage reports. --- .gitlab-ci.yml | 30 ++++++++++++++++++++++++++++-- Pipfile | 1 + Pipfile.lock | 39 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 67 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4b413115..cec84074 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,6 +2,7 @@ stages: - build - lint - test + - deploy build base image: image: docker:stable-git @@ -26,11 +27,36 @@ test: stage: test services: - postgres:10-alpine - script: + before_script: - python manage.py migrate - - python manage.py test + - pip install coverage + script: + - coverage run --source=api,home,pysite,wiki --branch manage.py test + after_script: + - coverage report + artifacts: + paths: + - .coverage variables: DATABASE_URL: postgres://django:supersecret@postgres/pysite POSTGRES_DB: pysite POSTGRES_PASSWORD: supersecret POSTGRES_USER: django + +pages: + stage: deploy + image: + dependencies: + - test + before_script: + - pip install coverage + script: + - coverage html --directory=public + artifacts: + paths: + - public + expire_in: 30 days + only: + - master + - django + - django+add-gitlab-ci diff --git a/Pipfile b/Pipfile index b54539ca..d3b340ab 100644 --- a/Pipfile +++ b/Pipfile @@ -17,6 +17,7 @@ djangorestframework = "*" "flake8-import-order" = "*" "flake8-tidy-imports" = "*" "flake8-string-format" = "*" +coverage = "*" [requires] python_version = "3.7" diff --git a/Pipfile.lock b/Pipfile.lock index 528bb20a..2feb2cb4 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "778f93720794c8cea0740eee96a5069e38ae2825830578964227c8ef085d8c8b" + "sha256": "cc8270991baaef694efa7678b651fb4a7b97274cd2acb0a8bd41b7291a1203b1" }, "pipfile-spec": 6, "requires": { @@ -107,6 +107,43 @@ ], "version": "==1.5.0" }, + "coverage": { + "hashes": [ + "sha256:03481e81d558d30d230bc12999e3edffe392d244349a90f4ef9b88425fac74ba", + "sha256:0b136648de27201056c1869a6c0d4e23f464750fd9a9ba9750b8336a244429ed", + "sha256:10a46017fef60e16694a30627319f38a2b9b52e90182dddb6e37dcdab0f4bf95", + "sha256:198626739a79b09fa0a2f06e083ffd12eb55449b5f8bfdbeed1df4910b2ca640", + "sha256:23d341cdd4a0371820eb2b0bd6b88f5003a7438bbedb33688cd33b8eae59affd", + "sha256:28b2191e7283f4f3568962e373b47ef7f0392993bb6660d079c62bd50fe9d162", + "sha256:2a5b73210bad5279ddb558d9a2bfedc7f4bf6ad7f3c988641d83c40293deaec1", + "sha256:2eb564bbf7816a9d68dd3369a510be3327f1c618d2357fa6b1216994c2e3d508", + "sha256:337ded681dd2ef9ca04ef5d93cfc87e52e09db2594c296b4a0a3662cb1b41249", + "sha256:3a2184c6d797a125dca8367878d3b9a178b6fdd05fdc2d35d758c3006a1cd694", + "sha256:3c79a6f7b95751cdebcd9037e4d06f8d5a9b60e4ed0cd231342aa8ad7124882a", + "sha256:3d72c20bd105022d29b14a7d628462ebdc61de2f303322c0212a054352f3b287", + "sha256:3eb42bf89a6be7deb64116dd1cc4b08171734d721e7a7e57ad64cc4ef29ed2f1", + "sha256:4635a184d0bbe537aa185a34193898eee409332a8ccb27eea36f262566585000", + "sha256:56e448f051a201c5ebbaa86a5efd0ca90d327204d8b059ab25ad0f35fbfd79f1", + "sha256:5a13ea7911ff5e1796b6d5e4fbbf6952381a611209b736d48e675c2756f3f74e", + "sha256:69bf008a06b76619d3c3f3b1983f5145c75a305a0fea513aca094cae5c40a8f5", + "sha256:6bc583dc18d5979dc0f6cec26a8603129de0304d5ae1f17e57a12834e7235062", + "sha256:701cd6093d63e6b8ad7009d8a92425428bc4d6e7ab8d75efbb665c806c1d79ba", + "sha256:7608a3dd5d73cb06c531b8925e0ef8d3de31fed2544a7de6c63960a1e73ea4bc", + "sha256:76ecd006d1d8f739430ec50cc872889af1f9c1b6b8f48e29941814b09b0fd3cc", + "sha256:7aa36d2b844a3e4a4b356708d79fd2c260281a7390d678a10b91ca595ddc9e99", + "sha256:7d3f553904b0c5c016d1dad058a7554c7ac4c91a789fca496e7d8347ad040653", + "sha256:7e1fe19bd6dce69d9fd159d8e4a80a8f52101380d5d3a4d374b6d3eae0e5de9c", + "sha256:8c3cb8c35ec4d9506979b4cf90ee9918bc2e49f84189d9bf5c36c0c1119c6558", + "sha256:9d6dd10d49e01571bf6e147d3b505141ffc093a06756c60b053a859cb2128b1f", + "sha256:be6cfcd8053d13f5f5eeb284aa8a814220c3da1b0078fa859011c7fffd86dab9", + "sha256:c1bb572fab8208c400adaf06a8133ac0712179a334c09224fb11393e920abcdd", + "sha256:de4418dadaa1c01d497e539210cb6baa015965526ff5afc078c57ca69160108d", + "sha256:e05cb4d9aad6233d67e0541caa7e511fa4047ed7750ec2510d466e806e0255d6", + "sha256:f3f501f345f24383c0000395b26b726e46758b71393267aeae0bd36f8b3ade80" + ], + "index": "pypi", + "version": "==4.5.1" + }, "flake8": { "hashes": [ "sha256:7253265f7abd8b313e3892944044a365e3f4ac3fcdcfb4298f55ee9ddf188ba0", -- cgit v1.2.3 From 2f252bc12c5ddb5acb3132b1bd851fd2dd641f03 Mon Sep 17 00:00:00 2001 From: Johannes Christ Date: Thu, 30 Aug 2018 21:54:42 +0200 Subject: Always upload cov reports, add pipenv cache. --- .gitlab-ci.yml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index cec84074..5389495a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,6 +4,13 @@ stages: - test - deploy +cache: + paths: + - .cache/ + +variables: + PIPENV_CACHE_DIR: "$CI_PROJECT_DIR/.cache" + build base image: image: docker:stable-git stage: build @@ -19,7 +26,7 @@ lint: image: registry.gitlab.com/python-discord/projects/site/django-base:latest stage: lint script: - - pipenv install --dev --system + - pipenv install --dev - flake8 test: @@ -56,7 +63,3 @@ pages: paths: - public expire_in: 30 days - only: - - master - - django - - django+add-gitlab-ci -- cgit v1.2.3 From 27c897045ba48922c5a25b6bd24bd7c96b00cdd4 Mon Sep 17 00:00:00 2001 From: Johannes Christ Date: Fri, 31 Aug 2018 23:21:53 +0200 Subject: Install `flake8` on system. --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5389495a..c6eaac3d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -26,7 +26,7 @@ lint: image: registry.gitlab.com/python-discord/projects/site/django-base:latest stage: lint script: - - pipenv install --dev + - pipenv install --dev --system - flake8 test: -- cgit v1.2.3