Skip to content

Commit

Permalink
adds dockerfile that uses pipenv (#60)
Browse files Browse the repository at this point in the history
Dockerfile and new deploy flow that builds the container in travis
  • Loading branch information
Inveracity committed Apr 28, 2018
1 parent e3306b3 commit 54369f6
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 20 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.venv
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ branches:
only:
- "master"

sudo: required

services:
- docker

env:
global:
- PIPENV_VENV_IN_PROJECT=1
Expand All @@ -17,7 +22,7 @@ install:
script:
- pipenv run python -m flake8
after_success:
- pipenv run python deploy.py
- bash scripts/deploy.sh

cache: pip

Expand Down
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
7 changes: 7 additions & 0 deletions Dockerfile.base
Original file line number Diff line number Diff line change
@@ -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
19 changes: 0 additions & 19 deletions deploy.py

This file was deleted.

8 changes: 8 additions & 0 deletions scripts/deploy.py
Original file line number Diff line number Diff line change
@@ -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)
16 changes: 16 additions & 0 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 54369f6

Please sign in to comment.