From e028f4449b41839e3c334bf74e11bb8ead8cdc23 Mon Sep 17 00:00:00 2001 From: Filipe Santos Date: Sun, 22 Apr 2018 16:53:37 +1200 Subject: [PATCH 1/5] Add docker build by branch --- .dockerignore | 23 ----------------------- docker/.dockerignore | 2 ++ Dockerfile => docker/Dockerfile | 11 +++++------ docker/hooks/build | 3 +++ 4 files changed, 10 insertions(+), 29 deletions(-) delete mode 100644 .dockerignore create mode 100644 docker/.dockerignore rename Dockerfile => docker/Dockerfile (85%) create mode 100644 docker/hooks/build diff --git a/.dockerignore b/.dockerignore deleted file mode 100644 index e2c9e06..0000000 --- a/.dockerignore +++ /dev/null @@ -1,23 +0,0 @@ -# Git -.git - -# Systemd files -systemd - -# Logs -*.log* - -# Configs -*.json - -# Byte-compiled / optimized / DLL files -**/__pycache__ -*.py[cod] -*$py.class -*.pyc - -# Pyenv -**/.python-version - -# User-specific stuff: -.idea diff --git a/docker/.dockerignore b/docker/.dockerignore new file mode 100644 index 0000000..bfefeee --- /dev/null +++ b/docker/.dockerignore @@ -0,0 +1,2 @@ +# Hooks +hooks diff --git a/Dockerfile b/docker/Dockerfile similarity index 85% rename from Dockerfile rename to docker/Dockerfile index 3034b41..2bc7543 100644 --- a/Dockerfile +++ b/docker/Dockerfile @@ -1,13 +1,12 @@ FROM python:3.6-alpine3.7 +# Default branch to master +ARG BRANCH=master + ENV \ - # App directory APP_DIR=traktarr \ - # Branch to clone - BRANCH=master \ - # Config file + BRANCH=${BRANCH} \ TRAKTARR_CONFIG=/config/config.json \ - # Log file TRAKTARR_LOGFILE=/config/traktarr.log RUN \ @@ -15,7 +14,7 @@ RUN \ apk --no-cache -U upgrade && \ echo "** Install OS dependencies **" && \ apk --no-cache -U add git && \ - echo "** Get Traktarr **" && \ + echo "** Get Traktarr branch: ${BRANCH} **" && \ git clone --depth 1 --branch ${BRANCH} https://github.com/l3uddz/traktarr.git /${APP_DIR} && \ echo "** Install PIP dependencies **" && \ pip install --no-cache-dir --upgrade pip setuptools && \ diff --git a/docker/hooks/build b/docker/hooks/build new file mode 100644 index 0000000..a6ef3df --- /dev/null +++ b/docker/hooks/build @@ -0,0 +1,3 @@ +#!/bin/bash + +docker build --build-arg BRANCH=${SOURCE_BRANCH} -f ${DOCKERFILE_PATH} -t ${IMAGE_NAME} . From 66ea6917d966b43f6a7714d4dd8a2b87e0d57ddc Mon Sep 17 00:00:00 2001 From: Filipe Santos Date: Sun, 22 Apr 2018 16:53:37 +1200 Subject: [PATCH 2/5] Add docker build by branch --- traktarr.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/traktarr.py b/traktarr.py index 97c7f14..5e14706 100755 --- a/traktarr.py +++ b/traktarr.py @@ -493,21 +493,32 @@ def automatic_movies(add_delay=2.5, no_search=False, notifications=False): def run(add_delay=2.5, no_search=False, no_notifications=False): # add tasks to repeat if cfg.automatic.movies.interval: - schedule.every(cfg.automatic.movies.interval).hours.do(automatic_movies, add_delay, no_search, - not no_notifications) + schedule.every(cfg.automatic.movies.interval).hours.do( + automatic_movies, + add_delay, + no_search, + not no_notifications + ) + if cfg.automatic.shows.interval: - schedule.every(cfg.automatic.shows.interval).hours.do(automatic_shows, add_delay, no_search, - not no_notifications) + schedule.every(cfg.automatic.shows.interval).hours.do( + automatic_shows, + add_delay, + no_search, + not no_notifications + ) # run schedule log.info("Automatic mode is now running...") while True: try: + # Sleep until next run + time.sleep(schedule.idle_seconds()) + # Check jobs to run schedule.run_pending() - except Exception: - log.exception("Unhandled exception occurred while processing scheduled tasks: ") - else: - time.sleep(1) + + except Exception as e: + log.exception("Unhandled exception occurred while processing scheduled tasks: %s", e) ############################################################ From 6d1347dc59de727a094e49f905fff3b32f345453 Mon Sep 17 00:00:00 2001 From: Filipe Santos Date: Sun, 22 Apr 2018 23:28:14 +1200 Subject: [PATCH 3/5] Dockerfile copy instead of git clone --- .dockerignore | 45 ++++++++++++++++++++++++++++++++++++++++++++ docker/.dockerignore | 2 -- docker/Dockerfile | 11 +++++------ docker/hooks/build | 2 +- 4 files changed, 51 insertions(+), 9 deletions(-) create mode 100644 .dockerignore delete mode 100644 docker/.dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..8f004c6 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,45 @@ +# User-specific stuff: +.idea + +## File-based project format: +*.iws + +# IntelliJ +/out/ + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class +*.pyc + +# logs +*.log* + +# databases +*.db + +# configs +*.cfg +*.json + +# generators +*.bat + +# Pyenv +**/.python-version + +# PyInstaller +build/ +dist/ +*.manifest +*.spec + +# Git +.git + +# Systemd +systemd + +# Docker files +docker diff --git a/docker/.dockerignore b/docker/.dockerignore deleted file mode 100644 index bfefeee..0000000 --- a/docker/.dockerignore +++ /dev/null @@ -1,2 +0,0 @@ -# Hooks -hooks diff --git a/docker/Dockerfile b/docker/Dockerfile index 2bc7543..44f8bec 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,21 +1,20 @@ FROM python:3.6-alpine3.7 -# Default branch to master -ARG BRANCH=master +# Arguments for build tracking +ARG BRANCH= +ARG COMMIT= ENV \ APP_DIR=traktarr \ BRANCH=${BRANCH} \ + COMMIT=${COMMIT} \ TRAKTARR_CONFIG=/config/config.json \ TRAKTARR_LOGFILE=/config/traktarr.log RUN \ + echo "** BRANCH: ${BRANCH} COMMIT: ${COMMIT} **" && \ echo "** Upgrade all packages **" && \ apk --no-cache -U upgrade && \ - echo "** Install OS dependencies **" && \ - apk --no-cache -U add git && \ - echo "** Get Traktarr branch: ${BRANCH} **" && \ - git clone --depth 1 --branch ${BRANCH} https://github.com/l3uddz/traktarr.git /${APP_DIR} && \ echo "** Install PIP dependencies **" && \ pip install --no-cache-dir --upgrade pip setuptools && \ pip install --no-cache-dir --upgrade -r /${APP_DIR}/requirements.txt diff --git a/docker/hooks/build b/docker/hooks/build index a6ef3df..578d0bd 100644 --- a/docker/hooks/build +++ b/docker/hooks/build @@ -1,3 +1,3 @@ #!/bin/bash -docker build --build-arg BRANCH=${SOURCE_BRANCH} -f ${DOCKERFILE_PATH} -t ${IMAGE_NAME} . +docker build --build-arg BRANCH=${SOURCE_BRANCH} --build-arg COMMIT=${SOURCE_COMMIT} -f ${DOCKERFILE_PATH} -t ${IMAGE_NAME} . From 9b5b84c5a99115908ada9d6bae0514f8b5b1ad32 Mon Sep 17 00:00:00 2001 From: Filipe Santos Date: Mon, 23 Apr 2018 00:40:42 +1200 Subject: [PATCH 4/5] Fix docker cloud build --- .dockerignore | 3 --- docker/hooks/build | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.dockerignore b/.dockerignore index 8f004c6..82cbdf1 100644 --- a/.dockerignore +++ b/.dockerignore @@ -40,6 +40,3 @@ dist/ # Systemd systemd - -# Docker files -docker diff --git a/docker/hooks/build b/docker/hooks/build index 578d0bd..1727f7a 100644 --- a/docker/hooks/build +++ b/docker/hooks/build @@ -1,3 +1,6 @@ #!/bin/bash +# Docker cloud bug ?, working directory is not set acording to the config +cd .. + docker build --build-arg BRANCH=${SOURCE_BRANCH} --build-arg COMMIT=${SOURCE_COMMIT} -f ${DOCKERFILE_PATH} -t ${IMAGE_NAME} . From b33ccffc0e9f57ec2e011c38b6f259146c2879d4 Mon Sep 17 00:00:00 2001 From: Filipe Santos Date: Mon, 23 Apr 2018 01:03:33 +1200 Subject: [PATCH 5/5] Something important --- docker/Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker/Dockerfile b/docker/Dockerfile index 44f8bec..67d0b49 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -11,6 +11,8 @@ ENV \ TRAKTARR_CONFIG=/config/config.json \ TRAKTARR_LOGFILE=/config/traktarr.log +COPY . /${APP_DIR} + RUN \ echo "** BRANCH: ${BRANCH} COMMIT: ${COMMIT} **" && \ echo "** Upgrade all packages **" && \