From f57942f2575dc26c9487688ded773a0abdab5c61 Mon Sep 17 00:00:00 2001 From: Christopher Baklid Date: Sun, 29 Apr 2018 20:03:50 +0200 Subject: pipenv and dockerfile (#62) pipenv and dockerfile --- scripts/deploy.py | 20 ++++++++++ scripts/deploy.sh | 18 +++++++++ scripts/vagrant_bootstrap.sh | 87 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 125 insertions(+) create mode 100644 scripts/deploy.py create mode 100644 scripts/deploy.sh create mode 100644 scripts/vagrant_bootstrap.sh (limited to 'scripts') diff --git a/scripts/deploy.py b/scripts/deploy.py new file mode 100644 index 00000000..20d8edd5 --- /dev/null +++ b/scripts/deploy.py @@ -0,0 +1,20 @@ +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.sh b/scripts/deploy.sh new file mode 100644 index 00000000..9bdff580 --- /dev/null +++ b/scripts/deploy.sh @@ -0,0 +1,18 @@ +#!/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/site:latest . + + echo "Pushing image" + docker push pythondiscord/site:latest + + echo "Deploying container" + pipenv run python scripts/deploy.py +else + echo "Skipping deploy" +fi diff --git a/scripts/vagrant_bootstrap.sh b/scripts/vagrant_bootstrap.sh new file mode 100644 index 00000000..307107d4 --- /dev/null +++ b/scripts/vagrant_bootstrap.sh @@ -0,0 +1,87 @@ +#!/bin/bash + +# Dependencies +apt-get update +apt-get install -y software-properties-common +apt-get install -y python-software-properties +apt-get install -y curl +apt-get install -y apt-transport-https +add-apt-repository -y ppa:jonathonf/python-3.6 +echo "deb http://download.rethinkdb.com/apt xenial main" | sudo tee /etc/apt/sources.list.d/rethinkdb.list +wget -qO- https://download.rethinkdb.com/apt/pubkey.gpg | sudo apt-key add - +apt-get update + +# Python3.6 +apt-get install -y python3.6 +apt-get install -y python3.6-dev +apt-get install -y build-essential +curl -s https://bootstrap.pypa.io/get-pip.py | python3.6 - +python3.6 -m pip install -r /vagrant/requirements.txt +python3.6 -m pip install -r /vagrant/requirements-ci.txt +python3.6 -m pip install gunicorn + +# RethinkDB +apt-get install -y rethinkdb + +tee /etc/rethinkdb/instances.d/rethinkdb.conf < Date: Mon, 30 Apr 2018 16:16:32 +0200 Subject: restructure docker --- .dockerignore | 1 + Dockerfile | 20 -------------------- Dockerfile.base | 20 -------------------- docker/Dockerfile | 21 +++++++++++++++++++++ docker/Dockerfile.base | 20 ++++++++++++++++++++ scripts/deploy.sh | 2 +- 6 files changed, 43 insertions(+), 41 deletions(-) delete mode 100644 Dockerfile delete mode 100644 Dockerfile.base create mode 100644 docker/Dockerfile create mode 100644 docker/Dockerfile.base (limited to 'scripts') diff --git a/.dockerignore b/.dockerignore index 797f4db4..210f85f9 100644 --- a/.dockerignore +++ b/.dockerignore @@ -12,3 +12,4 @@ Vagrantfile .coveragerc .gitignore .travis.yml +docker diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 3899084a..00000000 --- a/Dockerfile +++ /dev/null @@ -1,20 +0,0 @@ -FROM pythondiscord/site-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 . /site -WORKDIR /site -ENV PYTHONPATH=/site - -RUN pipenv clean -RUN pipenv sync - -EXPOSE 10012 - -ENTRYPOINT ["/sbin/tini", "--"] -CMD ["pipenv", "run", "start"] diff --git a/Dockerfile.base b/Dockerfile.base deleted file mode 100644 index c5234997..00000000 --- a/Dockerfile.base +++ /dev/null @@ -1,20 +0,0 @@ -FROM python:3.6-alpine - -RUN apk add --update tini -RUN apk add --update git -RUN apk add --update build-base - -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 /site -COPY Pipfile /site -COPY Pipfile.lock /site -WORKDIR /site -ENV PYTHONPATH=/site - -RUN pipenv sync diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 00000000..cb2b1b5f --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,21 @@ +FROM pythondiscord/site-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 + +RUN mkdir -p /site +COPY . /site +WORKDIR /site +ENV PYTHONPATH=/site + +RUN pipenv clean +RUN pipenv sync + +EXPOSE 10012 + +ENTRYPOINT ["/sbin/tini", "--"] +CMD ["pipenv", "run", "start"] diff --git a/docker/Dockerfile.base b/docker/Dockerfile.base new file mode 100644 index 00000000..87c6fd73 --- /dev/null +++ b/docker/Dockerfile.base @@ -0,0 +1,20 @@ +FROM python:3.6-alpine + +RUN apk add --update tini +RUN apk add --update git +RUN apk add --update build-base + +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/scripts/deploy.sh b/scripts/deploy.sh index 9bdff580..96723aa6 100644 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -6,7 +6,7 @@ if [[ $TRAVIS_BRANCH == 'master' && $TRAVIS_PULL_REQUEST == 'false' ]]; then echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin echo "Building image" - docker build -t pythondiscord/site:latest . + docker build -t pythondiscord/site:latest -f docker/Dockerfile . echo "Pushing image" docker push pythondiscord/site:latest -- cgit v1.2.3