diff options
| -rw-r--r-- | .dockerignore | 1 | ||||
| -rw-r--r-- | .travis.yml | 7 | ||||
| -rw-r--r-- | Dockerfile | 16 | ||||
| -rw-r--r-- | Dockerfile.base | 7 | ||||
| -rw-r--r-- | deploy.py | 19 | ||||
| -rw-r--r-- | scripts/deploy.py | 8 | ||||
| -rw-r--r-- | scripts/deploy.sh | 16 | 
7 files changed, 54 insertions, 20 deletions
| diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..1d17dae13 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +.venv diff --git a/.travis.yml b/.travis.yml index 1522feb8d..4d70f870e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,11 @@ branches:    only:      - "master" +sudo: required + +services: +  - docker +  env:    global:      - PIPENV_VENV_IN_PROJECT=1 @@ -17,7 +22,7 @@ install:  script:    - pipenv run python -m flake8  after_success: -  - pipenv run python deploy.py +  - bash scripts/deploy.sh  cache: pip diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..cf53d2fb9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM pythondiscord/bot-base:latest + +ENV PIPENV_VENV_IN_PROJECT=1 +ENV PIPENV_IGNORE_VIRTUALENVS=1 +ENV PIPENV_NOSPIN=1 +ENV PIPENV_HIDE_EMOJIS=1 + +RUN pip install pipenv + +COPY . /bot +WORKDIR /bot + +RUN pipenv sync + +ENTRYPOINT ["/sbin/tini", "--"] +CMD ["pipenv", "run", "python", "-m", "bot"] diff --git a/Dockerfile.base b/Dockerfile.base new file mode 100644 index 000000000..b74be598e --- /dev/null +++ b/Dockerfile.base @@ -0,0 +1,7 @@ +FROM python:3.6-alpine + +RUN apk add --update tini +RUN apk add --update build-base +RUN apk add --update libffi-dev + +# usage: FROM pythondiscord/bot-base:latest diff --git a/deploy.py b/deploy.py deleted file mode 100644 index 853d2b0c5..000000000 --- a/deploy.py +++ /dev/null @@ -1,19 +0,0 @@ -import os - -import requests - -branch = os.environ.get("TRAVIS_BRANCH") -url = os.environ.get("AUTODEPLOY_WEBHOOK") -token = os.environ.get("AUTODEPLOY_TOKEN") -PR = os.environ.get("TRAVIS_PULL_REQUEST") - -print('branch:', branch) -print('is_pr:', PR) - -if branch == 'master' and PR == 'false': -    print("deploying..") -    result = requests.get(url=url, headers={'token': token}) -    print(result.text) - -else: -    print("skipping deploy") diff --git a/scripts/deploy.py b/scripts/deploy.py new file mode 100644 index 000000000..04f3e8229 --- /dev/null +++ b/scripts/deploy.py @@ -0,0 +1,8 @@ +import os + +import requests + +url = os.environ.get("AUTODEPLOY_WEBHOOK") +token = os.environ.get("AUTODEPLOY_TOKEN") +result = requests.get(url=url, headers={'token': token}) +print(result.text) diff --git a/scripts/deploy.sh b/scripts/deploy.sh new file mode 100644 index 000000000..98b9a9462 --- /dev/null +++ b/scripts/deploy.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# Build and deploy on master branch +if [[ $TRAVIS_BRANCH == 'master' && $TRAVIS_PULL_REQUEST == 'false' ]]; then +    echo "Connecting to docker hub" +    echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin + +    echo "Building image" +    docker build -t pythondiscord/bot:latest . + +    echo "Pushing image" +    docker push pythondiscord/bot:latest + +    echo "Deploying container" +    pipenv run python scripts/deploy.py +fi | 
