From fe9efe6fc845380705b4c99ae861bf0c6bb1cd3a Mon Sep 17 00:00:00 2001 From: scragly <29337040+scragly@users.noreply.github.com> Date: Mon, 23 Sep 2019 17:01:21 +1000 Subject: Reformat indents, use Docker@2 task for azure instead of sh script. --- azure-pipelines.yml | 129 +++++++++++++++++++++++------------------------- scripts/deploy-azure.sh | 12 ----- 2 files changed, 63 insertions(+), 78 deletions(-) delete mode 100644 scripts/deploy-azure.sh diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 4dcad685c..0c47d2544 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -6,69 +6,66 @@ variables: PIPENV_NOSPIN: 1 jobs: -- job: test - displayName: 'Lint & Test' - - pool: - vmImage: ubuntu-16.04 - - variables: - PIPENV_CACHE_DIR: ".cache/pipenv" - PIP_CACHE_DIR: ".cache/pip" - PIP_SRC: ".cache/src" - - steps: - - script: | - sudo apt-get update - sudo apt-get install build-essential curl docker libffi-dev libfreetype6-dev libxml2 libxml2-dev libxslt1-dev zlib1g zlib1g-dev - displayName: 'Install base dependencies' - - - task: UsePythonVersion@0 - displayName: 'Set Python version' - inputs: - versionSpec: '3.7.x' - addToPath: true - - - script: sudo pip install pipenv - displayName: 'Install pipenv' - - - script: pipenv install --dev --deploy --system - displayName: 'Install project using pipenv' - - - script: python -m flake8 - displayName: 'Run linter' - - - script: BOT_API_KEY=foo BOT_TOKEN=bar WOLFRAM_API_KEY=baz python -m pytest --junitxml=junit.xml --cov=bot --cov-branch --cov-report=term --cov-report=xml tests - displayName: Run tests - - - task: PublishCodeCoverageResults@1 - displayName: 'Publish Coverage Results' - condition: succeededOrFailed() - inputs: - codeCoverageTool: Cobertura - summaryFileLocation: coverage.xml - - - task: PublishTestResults@2 - displayName: 'Publish Test Results' - condition: succeededOrFailed() - inputs: - testResultsFiles: junit.xml - testRunTitle: 'Bot Test results' - -- job: build - displayName: 'Build Containers' - dependsOn: 'test' - - steps: - - task: Docker@1 - displayName: 'Login: Docker Hub' - - inputs: - containerregistrytype: 'Container Registry' - dockerRegistryEndpoint: 'DockerHub' - command: 'login' - - - task: ShellScript@2 - displayName: 'Build and deploy containers' - inputs: - scriptPath: scripts/deploy-azure.sh + - job: test + displayName: 'Lint & Test' + + pool: + vmImage: ubuntu-16.04 + + variables: + PIPENV_CACHE_DIR: ".cache/pipenv" + PIP_CACHE_DIR: ".cache/pip" + PIP_SRC: ".cache/src" + + steps: + - script: | + sudo apt-get update + sudo apt-get install build-essential curl docker libffi-dev libfreetype6-dev libxml2 libxml2-dev libxslt1-dev zlib1g zlib1g-dev + displayName: 'Install base dependencies' + + - task: UsePythonVersion@0 + displayName: 'Set Python version' + inputs: + versionSpec: '3.7.x' + addToPath: true + + - script: sudo pip install pipenv + displayName: 'Install pipenv' + + - script: pipenv install --dev --deploy --system + displayName: 'Install project using pipenv' + + - script: python -m flake8 + displayName: 'Run linter' + + - script: BOT_API_KEY=foo BOT_TOKEN=bar WOLFRAM_API_KEY=baz python -m pytest --junitxml=junit.xml --cov=bot --cov-branch --cov-report=term --cov-report=xml tests + displayName: Run tests + + - task: PublishCodeCoverageResults@1 + displayName: 'Publish Coverage Results' + condition: succeededOrFailed() + inputs: + codeCoverageTool: Cobertura + summaryFileLocation: coverage.xml + + - task: PublishTestResults@2 + displayName: 'Publish Test Results' + condition: succeededOrFailed() + inputs: + testResultsFiles: junit.xml + testRunTitle: 'Bot Test results' + + - job: build + displayName: 'Build & Push Container' + dependsOn: 'test' + + steps: + - task: Docker@2 + displayName: 'Build & Push Container' + inputs: + containerRegistry: 'DockerHub' + repository: 'pythondiscord/bot' + command: 'buildAndPush' + Dockerfile: 'Dockerfile' + buildContext: '.' + tags: 'latest' diff --git a/scripts/deploy-azure.sh b/scripts/deploy-azure.sh deleted file mode 100644 index ed4b719e2..000000000 --- a/scripts/deploy-azure.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -cd .. - -# Build and deploy on master branch, only if not a pull request -if [[ ($BUILD_SOURCEBRANCHNAME == 'master') && ($SYSTEM_PULLREQUEST_PULLREQUESTID == '') ]]; then - echo "Building image" - docker build -t pythondiscord/bot:latest . - - echo "Pushing image" - docker push pythondiscord/bot:latest -fi -- cgit v1.2.3 From 6a2d6b973bd3c4db3f6cca5972dfc05c32b18be4 Mon Sep 17 00:00:00 2001 From: scragly <29337040+scragly@users.noreply.github.com> Date: Mon, 23 Sep 2019 18:57:28 +1000 Subject: Pin dependencies, pre-build `regex` pkg. --- .gitignore | 1 - Pipfile | 34 ++++++++++----------- Pipfile.lock | 2 +- wheels/regex-2019.8.19-cp37-cp37m-linux_x86_64.whl | Bin 0 -> 688982 bytes 4 files changed, 17 insertions(+), 20 deletions(-) create mode 100644 wheels/regex-2019.8.19-cp37-cp37m-linux_x86_64.whl diff --git a/.gitignore b/.gitignore index cda3aeb9f..261fa179f 100644 --- a/.gitignore +++ b/.gitignore @@ -20,7 +20,6 @@ lib64/ parts/ sdist/ var/ -wheels/ *.egg-info/ .installed.cfg *.egg diff --git a/Pipfile b/Pipfile index 33f44e9a6..990653f92 100644 --- a/Pipfile +++ b/Pipfile @@ -5,18 +5,18 @@ name = "pypi" [packages] discord-py = "~=1.2" -aiodns = "*" -logmatic-python = "*" -aiohttp = "*" -sphinx = "*" -markdownify = "*" -lxml = "*" -pyyaml = "*" -fuzzywuzzy = "*" -aio-pika = "*" -python-dateutil = "*" -deepdiff = "*" -requests = "*" +aiodns = "~=2.0" +logmatic-python = "~=0.1" +aiohttp = "~=3.5" +sphinx = "~=2.2" +markdownify = "~=0.4" +lxml = "~=4.4" +pyyaml = "~=5.1" +fuzzywuzzy = "~=0.17" +aio-pika = "~=6.1" +python-dateutil = "~=2.8" +deepdiff = "~=4.0" +requests = "~=2.22" more_itertools = "~=7.2" urllib3 = ">=1.24.2,<1.25" @@ -30,10 +30,10 @@ flake8-string-format = "~=0.2" flake8-tidy-imports = "~=2.0" flake8-todo = "~=0.7" pre-commit = "~=1.18" -safety = "*" -dodgy = "*" -pytest = "*" -pytest-cov = "*" +safety = "~=1.8" +dodgy = "~=0.1" +pytest = "~=5.1" +pytest-cov = "~=2.7" [requires] python_version = "3.7" @@ -46,5 +46,3 @@ build = "docker build -t pythondiscord/bot:latest -f docker/bot.Dockerfile ." push = "docker push pythondiscord/bot:latest" buildbase = "docker build -t pythondiscord/bot-base:latest -f docker/base.Dockerfile ." pushbase = "docker push pythondiscord/bot-base:latest" -buildci = "docker build -t pythondiscord/bot-ci:latest -f docker/ci.Dockerfile ." -pushci = "docker push pythondiscord/bot-ci:latest" diff --git a/Pipfile.lock b/Pipfile.lock index 7674acb26..58489c60e 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "d582b1e226b1ce675817161d9059352d8f303c1bc1646034a9e73673f6581d12" + "sha256": "6c2d9ea980f1dbe954237de6d173ffa9ba480aa5cf0a03c4d7840b0739d4e2fa" }, "pipfile-spec": 6, "requires": { diff --git a/wheels/regex-2019.8.19-cp37-cp37m-linux_x86_64.whl b/wheels/regex-2019.8.19-cp37-cp37m-linux_x86_64.whl new file mode 100644 index 000000000..0be4519fe Binary files /dev/null and b/wheels/regex-2019.8.19-cp37-cp37m-linux_x86_64.whl differ -- cgit v1.2.3 From 8755a93a2866f7a4b94e3e0493f07141f55d03b1 Mon Sep 17 00:00:00 2001 From: scragly <29337040+scragly@users.noreply.github.com> Date: Mon, 23 Sep 2019 20:07:15 +1000 Subject: Add a dev-only compose for new devs who don't have `site`. --- docker-compose.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..1c55482dc --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,28 @@ +# This docker compose is used for quick setups of the site and database which +# the bot project relies on for testing. Use it if you haven't got a +# ready-to-use site environment already setup. + +version: "3.7" + +services: + postgres: + image: postgres:11-alpine + ports: + - "127.0.0.1:7777:5432" + environment: + POSTGRES_DB: pysite + POSTGRES_PASSWORD: pysite + POSTGRES_USER: pysite + + web: + image: pythondiscord/site:latest + command: "./manage.py runserver 0.0.0.0:8000" + ports: + - "127.0.0.1:8000:8000" + depends_on: + - postgres + environment: + DATABASE_URL: postgres://pysite:pysite@postgres:5432/pysite + DEBUG: "true" + SECRET_KEY: suitable-for-development-only + STATIC_ROOT: /var/www/static -- cgit v1.2.3 From 5fdacedccb70b2f549439aaa709beb24e84737c1 Mon Sep 17 00:00:00 2001 From: scragly <29337040+scragly@users.noreply.github.com> Date: Mon, 23 Sep 2019 20:16:59 +1000 Subject: Remove unneeded Pipfile scripts and azure stages/vars. --- Dockerfile | 33 +++++++++++++-------------------- Pipfile | 4 +--- azure-pipelines.yml | 8 -------- docker/ci.Dockerfile | 20 -------------------- 4 files changed, 14 insertions(+), 51 deletions(-) delete mode 100644 docker/ci.Dockerfile diff --git a/Dockerfile b/Dockerfile index aa6333380..21a938c4f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,27 +1,20 @@ -FROM python:3.7-alpine3.7 +FROM python:3.7-slim -RUN apk add --no-cache \ - build-base \ - freetype-dev \ - git \ - jpeg-dev \ - libffi-dev \ - libxml2 \ - libxml2-dev \ - libxslt-dev \ - tini \ - zlib \ - zlib-dev - -ENV \ - LIBRARY_PATH=/lib:/usr/lib +# Set pip to have cleaner logs and no saved cache +ENV PIP_NO_CACHE_DIR=false \ + PIPENV_HIDE_EMOJIS=1 \ + PIPENV_IGNORE_VIRTUALENVS=1 \ + PIPENV_NOSPIN=1 +# Install pipenv RUN pip install -U pipenv +# Copy project files into working directory WORKDIR /bot -COPY . . +COPY docker . -RUN pipenv install --deploy --system +# Install project dependencies +RUN pipenv install --system --deploy -ENTRYPOINT ["/sbin/tini", "--"] -CMD ["python3", "-m", "bot"] +ENTRYPOINT ["python3"] +CMD ["-m", "bot"] diff --git a/Pipfile b/Pipfile index 990653f92..da46a536d 100644 --- a/Pipfile +++ b/Pipfile @@ -42,7 +42,5 @@ python_version = "3.7" start = "python -m bot" lint = "python -m flake8" precommit = "pre-commit install" -build = "docker build -t pythondiscord/bot:latest -f docker/bot.Dockerfile ." +build = "docker build -t pythondiscord/bot:latest -f Dockerfile ." push = "docker push pythondiscord/bot:latest" -buildbase = "docker build -t pythondiscord/bot-base:latest -f docker/base.Dockerfile ." -pushbase = "docker push pythondiscord/bot-base:latest" diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 0c47d2544..1adbd12ea 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -8,21 +8,13 @@ variables: jobs: - job: test displayName: 'Lint & Test' - pool: vmImage: ubuntu-16.04 variables: - PIPENV_CACHE_DIR: ".cache/pipenv" PIP_CACHE_DIR: ".cache/pip" - PIP_SRC: ".cache/src" steps: - - script: | - sudo apt-get update - sudo apt-get install build-essential curl docker libffi-dev libfreetype6-dev libxml2 libxml2-dev libxslt1-dev zlib1g zlib1g-dev - displayName: 'Install base dependencies' - - task: UsePythonVersion@0 displayName: 'Set Python version' inputs: diff --git a/docker/ci.Dockerfile b/docker/ci.Dockerfile deleted file mode 100644 index fd7e25239..000000000 --- a/docker/ci.Dockerfile +++ /dev/null @@ -1,20 +0,0 @@ -FROM python:3.6-alpine3.7 - -RUN apk add --update docker \ - curl \ - tini \ - build-base \ - libffi-dev \ - zlib \ - jpeg-dev \ - libxml2 libxml2-dev libxslt-dev \ - zlib-dev \ - freetype-dev - -RUN pip install pipenv - -ENV LIBRARY_PATH=/lib:/usr/lib -ENV PIPENV_VENV_IN_PROJECT=1 -ENV PIPENV_IGNORE_VIRTUALENVS=1 -ENV PIPENV_NOSPIN=1 -ENV PIPENV_HIDE_EMOJIS=1 -- cgit v1.2.3 From 4f11cbb706640fb459df9f3d7a737ea2a5b81e73 Mon Sep 17 00:00:00 2001 From: scragly <29337040+scragly@users.noreply.github.com> Date: Mon, 23 Sep 2019 22:19:22 +1000 Subject: Add docker build condition for CI. --- azure-pipelines.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 1adbd12ea..de454e5c4 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -50,6 +50,7 @@ jobs: - job: build displayName: 'Build & Push Container' dependsOn: 'test' + condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) steps: - task: Docker@2 -- cgit v1.2.3 From 0232db30bcd247a6218f853c5e1e6f7c19b5fbd5 Mon Sep 17 00:00:00 2001 From: scragly <29337040+scragly@users.noreply.github.com> Date: Mon, 23 Sep 2019 22:24:34 +1000 Subject: Fix random text mistake in Dockerfile. --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 21a938c4f..271c25050 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,7 @@ RUN pip install -U pipenv # Copy project files into working directory WORKDIR /bot -COPY docker . +COPY . . # Install project dependencies RUN pipenv install --system --deploy -- cgit v1.2.3 From 83ce5184a5f4edf40abeeb42214261450095aeff Mon Sep 17 00:00:00 2001 From: scragly <29337040+scragly@users.noreply.github.com> Date: Tue, 24 Sep 2019 14:45:24 +1000 Subject: Create default django admin user. --- docker-compose.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 1c55482dc..4b0dcff35 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,7 +16,9 @@ services: web: image: pythondiscord/site:latest - command: "./manage.py runserver 0.0.0.0:8000" + command: > + bash -c "echo \"from django.contrib.auth import get_user_model; User = get_user_model(); User.objects.create_superuser('admin', 'admin', 'admin') if not User.objects.filter(username='admin').exists() else print('Admin user already exists')\" | python manage.py shell + && ./manage.py runserver 0.0.0.0:8000" ports: - "127.0.0.1:8000:8000" depends_on: -- cgit v1.2.3 From cdcfabfb12ea6709b49c8509e6fa6627fb4e0220 Mon Sep 17 00:00:00 2001 From: scragly <29337040+scragly@users.noreply.github.com> Date: Wed, 25 Sep 2019 02:27:51 +1000 Subject: Remove regex wheel as dateparser is no longer used. --- wheels/regex-2019.8.19-cp37-cp37m-linux_x86_64.whl | Bin 688982 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 wheels/regex-2019.8.19-cp37-cp37m-linux_x86_64.whl diff --git a/wheels/regex-2019.8.19-cp37-cp37m-linux_x86_64.whl b/wheels/regex-2019.8.19-cp37-cp37m-linux_x86_64.whl deleted file mode 100644 index 0be4519fe..000000000 Binary files a/wheels/regex-2019.8.19-cp37-cp37m-linux_x86_64.whl and /dev/null differ -- cgit v1.2.3 From 5ab0f0d8690af02fbd0f014cad5227a350e2483f Mon Sep 17 00:00:00 2001 From: "S. Co1" Date: Tue, 24 Sep 2019 12:35:10 -0400 Subject: Fix reminders filter query Closes #445 --- bot/cogs/reminders.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/cogs/reminders.py b/bot/cogs/reminders.py index c37abf21e..6e91d2c06 100644 --- a/bot/cogs/reminders.py +++ b/bot/cogs/reminders.py @@ -146,7 +146,7 @@ class Reminders(Scheduler, Cog): active_reminders = await self.bot.api_client.get( 'bot/reminders', params={ - 'user__id': str(ctx.author.id) + 'author__id': str(ctx.author.id) } ) @@ -184,7 +184,7 @@ class Reminders(Scheduler, Cog): # Get all the user's reminders from the database. data = await self.bot.api_client.get( 'bot/reminders', - params={'user__id': str(ctx.author.id)} + params={'author__id': str(ctx.author.id)} ) now = datetime.utcnow() -- cgit v1.2.3 From d91beca91d2e58b1ca01ea9f5c9ac92185b0c193 Mon Sep 17 00:00:00 2001 From: scragly <29337040+scragly@users.noreply.github.com> Date: Wed, 25 Sep 2019 03:04:45 +1000 Subject: Remove unnecessary sudo for pipenv install. --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index de454e5c4..b5ecab83c 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -21,7 +21,7 @@ jobs: versionSpec: '3.7.x' addToPath: true - - script: sudo pip install pipenv + - script: pip install pipenv displayName: 'Install pipenv' - script: pipenv install --dev --deploy --system -- cgit v1.2.3