From 4aadd886d5b5cd52ac83e3b20bf997ede3b4f55d Mon Sep 17 00:00:00 2001 From: Joshua Arulsamy Date: Sun, 9 Aug 2020 20:12:31 -0600 Subject: [PATCH 1/7] :pencil: Format fixes --- README.md | 126 +++++++++++++++++++++++++----------------------------- 1 file changed, 59 insertions(+), 67 deletions(-) diff --git a/README.md b/README.md index 4caba35..8580acf 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![GPLv3 license](https://img.shields.io/badge/License-GPLv3-blue.svg)](http://perso.crans.org/besson/LICENSE.html) ![docker pulls](https://img.shields.io/docker/pulls/jarulsamy/plex-bot) ![docker img size](https://img.shields.io/docker/image-size/jarulsamy/plex-bot) -Code style: black +![black badge](https://img.shields.io/badge/code%20style-black-000000.svg) A Python-based Plex music bot for discord. @@ -13,106 +13,105 @@ A Python-based Plex music bot for discord. Plex-Bot runs entirely in a Docker container. Ensure you have Docker and docker-compose installed according to the official Docker [documentation](https://docs.docker.com/get-docker/). -1. Create a new folder and `cd` into it: +1. Create a new folder and `cd` into it: -``` -$ mkdir Plex-Bot -$ cd Plex-Bot -``` + ```bash + mkdir Plex-Bot + cd Plex-Bot + ``` -2. Make a `docker-compose.yml` file or use this sample: +2. Make a `docker-compose.yml` file or use this sample: -```yml -version: "3" -services: - plex-bot: - container_name: "PlexBot" - image: jarulsamy/plex-bot:latest - environment: - - PUID=1000 - - PGID=1000 - - TZ=America/Denver - # Required dir for configuration files - volumes: - - "./config:/config:ro" - restart: "unless-stopped" -``` + ```yml + version: "3" + services: + plex-bot: + container_name: "PlexBot" + image: jarulsamy/plex-bot:latest + environment: + - PUID=1000 + - PGID=1000 + - TZ=America/Denver + # Required dir for configuration files + volumes: + - "./config:/config:ro" + restart: "unless-stopped" + ``` -3. Create a configuration folder: +3. Create a new `config` folder and create a config file like this:: -Create a new `config` folder and create a config file like this: + ```bash + mkdir config + cd config + touch config.yaml + ``` -``` -$ mkdir config -$ cd config -``` + ```yml + # Create a file called config.yaml with the following contents -```yml -# Create a file called config.yaml with the following contents + root: + log_level: "info" -root: - log_level: "info" + discord: + prefix: "?" + token: "" + log_level: "debug" -discord: - prefix: "?" - token: "" - log_level: "debug" + plex: + base_url: "" + token: "" + library_name: "" + log_level: "debug" + ``` -plex: - base_url: "" - token: "" - library_name: "" - log_level: "debug" -``` +4. Create a Discord bot application: -4. Create a Discord bot application: + 1. Go to the Discord developer portal, [here](https://discord.com/developers/applications). - * Go to the Discord developer portal, [here](https://discord.com/developers/applications). + 2. Log in or create an account - * Log in or create an account + 3. Click New App - * Click New App + 4. Fill in App Name and anything else you'd like to include - * Fill in App Name and anything else you'd like to include - - * Click Create App + 5. Click Create App This will provide you with your Client ID and Client Secret - * Click Create Bot User + 6. Click Create Bot User This will provide you with your bot Username and Token - * Fill in the bot token in `config/config.yaml` + 7. Fill in the bot token in `config/config.yaml` -5. Get your plex token: +5. Get your plex token: * Refer to the official [plex documentation](https://support.plex.tv/articles/204059436-finding-an-authentication-token-x-plex-token/). * Add it to `config/config.yaml` in the appropiate spot. -6. Customize remaining settings +6. Customize remaining settings Set any remaining settings in the config file that you would like. Such as music library, and base url of the Plex server. 7. Start the service: -``` -$ docker-compose up -d -``` + ```bash + docker-compose up -d + ``` ## Logs You can view the logs with the following command -``` -$ docker-compose logs -f CONTAINER_NAME_OR_ID +```bash +docker-compose logs -f CONTAINER_NAME_OR_ID # For example -$ docker-compose logs -f PlexBot +docker-compose logs -f PlexBot ``` ## Usage -``` +```text General: kill - Stop the bot. Plex: @@ -129,11 +128,4 @@ Type ?help command for more info on a command. You can also type ?help category for more info on a category. ``` -## Support - -Reach out to me at one of the following places! - -- Email (Best) at joshua.gf.arul@gmail.com -- Twitter at `@jarulsamy_` - * * * From b7ab589f6e17952bf2ad38d12c14ca42aaefd75e Mon Sep 17 00:00:00 2001 From: Joshua Arulsamy Date: Mon, 10 Aug 2020 02:16:11 -0600 Subject: [PATCH 2/7] :art: Switch to shell scripts for deployment --- PlexBot/__version__.py | 7 +++++-- deploy/build.py | 8 -------- deploy/build.sh | 14 ++++++++++++++ deploy/push.py | 8 -------- deploy/push.sh | 14 ++++++++++++++ 5 files changed, 33 insertions(+), 18 deletions(-) delete mode 100644 deploy/build.py create mode 100755 deploy/build.sh delete mode 100755 deploy/push.py create mode 100755 deploy/push.sh diff --git a/PlexBot/__version__.py b/PlexBot/__version__.py index e2acb55..8f25dfd 100644 --- a/PlexBot/__version__.py +++ b/PlexBot/__version__.py @@ -1,2 +1,5 @@ -"""Track version number of package""" -VERSION = "0.0.6" +"""Track version number of package.""" +VERSION = "0.0.7" + +if __name__ == "__main__": + print(VERSION) diff --git a/deploy/build.py b/deploy/build.py deleted file mode 100644 index 78c9326..0000000 --- a/deploy/build.py +++ /dev/null @@ -1,8 +0,0 @@ -import os -import sys - -sys.path.append("PlexBot") - -from __version__ import VERSION - -sys.exit(os.system(f"docker build -t jarulsamy/plex-bot:{VERSION} .")) diff --git a/deploy/build.sh b/deploy/build.sh new file mode 100755 index 0000000..9fe1c36 --- /dev/null +++ b/deploy/build.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +VERSION=$(python PlexBot/__version__.py) + +docker build -t "jarulsamy/plex-bot:$VERSION" . + +if [ $? -eq 0 ] +then + echo "Successfully build docker image." + exit 0 +else + echo "Failed to build docker image." >&2 + exit 1 +fi diff --git a/deploy/push.py b/deploy/push.py deleted file mode 100755 index 98fc956..0000000 --- a/deploy/push.py +++ /dev/null @@ -1,8 +0,0 @@ -import os -import sys - -sys.path.append("PlexBot") - -from __version__ import VERSION - -sys.exit(os.system(f"docker push jarulsamy/plex-bot:{VERSION}")) diff --git a/deploy/push.sh b/deploy/push.sh new file mode 100755 index 0000000..ce37735 --- /dev/null +++ b/deploy/push.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +VERSION=$(python PlexBot/__version__.py) + +docker push "jarulsamy/plex-bot:$VERSION" + +if [ $? -eq 0 ] +then + echo "Successfully pushed docker image." + exit 0 +else + echo "Failed to push docker image." >&2 + exit 1 +fi From 98a36c6cbc1a8520c3a06082f6ada22d75961ae0 Mon Sep 17 00:00:00 2001 From: Joshua Arulsamy Date: Mon, 10 Aug 2020 02:18:06 -0600 Subject: [PATCH 3/7] :bug: Update to support shell scripts for deploy --- Jenkinsfile | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index b08e77a..3968490 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -49,16 +49,12 @@ pipeline { steps { sh ''' source /var/lib/jenkins/miniconda3/etc/profile.d/conda.sh conda activate ${BUILD_TAG} - python deploy/build.py + ./deploy/build.sh ''' } post { always { - // Archive unit tests for the future - archiveArtifacts (allowEmptyArchive: true, - artifacts: 'dist/*whl', - fingerprint: true) - sh 'python deploy/push.py' + sh './deploy/push.sh' } } } From 463324700444c5de1775f94ffd2cbd6d233ef481 Mon Sep 17 00:00:00 2001 From: Joshua Arulsamy Date: Mon, 10 Aug 2020 02:25:33 -0600 Subject: [PATCH 4/7] :bug: Cleaner builds, allow some compilation --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 65c00a5..827024d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,7 @@ WORKDIR /src COPY requirements.txt . # Install all dependencies. -RUN pip install --only-binary all --no-cache-dir -r requirements.txt +RUN pip install --no-cache-dir -r requirements.txt # Copy PlexBot over to src. COPY PlexBot/ PlexBot From 7471da85f7dc8da2f5cc15b0027389940f0af936 Mon Sep 17 00:00:00 2001 From: Joshua Arulsamy Date: Mon, 10 Aug 2020 02:25:48 -0600 Subject: [PATCH 5/7] :sparkles: Seperate field for pushing package --- Jenkinsfile | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 3968490..e844538 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -52,11 +52,16 @@ pipeline { ./deploy/build.sh ''' } - post { - always { - sh './deploy/push.sh' + } + stage('Push Image') { + when { + expression { + currentBuild.result == 'SUCCESS' } } + steps { + sh './deploy/push.sh' + } } } From ed1a64cb529cb43233ab3bd8900fae613ea2bb6c Mon Sep 17 00:00:00 2001 From: Joshua Arulsamy Date: Mon, 10 Aug 2020 02:26:38 -0600 Subject: [PATCH 6/7] :art: Fix style of docstrings --- PlexBot/__init__.py | 8 ++++---- PlexBot/__main__.py | 7 +++---- PlexBot/bot.py | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/PlexBot/__init__.py b/PlexBot/__init__.py index 9faccea..bfc5f1e 100644 --- a/PlexBot/__init__.py +++ b/PlexBot/__init__.py @@ -1,8 +1,8 @@ -"""Plex music bot for discord. - - Do not import this module, it is intended to be - used exclusively within a docker environment. +""" +Plex music bot for discord. +Do not import this module, it is intended to be +used exclusively within a docker environment. """ import logging import sys diff --git a/PlexBot/__main__.py b/PlexBot/__main__.py index 7079a38..8dfae5e 100644 --- a/PlexBot/__main__.py +++ b/PlexBot/__main__.py @@ -1,7 +1,6 @@ -"""Main entrypoint for bot - - Sets up loggers and initiates bot. - +""" +Main entrypoint script. +Sets up loggers and initiates bot. """ import logging diff --git a/PlexBot/bot.py b/PlexBot/bot.py index 616daa8..4436f62 100644 --- a/PlexBot/bot.py +++ b/PlexBot/bot.py @@ -1,4 +1,4 @@ -""" All discord bot and Plex api interactions""" +"""All discord bot and Plex api interactions.""" import asyncio import io import logging From 7f49c4d958008af67752cd0a5bfde911516ad018 Mon Sep 17 00:00:00 2001 From: Joshua Arulsamy Date: Mon, 10 Aug 2020 02:33:15 -0600 Subject: [PATCH 7/7] :bookmark: Tag release --- PlexBot/__version__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PlexBot/__version__.py b/PlexBot/__version__.py index 8f25dfd..f06a6d3 100644 --- a/PlexBot/__version__.py +++ b/PlexBot/__version__.py @@ -1,5 +1,5 @@ """Track version number of package.""" -VERSION = "0.0.7" +VERSION = "1.0.0" if __name__ == "__main__": print(VERSION)