From 0418ae16a66546ca7b804504fb54197806b8766b Mon Sep 17 00:00:00 2001 From: Abigail Gold Date: Mon, 4 Nov 2019 12:17:59 -0500 Subject: [PATCH] updates based on PR review, and new code in quickbot --- Dockerfile | 12 +++++------- README-DOCKER.md | 11 +++++++++++ README.md | 20 +++++++++++++++++++ docker-compose.yml | 2 +- docker-run.sh | 49 ---------------------------------------------- run.sh | 41 ++++++++++++++++++++++++++++++-------- 6 files changed, 70 insertions(+), 65 deletions(-) create mode 100644 README-DOCKER.md delete mode 100644 docker-run.sh diff --git a/Dockerfile b/Dockerfile index 20b5a97..fc7dd48 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ FROM python:3-alpine COPY . /app WORKDIR /app -VOLUME /app/data +ENV PYTHON_BIN python3 RUN \ echo "**** install build packages ****" && \ @@ -13,11 +13,11 @@ RUN \ gcc \ libxml2-dev \ libxslt-dev \ - openssl-dev \ + libressl-dev \ python3-dev && \ echo "**** install runtime packages ****" && \ apk add --no-cache \ - openssl \ + libressl \ py3-lxml \ py3-pip \ python3 && \ @@ -30,8 +30,6 @@ RUN \ rm -rf \ /root/.cache \ /tmp/* \ - /var/cache/apk/* && \ - echo "**** prepare scripts ****" && \ - chmod +x docker-run.sh + /var/cache/apk/* -CMD ["sh", "docker-run.sh", "--pass-errors"] +CMD ["/bin/sh", "run.sh", "--pass-errors", "--no-botenv"] diff --git a/README-DOCKER.md b/README-DOCKER.md new file mode 100644 index 0000000..45b19d7 --- /dev/null +++ b/README-DOCKER.md @@ -0,0 +1,11 @@ +A sample `docker-compose.yml` file: + +```yaml +version: '3' +services: + bot: + image: "classabbyamp/discord-qrm-bot:latest" + container_name: "qrmbot" + volumes: + - "./data:/app/data:rw" +``` diff --git a/README.md b/README.md index fb42e69..b3bfa1d 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,26 @@ A discord bot with ham radio functionalities. An independent rewrite of qrmbot-discord. +## Running + +### Docker + +See [README-DOCKER.md](./README-DOCKER.md) + +### Without Docker + +Prep the environment. For more information on extra options, see the [quick-bot-no-pain Makefile documentation](https://github.com/0x5c/quick-bot-no-pain/blob/master/docs/makefile.md). + +``` +$ make install +``` + +Run. For more information on options, see the [quick-bot-no-pain run.sh documentation](https://github.com/0x5c/quick-bot-no-pain/blob/master/docs/run.sh.md). + +``` +$ run.sh +``` + ## Copyright Copyright (C) 2019 Abigail Gold, 0x5c diff --git a/docker-compose.yml b/docker-compose.yml index c2541fd..183d669 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: '3' services: bot: - image: "classabbyamp/discord-qrm-bot:latest" + build: . container_name: "qrmbot" volumes: - "./data:/app/data:rw" diff --git a/docker-run.sh b/docker-run.sh deleted file mode 100644 index dcddcf2..0000000 --- a/docker-run.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash - -# A wrapper script for painless discord bots. -# v1.0.0 -# Copyright (c) 2019 0x5c -# Released under the terms of the MIT license. -# Part of: -# https://github.com/0x5c/quick-bot-no-pain - - -# Argument handling # ? TODO: Argument passing ? -if [[ $1 == '--pass-errors' ]]; then - _PASS_ERRORS=1 -fi - - -# A function called when the bot exits to decide what to do -code_handling() { - case $err in - 0) - echo "$_message: exiting" - exit 0 # The bot whishes to stay alone. - ;; - 42) - echo "$_message: restarting" - return # The bot whishes to be restarted (returns to the loop). - ;; - *) - if [[ $_PASS_ERRORS -eq 0 ]]; then # The bot crashed and: - echo "$_message: restarting" - return # ...we should return to the loop to restart it. - else - echo "$_message: exiting (--pass-errors)" - exit $err # ...we should just exit and pass the code to our parent (probably a daemon/service manager). - fi - ;; - esac -} - - -echo "$0: Starting bot..." - -# The loop -while true; do - python3 main.py - err=$? - _message="$0: The bot exited with [$err]" - code_handling -done diff --git a/run.sh b/run.sh index a48c23e..cf1d67b 100644 --- a/run.sh +++ b/run.sh @@ -1,7 +1,7 @@ -#!/bin/bash +#!/bin/sh # A wrapper script for painless discord bots. -# v1.0.0 +# v1.2.0 # Copyright (c) 2019 0x5c # Released under the terms of the MIT license. # Part of: @@ -9,13 +9,34 @@ # If $BOTENV is not defined, default to 'botenv' -if [[ -z ${BOTENV+x} ]]; then +if [ -z "$BOTENV" ]; then BOTENV='botenv' fi -# Argument handling # ? TODO: Argument passing ? -if [[ $1 == '--pass-errors' ]]; then - _PASS_ERRORS=1 + +# Argument handling +_PASS_ERRORS=0 +_NO_BOTENV=0 +while [ ! -z "$1" ]; do + case $1 in + --pass-errors) + _PASS_ERRORS=1 + ;; + --no-botenv) + _NO_BOTENV=1 + ;; + --) + shift + break + ;; + esac + shift +done + + +# If $PYTHON_BIN is not defined, default to 'python3.7' +if [ $_NO_BOTENV -eq 1 -a -z "$PYTHON_BIN" ]; then + PYTHON_BIN='python3.7' fi @@ -31,7 +52,7 @@ code_handling() { return # The bot whishes to be restarted (returns to the loop). ;; *) - if [[ $_PASS_ERRORS -eq 0 ]]; then # The bot crashed and: + if [ $_PASS_ERRORS -eq 0 ]; then # The bot crashed and: echo "$_message: restarting" return # ...we should return to the loop to restart it. else @@ -47,7 +68,11 @@ echo "$0: Starting bot..." # The loop while true; do - ./$BOTENV/bin/python3 main.py + if [ $_NO_BOTENV -eq 1 ]; then + "$PYTHON_BIN" main.py $@ + else + ./$BOTENV/bin/python3 main.py $@ + fi err=$? _message="$0: The bot exited with [$err]" code_handling