diff options
-rw-r--r-- | .gitlab-ci.yml | 131 | ||||
-rw-r--r-- | Dockerfile | 18 | ||||
-rw-r--r-- | Pipfile | 2 | ||||
-rw-r--r-- | Pipfile.lock | 61 | ||||
-rw-r--r-- | SETUP.md | 1 | ||||
-rw-r--r-- | api/admin.py | 2 | ||||
-rw-r--r-- | docker/Dockerfile.base | 25 | ||||
-rw-r--r-- | docker/base.Dockerfile | 18 | ||||
-rw-r--r-- | docker/ci.Dockerfile | 23 | ||||
-rw-r--r-- | home/admin.py | 2 | ||||
-rw-r--r-- | home/models.py | 2 | ||||
-rw-r--r-- | home/views.py | 2 | ||||
-rw-r--r-- | pysite/hosts.py | 8 | ||||
-rw-r--r-- | pysite/settings.py | 10 | ||||
-rwxr-xr-x | scripts/deploy-ci.sh | 19 | ||||
-rw-r--r-- | wiki/admin.py | 2 | ||||
-rw-r--r-- | wiki/models.py | 2 | ||||
-rw-r--r-- | wiki/tests.py | 2 | ||||
-rw-r--r-- | wiki/views.py | 2 |
19 files changed, 154 insertions, 178 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 144260ff..5389495a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,78 +1,65 @@ -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 + - build + - lint + - test + - deploy -test: - tags: - - docker +cache: + paths: + - .cache/ - stage: test -# services: -# - name: rabbitmq:3.7.5-alpine -# alias: rabbit -# -# - name: rethinkdb:2.3.6 -# alias: rethinkdb +variables: + PIPENV_CACHE_DIR: "$CI_PROJECT_DIR/.cache" - cache: - paths: - - ".venv" - - ".gem" +build base image: + image: docker:stable-git + stage: build + script: + - sh scripts/deploy-ci.sh + tags: + - docker + only: + - master + - django - script: - - pipenv sync --dev +lint: + image: registry.gitlab.com/python-discord/projects/site/django-base:latest + stage: lint + script: + - pipenv install --dev + - flake8 + +test: + image: registry.gitlab.com/python-discord/projects/site/django-base:latest + stage: test + services: + - postgres:10-alpine + before_script: + - python manage.py migrate + - 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 - - 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 +pages: + stage: deploy + image: + dependencies: + - test + before_script: + - pip install coverage + script: + - coverage html --directory=public + artifacts: + paths: + - public + expire_in: 30 days @@ -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 registry.gitlab.com/python-discord/projects/site/django-base:latest @@ -17,7 +17,7 @@ djangorestframework = "*" "flake8-import-order" = "*" "flake8-tidy-imports" = "*" "flake8-string-format" = "*" -libsass = "*" +coverage = "*" [requires] python_version = "3.7" diff --git a/Pipfile.lock b/Pipfile.lock index 628d072a..2feb2cb4 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "8fee16876d03bf40515412046685b94bab4153c6e691e3837908cec81fa29689" + "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", @@ -176,28 +213,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", @@ -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/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/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..c90ee5dc --- /dev/null +++ b/docker/base.Dockerfile @@ -0,0 +1,18 @@ +# 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 +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/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..c7a21083 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 @@ -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<wxß¾±ðÛJ@q" + else: ALLOWED_HOSTS = [ 'pythondiscord.com', @@ -175,6 +180,3 @@ REST_FRAMEWORK = { ), 'TEST_REQUEST_DEFAULT_FORMAT': 'json' } - -# Bot API settings -BOT_API_KEY = env('BOT_API_KEY') diff --git a/scripts/deploy-ci.sh b/scripts/deploy-ci.sh new file mode 100755 index 00000000..f5c965ca --- /dev/null +++ b/scripts/deploy-ci.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# Build and deploy on master branch +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) + +if [ $changed_lines != '0' ]; then + echo "base.Dockerfile was changed" + + 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 GitLab registry" + docker push registry.gitlab.com/python-discord/projects/site/django-base:latest +else + echo "base.Dockerfile was not changed, not building" +fi 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. |