From 0202dc6b041eca73665c8516276d45e74fd9f6a0 Mon Sep 17 00:00:00 2001 From: Jayden Bailey Date: Sun, 14 Jan 2018 16:40:01 +0000 Subject: [PATCH] :whale: changes to allow the bot to work on Docker --- .travis.yml | 25 +++++++++++++++++++++++++ .travis/install.sh | 22 ++++++++++++++++++++++ Dockerfile | 2 ++ run.py | 6 +++++- 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 .travis.yml create mode 100755 .travis/install.sh diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..37a338815 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,25 @@ +sudo: required +language: python + +matrix: + include: + - env: TYPE=docker + sudo: required + - env: TYPE=build + os: linux + python: 3.5 + dist: trusty + sudo: required + +services: +- docker + +install: +- if [ "$TYPE" = "build" ]; then ./.travis/install.sh; fi; + +script: +- if [ "$TYPE" = "docker" ]; then docker build -t musicbot .; docker images -a; fi; +- if [ "$TYPE" = "build" ]; then python -m compileall ./musicbot; fi; + +after_success: +- if [ "$TRAVIS_BRANCH" == "master" ]; then docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASS"; docker tag musicbot $DOCKER_USERNAME/musicbot ; docker push $DOCKER_USERNAME/musicbot; fi; \ No newline at end of file diff --git a/.travis/install.sh b/.travis/install.sh new file mode 100755 index 000000000..125de4d1f --- /dev/null +++ b/.travis/install.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +if [[ $TRAVIS_OS_NAME == 'osx' ]]; then + brew install git + brew install ffmpeg + brew install opus + brew install libffi + brew install libsodium + python3 -m pip install -U pip + python3 -m pip install -U -r requirements.txt +else + sudo apt-get install build-essential unzip -y + sudo apt-get install software-properties-common -y + sudo add-apt-repository ppa:deadsnakes -y + sudo add-apt-repository ppa:mc3man/trusty-media -y + sudo add-apt-repository ppa:chris-lea/libsodium -y + sudo apt-get update -y + sudo apt-get install git python3.5-dev libav-tools libopus-dev libffi-dev libsodium-dev python3-pip -y + sudo apt-get upgrade -y + sudo python3 -m pip install -U pip + sudo python3 -m pip install -U -r requirements.txt +fi \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 4d6bbaace..71cc5e5a5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,4 +32,6 @@ RUN apk update \ # Create volume for mapping the config VOLUME /usr/src/musicbot/config +ENV APP_ENV=docker + ENTRYPOINT ["python3", "run.py"] \ No newline at end of file diff --git a/run.py b/run.py index 75e19a536..11a03d36f 100755 --- a/run.py +++ b/run.py @@ -9,6 +9,7 @@ import subprocess from shutil import disk_usage, rmtree +from base64 import b64decode try: import pathlib @@ -276,10 +277,13 @@ def req_ensure_encoding(): def req_ensure_env(): log.info("Ensuring we're in the right environment") + if os.environ.get('APP_ENV') != 'docker' and not os.path.isdir(b64decode('LmdpdA==').decode('utf-8')): + log.critical(b64decode('Qm90IHdhc24ndCBpbnN0YWxsZWQgdXNpbmcgR2l0LiBSZWluc3RhbGwgdXNpbmcgaHR0cDovL2JpdC5seS9tdXNpY2JvdGRvY3Mu').decode('utf-8')) + bugger_off() + try: assert os.path.isdir('config'), 'folder "config" not found' assert os.path.isdir('musicbot'), 'folder "musicbot" not found' - assert os.path.isdir('.git'), 'bot was not installed using Git. If you downloaded a ZIP, you did it wrong. Open http://bit.ly/dmbguide on your browser for official install steps.' assert os.path.isfile('musicbot/__init__.py'), 'musicbot folder is not a Python module' assert importlib.util.find_spec('musicbot'), "musicbot module is not importable"