Skip to content

Commit

Permalink
Merge pull request #143 from LanceMaverick/dockerfy
Browse files Browse the repository at this point in the history
Add ability to use docker for skybeard
  • Loading branch information
LanceMaverick committed Jun 14, 2017
2 parents 18225d9 + 84f045f commit 086e904
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ config.py
config.yml
.#*
*.db
docker-compose.yml

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM python:3

# Use bash as the shell because we will need to source a virtualenv later
SHELL ["/bin/bash", "-c"]

# Create a skybeard user
RUN useradd -m skybeard
USER skybeard
WORKDIR /home/skybeard

# Make a few directories which will be mounted to later
RUN mkdir code db db_binary_entries skybeard_virtualenv

# Create a base virtualenv. Normally, there's no need for a virtualenv in a
# docker container, but since any beards that run can add to the requirements,
# we'll need a virutalenv tied to a persistant container
RUN python3 -m venv skybeard_virtualenv_frozen
ADD requirements.txt .
RUN . /home/skybeard/skybeard_virtualenv_frozen/bin/activate && pip install -r requirements.txt
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ You will then need to make a `config.py`. An example `config.py` is provided so
cp config.py.example config.py
```

## Installation with docker
This method is currently in beta. It requires docker-compose.

```
cp docker-compose.yml.example docker-compose.yml
```
then replace `YOUR_TOKEN_GOES_HERE` in `docker-compose.yml` with your token. Then run

```
docker-compose up --build
```

And skybeard will be (hopefully) running!

## Running Skybeard

To run skybeard define your key in the environment variable `$TG_BOT_TOKEN` or as an argument with `-k` and run `main.py`. this can be done easily e.g.:
Expand Down
4 changes: 4 additions & 0 deletions beard_repo/enigmabeard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
description: Enigma M3 Emulator plugin for Skybeard v2
git_url: https://github.com/artemis-beta/skb-enigmabeard.git
name: enigmabeard

3 changes: 3 additions & 0 deletions beard_repo/natrailenq.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
description: National Rail Enquiry plugin for Skybeard v2
git_url: https://github.com/artemis-beta/skb-natrailenq.git
name: natrailenq
4 changes: 4 additions & 0 deletions beard_repo/willbeard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
description: 'Skybeard 2 plugin: Find answers to your questions using this Skybeard
2 interface for W.I.L.L: https://github.com/ironman5366/W.I.L.L'
git_url: https://github.com/LanceMaverick/skybeard_willbot.git
name: willbeard
31 changes: 31 additions & 0 deletions config.docker.yml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
beard_paths:
- beards/
- beard_cache/
- examples/
- integration_test_beards/

beards:
- askfor
- database
- debugonlyexample
- config_helper
# Integration test beards
- different_name_inside
- oldstyle_beard

stache_paths:
- moustaches

staches:
- postcats

db_url: sqlite:///../db/skybeard-2.db
db_bin_path: ../db_binary_entries/

admins:
[
[Nathanael Farley, 89593615],
]

host: 0.0.0.0
port: 8000
15 changes: 15 additions & 0 deletions docker-compose.yml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
skybeard:
build: .
environment:
- TG_BOT_TOKEN=YOUR_TOKEN_GOES_HERE
- SKYBEARD_CONFIG=config.docker.yml.example
command: ./code/run_on_docker.sh
user: skybeard
volumes:
# This is where the code is hosted
- .:/home/skybeard/code
# These should be unique per bot. If they are not, database information
# and python packages will be shared between bots.
- skybeard_virtualenv:/home/skybeard/skybeard_virtualenv:z
- skybeard_db:/home/skybeard/db:z
- skybeard_db_binary_entries:/home/skybeard/db_binary_entries:z
10 changes: 6 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ def load_beard(beard_name, possible_dirs):
pass

# TODO make this a much better exception
if module:
return
else:
try:
logger.debug("Got module: {}".format(module))
except UnboundLocalError:
raise Exception("No beard found! Looked in: {}. Trying to find: {}".format(possible_dirs, beard_name))

foo = importlib.util.module_from_spec(module_spec)
Expand Down Expand Up @@ -223,7 +223,9 @@ async def bot_message_loop_and_aiothttp_session():
parser = argparse.ArgumentParser(description='Skybeard hails you!')

parser.add_argument('-k', '--key', default=os.environ.get('TG_BOT_TOKEN'))
parser.add_argument('-c', '--config-file', default=os.path.abspath("config.yml"))
parser.add_argument('-c', '--config-file',
default=(os.environ.get('SKYBEARD_CONFIG') or
os.path.abspath("config.yml")))
parser.add_argument('--no-help', action='store_true')
parser.add_argument('-d', '--debug', action='store_const', dest="loglevel",
const=logging.DEBUG, default=logging.INFO)
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
aiohttp
telepot>=10.4
pyconfig>=3.1.1
dataset>=0.7.0
Expand Down
12 changes: 12 additions & 0 deletions run_on_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
# If the virtualenv is not populated, copy it over.
echo "Let's run skybeard!"
if [[ "$(ls -A ~/skybeard_virtualenv)" ]];
then
:
else
cp -r ~/skybeard_virtualenv_frozen/* ~/skybeard_virtualenv
fi
source ~/skybeard_virtualenv/bin/activate
cd code
python main.py
9 changes: 7 additions & 2 deletions utils/getbeard.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python
import argparse
import yaml
import os
from os.path import join
from pathlib import Path

import git
Expand All @@ -26,9 +28,12 @@ def download_beard(beard_name, upgrade):
git_ = git.Git("beard_cache")
print("Attempting to clone from {}...".format(beard_details['git_url']))
try:
git_.clone(beard_details['git_url'])
repo_dir = join("beard_cache", beard_name)
os.makedirs(repo_dir)
repo = git.Repo()
repo.clone_from(beard_details['git_url'], repo_dir)
print("Done!")
except git.GitCommandError:
except FileExistsError:
repo = git.Repo("beard_cache/{}".format(beard_name))
if upgrade:
print("Updating repo")
Expand Down

0 comments on commit 086e904

Please sign in to comment.