added docker configs
This commit is contained in:
parent
a89f0df161
commit
5cb6bccd7f
14
.env-dist
Normal file
14
.env-dist
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
COMPOSE_FILE=docker-compose.yml
|
||||||
|
COMPOSE_DIR=.
|
||||||
|
|
||||||
|
MONGO_INITDB_ROOT_USERNAME=root
|
||||||
|
MONGO_INITDB_ROOT_PASSWORD=SetYourOwnPassword
|
||||||
|
MONGO_INITDB_DATABASE=pollmaster
|
||||||
|
|
||||||
|
# official discord bot token
|
||||||
|
DISCORD_BOT_TOKEN=
|
||||||
|
# owner user id
|
||||||
|
OWNER_ID=
|
||||||
|
|
||||||
|
# Sets the invite client id
|
||||||
|
INVITE_CLIENT_ID=
|
||||||
18
Dockerfile
Normal file
18
Dockerfile
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
FROM alpine:3.10.2
|
||||||
|
|
||||||
|
WORKDIR '/tmp'
|
||||||
|
|
||||||
|
COPY ./pm /data/pm
|
||||||
|
|
||||||
|
RUN apk update && apk add bash nodejs npm python3 python3-dev freetype-dev subversion
|
||||||
|
RUN apk --no-cache --update-cache add gcc gfortran build-base wget libpng-dev openblas-dev
|
||||||
|
|
||||||
|
RUN pip3 install --upgrade pip
|
||||||
|
|
||||||
|
WORKDIR '/data/pm'
|
||||||
|
|
||||||
|
RUN pip install pykg-config
|
||||||
|
|
||||||
|
RUN pip install -r requirements.txt
|
||||||
|
|
||||||
|
CMD python3 pollmaster.py
|
||||||
42
docker-compose.yml
Normal file
42
docker-compose.yml
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
# Use root/example as user/password credentials
|
||||||
|
version: '3.1'
|
||||||
|
|
||||||
|
services:
|
||||||
|
# Database
|
||||||
|
mongo:
|
||||||
|
image: mongo:latest
|
||||||
|
restart: always
|
||||||
|
volumes:
|
||||||
|
- ./docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d
|
||||||
|
environment:
|
||||||
|
- MONGO_INITDB_ROOT_USERNAME
|
||||||
|
- MONGO_INITDB_ROOT_PASSWORD
|
||||||
|
- MONGO_INITDB_DATABASE
|
||||||
|
|
||||||
|
# App - Container, where the main application runs
|
||||||
|
app:
|
||||||
|
restart: always
|
||||||
|
volumes:
|
||||||
|
- ./pm/cogs/poll_controls.py:/data/pm/cogs/poll_controls.py
|
||||||
|
- ./pm/pollmaster.py:/data/pm/pollmaster.py
|
||||||
|
links:
|
||||||
|
- mongo
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
environment:
|
||||||
|
- DISCORD_BOT_TOKEN
|
||||||
|
- MONGO_INITDB_ROOT_USERNAME
|
||||||
|
- MONGO_INITDB_ROOT_PASSWORD
|
||||||
|
- OWNER_ID
|
||||||
|
- INVITE_CLIENT_ID
|
||||||
|
|
||||||
|
# Admin Interface for Database
|
||||||
|
mongo-express:
|
||||||
|
image: mongo-express
|
||||||
|
restart: always
|
||||||
|
ports:
|
||||||
|
- 8081:8081
|
||||||
|
environment:
|
||||||
|
ME_CONFIG_MONGODB_ADMINUSERNAME: $MONGO_INITDB_ROOT_USERNAME
|
||||||
|
ME_CONFIG_MONGODB_ADMINPASSWORD: $MONGO_INITDB_ROOT_PASSWORD
|
||||||
2
.gitignore → pm/.gitignore
vendored
2
.gitignore → pm/.gitignore
vendored
@ -1,5 +1,5 @@
|
|||||||
# IDE Folders
|
# IDE Folders
|
||||||
\.idea/
|
../.idea/
|
||||||
|
|
||||||
# PY VENV
|
# PY VENV
|
||||||
venv/
|
venv/
|
||||||
@ -1,4 +1,5 @@
|
|||||||
import argparse
|
import argparse
|
||||||
|
import os
|
||||||
import asyncio
|
import asyncio
|
||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
@ -8,6 +9,8 @@ import shlex
|
|||||||
import discord
|
import discord
|
||||||
import pytz
|
import pytz
|
||||||
|
|
||||||
|
import time
|
||||||
|
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
|
||||||
from utils.misc import CustomFormatter
|
from utils.misc import CustomFormatter
|
||||||
@ -47,7 +50,9 @@ class PollControls(commands.Cog):
|
|||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
if not hasattr(self.bot, 'db'):
|
if not hasattr(self.bot, 'db'):
|
||||||
await asyncio.sleep(30)
|
"""await asyncio.sleep(30)"""
|
||||||
|
logger.info("DB not available yet")
|
||||||
|
time.sleep(30)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
query = self.bot.db.polls.find({'active': False, 'activation': {"$not": re.compile("0")}})
|
query = self.bot.db.polls.find({'active': False, 'activation': {"$not": re.compile("0")}})
|
||||||
@ -1,4 +1,5 @@
|
|||||||
import discord
|
import discord
|
||||||
|
import os
|
||||||
|
|
||||||
from essentials.secrets import SECRETS
|
from essentials.secrets import SECRETS
|
||||||
|
|
||||||
@ -9,11 +10,11 @@ class Settings:
|
|||||||
self.title_icon = "https://i.imgur.com/vtLsAl8.jpg" #PM
|
self.title_icon = "https://i.imgur.com/vtLsAl8.jpg" #PM
|
||||||
self.author_icon = "https://i.imgur.com/TYbBtwB.jpg" #tag
|
self.author_icon = "https://i.imgur.com/TYbBtwB.jpg" #tag
|
||||||
self.report_icon = "https://i.imgur.com/YksGRLN.png" #report
|
self.report_icon = "https://i.imgur.com/YksGRLN.png" #report
|
||||||
self.owner_id = 117687652278468610
|
self.owner_id = os.environ.get('OWNER_ID')
|
||||||
self.msg_errors = False
|
self.msg_errors = True
|
||||||
self.log_errors = True
|
self.log_errors = True
|
||||||
self.invite_link = \
|
self.invite_link = \
|
||||||
'https://discordapp.com/api/oauth2/authorize?client_id=444831720659877889&permissions=126016&scope=bot'
|
'https://discordapp.com/api/oauth2/authorize?client_id=%s&permissions=126016&scope=bot' % (os.environ.get('INVITE_CLIENT_ID'))
|
||||||
|
|
||||||
self.load_secrets()
|
self.load_secrets()
|
||||||
|
|
||||||
BIN
pm/models/__pycache__/__init__.cpython-36.pyc
Normal file
BIN
pm/models/__pycache__/__init__.cpython-36.pyc
Normal file
Binary file not shown.
BIN
pm/models/__pycache__/poll.cpython-36.pyc
Normal file
BIN
pm/models/__pycache__/poll.cpython-36.pyc
Normal file
Binary file not shown.
@ -43,17 +43,9 @@ ch.setFormatter(formatter)
|
|||||||
logger.addHandler(fh)
|
logger.addHandler(fh)
|
||||||
logger.addHandler(ch)
|
logger.addHandler(ch)
|
||||||
|
|
||||||
extensions = ['cogs.config', 'cogs.poll_controls', 'cogs.help', 'cogs.db_api', 'cogs.admin']
|
|
||||||
for ext in extensions:
|
|
||||||
bot.load_extension(ext)
|
|
||||||
|
|
||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
bot.owner = await bot.fetch_user(SETTINGS.owner_id)
|
bot.owner = await bot.fetch_user(SETTINGS.owner_id)
|
||||||
|
|
||||||
mongo = AsyncIOMotorClient(SETTINGS.mongo_db)
|
|
||||||
bot.db = mongo.pollmaster
|
|
||||||
bot.session = aiohttp.ClientSession()
|
bot.session = aiohttp.ClientSession()
|
||||||
print(bot.db)
|
print(bot.db)
|
||||||
|
|
||||||
@ -71,6 +63,7 @@ async def on_ready():
|
|||||||
|
|
||||||
except:
|
except:
|
||||||
print("Problem verifying servers.")
|
print("Problem verifying servers.")
|
||||||
|
logger.error("Problem verifying servers.")
|
||||||
|
|
||||||
# cache prefixes
|
# cache prefixes
|
||||||
bot.pre = {entry['_id']: entry['prefix'] async for entry in bot.db.config.find({}, {'_id', 'prefix'})}
|
bot.pre = {entry['_id']: entry['prefix'] async for entry in bot.db.config.find({}, {'_id', 'prefix'})}
|
||||||
@ -82,6 +75,7 @@ async def on_ready():
|
|||||||
await bot.change_presence(status=discord.Status.online, activity=game)
|
await bot.change_presence(status=discord.Status.online, activity=game)
|
||||||
|
|
||||||
print("Servers verified. Bot running.")
|
print("Servers verified. Bot running.")
|
||||||
|
logger.info("Servers verified. Bot running.")
|
||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
async def on_command_error(ctx, e):
|
async def on_command_error(ctx, e):
|
||||||
@ -136,4 +130,14 @@ async def on_guild_join(server):
|
|||||||
)
|
)
|
||||||
bot.pre[str(server.id)] = 'pm!'
|
bot.pre[str(server.id)] = 'pm!'
|
||||||
|
|
||||||
|
logger.info("Connecting to Mongo DB: " + SETTINGS.mongo_db)
|
||||||
|
mongo = AsyncIOMotorClient(SETTINGS.mongo_db)
|
||||||
|
bot.db = mongo.pollmaster
|
||||||
|
print(bot.db)
|
||||||
|
|
||||||
|
extensions = ['cogs.config', 'cogs.poll_controls', 'cogs.help', 'cogs.db_api', 'cogs.admin']
|
||||||
|
for ext in extensions:
|
||||||
|
logger.info("Loading extension " + ext)
|
||||||
|
bot.load_extension(ext)
|
||||||
|
|
||||||
bot.run(SETTINGS.bot_token)
|
bot.run(SETTINGS.bot_token)
|
||||||
Loading…
Reference in New Issue
Block a user