Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PokemonGo bot version to docker image #4884

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ data/map-caught-*.json
data/recent-forts-*.json
data/caught-*.json
data/deviceid-*.txt
data/mqtt_client_id.*
user_web_catchable
version

# Multiple config
configs/*
Expand Down
17 changes: 9 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ VOLUME ["/usr/src/app/configs", "/usr/src/app/web"]

ADD https://raw.githubusercontent.com/$BUILD_REPO/$BUILD_BRANCH/requirements.txt .
RUN apk -U --no-cache add python py-pip \
&& apk --no-cache add --virtual .build-dependencies python-dev gcc make musl-dev git tzdata tar \
&& apk --no-cache add --virtual .build-dependencies python-dev gcc make musl-dev git tzdata \
&& cp -fa /usr/share/zoneinfo/$TIMEZONE /etc/localtime \
&& echo $TIMEZONE > /etc/timezone \
&& ln -s locale.h /usr/include/xlocale.h \
Expand All @@ -35,17 +35,18 @@ RUN apk -U --no-cache add python py-pip \
&& find / -name '*.pyc' -o -name '*.pyo' -exec rm -f {} \;

ADD http://pgoapi.com/pgoencrypt.tar.gz /tmp/pgoencrypt.tar.gz
RUN apk --no-cache add --virtual .pgoencrypt-dependencies gcc make musl-dev tar \
&& cat /tmp/pgoencrypt.tar.gz | tar xzf - -C /tmp \
RUN apk --no-cache add --virtual .pgoencrypt-dependencies gcc make musl-dev \
&& tar zxf /tmp/pgoencrypt.tar.gz -C /tmp \
&& make -C /tmp/pgoencrypt/src \
&& cp /tmp/pgoencrypt/src/libencrypt.so /usr/src/app/encrypt.so \
&& apk del .pgoencrypt-dependencies \
&& rm -rf /var/cache/apk/* /tmp/pgoencrypt /tmp/pgoencrypt.tar.gz

ADD https://github.com/$BUILD_REPO/archive/$BUILD_BRANCH.tar.gz /tmp
RUN apk -U --no-cache add --virtual .tar-deps tar \
&& cat /tmp/$BUILD_BRANCH.tar.gz | tar -zxf - --strip-components=1 -C /usr/src/app \
&& apk del .tar-deps \
&& rm /tmp/$BUILD_BRANCH.tar.gz
ADD https://api.github.com/repos/$BUILD_REPO/git/refs/heads/$BUILD_BRANCH /tmp/pgobot-version
Copy link
Contributor

@th3w4y th3w4y Aug 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not working if i specify a particular commit as the BUILD_BRANCH
Ex:
https://api.github.com/repos/PokemonGoF/PokemonGo-Bot/git/refs/heads/1862b9bf296e201b1e3b5f2783f6a7436ced5698 404

{
"message": "Not Found",
"documentation_url": "https://developer.github.com/v3"
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there any situation we need to use a commit?

Copy link
Contributor

@th3w4y th3w4y Aug 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it order to test new changes... that is why you can also override the BUILD_REPO

In the past there was a COPY . /usr/src/app

the user was able to do it's changes and docker build again

I replaced that with ADD https://github.com/$BUILD_REPO/archive/$BUILD_BRANCH.tar.gz /tmp for various reasons:

  • security COPY . means including auth and unfits... and stuff (I know there is a .dockerignore but whatever... )
  • being able to reproduce the build if you know create date and LABEL build_branch and build_repo and not support some uncommited local modification that the user might have done...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, so I'll delete this PR

RUN apk -U --no-cache add --virtual .pgobot-dependencies wget ca-certificates tar jq \
&& wget -q -O- https://github.com/$BUILD_REPO/archive/$BUILD_BRANCH.tar.gz | tar zxf - --strip-components=1 -C /usr/src/app \
&& jq -r .object.sha /tmp/pgobot-version > /usr/src/app/version \
&& apk del .pgobot-dependencies \
&& rm -rf /var/cache/apk/* /tmp/pgobot-version

ENTRYPOINT ["python", "pokecli.py"]
57 changes: 35 additions & 22 deletions pokecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,10 @@
import signal
import string
import subprocess
from datetime import timedelta
from getpass import getpass
from pgoapi.exceptions import NotLoggedInException, ServerSideRequestThrottlingException, ServerBusyOrOfflineException, NoPlayerPositionSetException
from geopy.exc import GeocoderQuotaExceeded

from pokemongo_bot import inventory
from pokemongo_bot import PokemonGoBot, TreeConfigBuilder
from pokemongo_bot.base_dir import _base_dir
from pokemongo_bot.health_record import BotEvent
Expand All @@ -65,7 +63,10 @@
logger = logging.getLogger('cli')
logger.setLevel(logging.INFO)

class SIGINTRecieved(Exception): pass

class SIGINTRecieved(Exception):
pass


def main():
bot = False
Expand All @@ -81,21 +82,29 @@ def initialize_task(bot, config):
def initialize(config):
bot = PokemonGoBot(config)
return bot
def start_bot(bot,config):

def start_bot(bot, config):
bot.start()
initialize_task(bot,config)
initialize_task(bot, config)
bot.metrics.capture_stats()
bot.health_record = BotEvent(config)
return bot

def get_commit_hash():
try:
hash = subprocess.check_output(['git', 'rev-parse', 'HEAD'], stderr=subprocess.STDOUT)[:-1]

return hash if all(c in string.hexdigits for c in hash) else "not found"
hash = subprocess.check_output(['git', 'rev-parse', 'HEAD'],
stderr=subprocess.STDOUT)
if all(c in string.hexdigits for c in hash[:-1]):
with open('version', 'w') as f:
f.write(hash)
except:
return "not found"
pass

if not os.path.exists('version'):
return 'unknown'

with open('version') as f:
return f.read()[:8]

try:
logger.info('PokemonGO Bot v1.0')
Expand All @@ -116,7 +125,7 @@ def get_commit_hash():
while not finished:
try:
bot = initialize(config)
bot = start_bot(bot,config)
bot = start_bot(bot, config)
config_changed = check_mod(config_file)

bot.event_manager.emit(
Expand All @@ -132,10 +141,11 @@ def get_commit_hash():
logger.info('Config changed! Applying new config.')
config, _ = init_config()

if config.live_config_update_tasks_only: initialize_task(bot, config)
else:
if config.live_config_update_tasks_only:
initialize_task(bot, config)
else:
bot = initialize(config)
bot = start_bot(bot,config)
bot = start_bot(bot, config)

except KeyboardInterrupt:
bot.event_manager.emit(
Expand Down Expand Up @@ -232,6 +242,7 @@ def get_commit_hash():
data={'path': cached_forts_path}
)


def check_mod(config_file):
check_mod.mtime = os.path.getmtime(config_file)

Expand All @@ -245,6 +256,7 @@ def compare_mtime():

return compare_mtime


def report_summary(bot):
if bot.metrics.start_time is None:
return # Bot didn't actually start, no metrics to show.
Expand All @@ -270,6 +282,7 @@ def report_summary(bot):
if metrics.most_perfect is not None:
logger.info('Most Perfect Pokemon: {}'.format(metrics.most_perfect['desc']))


def init_config():
parser = argparse.ArgumentParser()
config_file = os.path.join(_base_dir, 'configs', 'config.json')
Expand Down Expand Up @@ -390,8 +403,7 @@ def _json_loader(filename):
load,
short_flag="-wmax",
long_flag="--walk_max",
help=
"Walk instead of teleport with given speed",
help="Walk instead of teleport with given speed",
type=float,
default=2.5
)
Expand All @@ -400,8 +412,7 @@ def _json_loader(filename):
load,
short_flag="-wmin",
long_flag="--walk_min",
help=
"Walk instead of teleport with given speed",
help="Walk instead of teleport with given speed",
type=float,
default=2.5
)
Expand Down Expand Up @@ -632,7 +643,7 @@ def _json_loader(filename):
type=bool,
default=False
)

# Start to parse other attrs
config = parser.parse_args()
if not config.username and 'username' not in load:
Expand Down Expand Up @@ -697,10 +708,10 @@ def task_configuration_error(flag_name):

if "daily_catch_limit" in load:
logger.warning('The daily_catch_limit argument has been moved into the CatchPokemon Task')

if "logging_color" in load:
logger.warning('The logging_color argument has been moved into the logging config section')

if config.walk_min < 1:
parser.error("--walk_min is out of range! (should be >= 1.0)")
return None
Expand All @@ -727,14 +738,15 @@ def task_configuration_error(flag_name):
fix_nested_config(config)
return config, config_file


def add_config(parser, json_config, short_flag=None, long_flag=None, **kwargs):
if not long_flag:
raise Exception('add_config calls requires long_flag parameter!')

full_attribute_path = long_flag.split('--')[1]
attribute_name = full_attribute_path.split('.')[-1]

if '.' in full_attribute_path: # embedded config!
if '.' in full_attribute_path: # embedded config!
embedded_in = full_attribute_path.split('.')[0: -1]
for level in embedded_in:
json_config = json_config.get(level, {})
Expand All @@ -757,6 +769,7 @@ def fix_nested_config(config):
config_dict[new_key] = value
del config_dict[key]


def parse_unicode_str(string):
try:
return string.decode('utf8')
Expand Down