diff options
-rw-r--r-- | .gitlab-ci.yml | 10 | ||||
-rw-r--r-- | azure-pipelines.yml | 58 | ||||
-rw-r--r-- | bot/__main__.py | 2 | ||||
-rw-r--r-- | bot/cogs/help.py | 2 | ||||
-rw-r--r-- | bot/cogs/snekbox.py | 2 | ||||
-rw-r--r-- | bot/constants.py | 2 | ||||
-rw-r--r-- | config-default.yml | 2 | ||||
-rw-r--r-- | scripts/deploy-azure.sh | 31 |
8 files changed, 94 insertions, 15 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f7aee8165..44126ded9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -26,13 +26,3 @@ test: - python -m flake8 - ls /root/.cache/ -build: - tags: - - docker - - services: - - docker:dind - - stage: build - script: - - sh scripts/deploy.sh diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 000000000..fe7486a5c --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,58 @@ +# https://aka.ms/yaml + +variables: + ENV LIBRARY_PATH: /lib:/usr/lib + ENV PIPENV_HIDE_EMOJIS: 1 + ENV PIPENV_IGNORE_VIRTUALENVS: 1 + ENV PIPENV_NOSPIN: 1 + ENV PIPENV_VENV_IN_PROJECT: 1 + +jobs: +- job: test + displayName: 'Lint & Test' + + pool: + vmImage: 'Ubuntu 16.04' + + variables: + PIPENV_CACHE_DIR: ".cache/pipenv" + PIP_CACHE_DIR: ".cache/pip" + + steps: + - script: 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' + +- 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 + args: '$(AUTODEPLOY_TOKEN) $(AUTODEPLOY_WEBHOOK)' diff --git a/bot/__main__.py b/bot/__main__.py index 5e6c7f603..3c40a3243 100644 --- a/bot/__main__.py +++ b/bot/__main__.py @@ -12,7 +12,7 @@ from bot.utils.service_discovery import wait_for_rmq log = logging.getLogger(__name__) bot = Bot( - command_prefix=when_mentioned_or("!"), + command_prefix=when_mentioned_or(BotConfig.prefix), activity=Game(name="Commands: !help"), case_insensitive=True, max_messages=10_000 diff --git a/bot/cogs/help.py b/bot/cogs/help.py index f229fa00b..144286c56 100644 --- a/bot/cogs/help.py +++ b/bot/cogs/help.py @@ -424,7 +424,7 @@ class HelpSession: strikeout = '~~' signature = self._get_command_params(command) - prefix = constants.Bot.help_prefix + prefix = constants.Bot.prefix info = f"{strikeout}**`{prefix}{signature}`**{strikeout}" # handle if the command has no docstring diff --git a/bot/cogs/snekbox.py b/bot/cogs/snekbox.py index 184a7545d..1b51da843 100644 --- a/bot/cogs/snekbox.py +++ b/bot/cogs/snekbox.py @@ -184,7 +184,7 @@ class Snekbox: msg = f"{ctx.author.mention} Your eval job has completed.\n\n```py\n{output}\n```" response = await ctx.send(msg) - await wait_for_deletion(response, user_ids=(ctx.author.id,), client=ctx.bot) + self.bot.loop.create_task(wait_for_deletion(response, user_ids=(ctx.author.id,), client=ctx.bot)) else: await ctx.send( diff --git a/bot/constants.py b/bot/constants.py index e2303efb2..266bd5eee 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -191,7 +191,7 @@ class YAMLGetter(type): class Bot(metaclass=YAMLGetter): section = "bot" - help_prefix: str + prefix: str token: str diff --git a/config-default.yml b/config-default.yml index 4fb8884e8..3598caa45 100644 --- a/config-default.yml +++ b/config-default.yml @@ -1,5 +1,5 @@ bot: - help_prefix: "bot." + prefix: "!" token: !ENV "BOT_TOKEN" cooldowns: diff --git a/scripts/deploy-azure.sh b/scripts/deploy-azure.sh new file mode 100644 index 000000000..6b3dea508 --- /dev/null +++ b/scripts/deploy-azure.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +cd .. + +# Build and deploy on master branch, only if not a pull request +if [[ ($BUILD_SOURCEBRANCHNAME == 'master') && ($SYSTEM_PULLREQUEST_PULLREQUESTID == '') ]]; then + changed_lines=$(git diff HEAD~1 HEAD docker/base.Dockerfile | wc -l) + + if [ $changed_lines != '0' ]; then + echo "base.Dockerfile was changed" + + echo "Building bot base" + docker build -t pythondiscord/bot-base:latest -f docker/base.Dockerfile . + + echo "Pushing image to Docker Hub" + docker push pythondiscord/bot-base:latest + else + echo "base.Dockerfile was not changed, not building" + fi + + echo "Building image" + docker build -t pythondiscord/bot:latest -f docker/bot.Dockerfile . + + echo "Pushing image" + docker push pythondiscord/bot:latest + + echo "Deploying container" + curl -H "token: $1" $2 +else + echo "Skipping deploy" +fi
\ No newline at end of file |