Finally a testing framework, fixes #9

This commit is contained in:
Luke Robles 2017-08-10 13:50:36 -07:00
parent ec62c918f8
commit b618bc85d6
6 changed files with 42 additions and 19 deletions

View File

@ -1,12 +1,9 @@
FROM python:3.6.2-slim
LABEL name="Dragon Bot"
RUN apt-get update && apt-get install curl -y &&\
curl -Lks get.docker.com | bash
RUN pip install requests discord.py docker pybooru termcolor
RUN pip install requests discord.py docker pybooru
ADD app /app
# Run this to test that the python compiles when we actually go live
RUN python /app/dragon-bot.py test
CMD python app/dragon-bot.py

14
Dockerfile-test-env Normal file
View File

@ -0,0 +1,14 @@
FROM python:3.6.2-slim
LABEL name="Dragon Bot Test environment"
RUN apt-get update && apt-get install curl -y &&\
curl -Lks get.docker.com | bash
RUN pip install requests discord.py docker pybooru pylint
ADD app /app
RUN echo "\nTesting your python code for errors\n" && \
pylint -E /app/*.py
RUN echo "\n#########################\nRun dragon bot by typing \npython dragon-bot.py\n#########################\n"
WORKDIR /app

View File

@ -13,11 +13,11 @@ A discord bot for the trifecta discord channel
* `curl -Ls get.docker.com | bash`
### Testing your changes ###
* Test that you can actually build the container
* `docker build -t testing .`
* `docker run -ti testing bash`
* Then, if you've added print statements to the script for testing, you can see them by running:
* `python /app/dragon-bot.py`
* Build the testing container by running
* `./test-dragon-bot.sh`
* The dragon-bot-test bot will connect to the server.
* If you want to test what the bot is seeing when you type commands, add LOTS of of print statements to dragon-bot.py
* you will see the output in the terminal. This is useful for debugging
* pipeline [here](https://cloud.docker.com/app/ldooks/repository/docker/ldooks/dragon-bot/builds)
### Contribution guidelines ###

View File

@ -1,19 +1,26 @@
import random
import sys
import requests
import os
import help_methods
import discord
import docker
from pybooru import Danbooru
from termcolor import colored
# Client object
client = discord.Client()
tokens = {
'test': 'MzQ1MjkwMTI5OTQ4Mjc4Nzg0.DG5IBw._9umb82PrL22bPe7GjmHClU-NtU',
'prod': 'MzM5NDQ2NTgwMTU3MzQ5ODg4.DG5K5Q.2kIonA_XHLXU4_Sq4O63OzCb0Jc'
}
token = os.getenv('DRAGON_ENV')
@client.event
async def on_ready():
print("Dragon bot up and ready to roll.\n")
print("\n********************************")
print("\nDRAGON BOT RUNNING IN {} MODE".format(token.upper()))
print("\n********************************")
@client.event
@ -253,10 +260,5 @@ async def on_message(message):
else:
await client.send_message(message.channel, "There arent {} lines of output yet".format(num_lines))
# Check if there is a command line argument after script
if len(sys.argv) > 1:
print(colored("If you're seeing this, the python compiled", 'green'))
sys.exit()
token = "MzM5NDQ2NTgwMTU3MzQ5ODg4.DFkGYg.z-XD17nFP4rtBq-YsNbOJHuBWfQ" # get from the bot page. must be a bot, not a discord app
client.run(token)
client.run(tokens[token])

View File

@ -6,5 +6,5 @@ printf "[+] Done\n"
# Run that shit and mount the docker socket so it can talk to the sky-factory container
printf "\n[-] Pulling latest build of container\n"
docker pull ldooks/dragon-bot:latest
docker run -d --name dragon-bot -v /var/run/docker.sock:/var/run/docker.sock --restart always ldooks/dragon-bot:latest
docker run -d --name dragon-bot -e "DRAGON_ENV=prod" -v /var/run/docker.sock:/var/run/docker.sock --restart always ldooks/dragon-bot:latest
printf "[+] Done\n"

10
test-dragon-bot.sh Executable file
View File

@ -0,0 +1,10 @@
# Remove the running container so we cna re-use the container name 'dragon-bot'
printf "\n[-] Deleting old dragon-bot container from system\n"
docker rm -f dragon-bot-test
printf "[+] Done\n"
# Run that shit and mount the docker socket so it can talk to the sky-factory container
printf "\n[-] Running dragon bot in test mode\n"
docker build -f ./Dockerfile-test-env -t dragon-bot-test . || exit
docker run -ti --name dragon-bot-test -e DRAGON_ENV=test -v /var/run/docker.sock:/var/run/docker.sock dragon-bot-test bash
printf "[+] Done\n"