From 34cf4101312e6cda98f20d8d7cfb81f8af561a1e Mon Sep 17 00:00:00 2001 From: Abigail Date: Sat, 2 Nov 2019 16:56:53 -0400 Subject: [PATCH] add docker deployment files --- .dockerignore | 1 + Dockerfile | 37 ++++++++++++++++++++++++++++++++++ docker-compose.yml | 7 +++++++ docker-run.sh | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 94 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 docker-run.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..8fce603 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +data/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..20b5a97 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,37 @@ +FROM python:3-alpine + +COPY . /app +WORKDIR /app + +VOLUME /app/data + +RUN \ + echo "**** install build packages ****" && \ + apk add --no-cache --virtual=build-dependencies \ + g++ \ + git \ + gcc \ + libxml2-dev \ + libxslt-dev \ + openssl-dev \ + python3-dev && \ + echo "**** install runtime packages ****" && \ + apk add --no-cache \ + openssl \ + py3-lxml \ + py3-pip \ + python3 && \ + echo "**** install pip packages ****" && \ + pip3 install -U pip setuptools wheel && \ + pip3 install -r requirements.txt && \ + echo "**** clean up ****" && \ + apk del --purge \ + build-dependencies && \ + rm -rf \ + /root/.cache \ + /tmp/* \ + /var/cache/apk/* && \ + echo "**** prepare scripts ****" && \ + chmod +x docker-run.sh + +CMD ["sh", "docker-run.sh", "--pass-errors"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..c2541fd --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,7 @@ +version: '3' +services: + bot: + image: "classabbyamp/discord-qrm-bot:latest" + container_name: "qrmbot" + volumes: + - "./data:/app/data:rw" diff --git a/docker-run.sh b/docker-run.sh new file mode 100644 index 0000000..dcddcf2 --- /dev/null +++ b/docker-run.sh @@ -0,0 +1,49 @@ +#!/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