From ab011f95a3025aa8c850ce5fe5b246fce990a7c6 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 1 Apr 2018 21:17:27 -0700 Subject: [PATCH 01/19] bump github3apps.py version --- requirements.txt | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index b45fe9a..cfe2c35 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,7 +10,7 @@ cryptography==2.2.2 Flask==0.12.2 gitconsensus==0.7.0 github3.py==1.0.2 -github3apps.py==0.1.2 +github3apps.py==0.1.3 idna==2.6 itsdangerous==0.24 Jinja2==2.10 diff --git a/setup.py b/setup.py index 44ce6e0..fcbf4b5 100644 --- a/setup.py +++ b/setup.py @@ -50,7 +50,7 @@ 'Flask>=0.12.2', 'gitconsensus>=0.7,<0.8' 'github3.py>=1,<2', - 'github3apps.py>=0.1.2', + 'github3apps.py>=0.1.3,<0.2', 'pyjwt>=1.5.3,<2', 'PyYAML>=3.12,<3.13', 'requests>=2.18.0,<2.19', From a6214664d467ed09e651683d6bf7cacb5fb76a76 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sat, 7 Apr 2018 22:49:39 -0700 Subject: [PATCH 02/19] bump gitconsensus version to 0.7.1 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index cfe2c35..698c38d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,7 +8,7 @@ chardet==3.0.4 click==6.7 cryptography==2.2.2 Flask==0.12.2 -gitconsensus==0.7.0 +gitconsensus==0.7.1 github3.py==1.0.2 github3apps.py==0.1.3 idna==2.6 From 1f81ec9bebf624c8ba153c8ed6f23a78e60a0fc2 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Mon, 9 Apr 2018 23:43:08 -0700 Subject: [PATCH 03/19] bump gitconsensus version to 0.7.2 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 698c38d..673bce7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,7 +8,7 @@ chardet==3.0.4 click==6.7 cryptography==2.2.2 Flask==0.12.2 -gitconsensus==0.7.1 +gitconsensus==0.7.2 github3.py==1.0.2 github3apps.py==0.1.3 idna==2.6 From 6b5ca55e0edf126db74ac040eac71d1557356c5a Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Wed, 11 Apr 2018 00:52:51 -0700 Subject: [PATCH 04/19] Create LICENSE --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..7eac12c --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 Robert Hafner + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From d0f03464b4997575c133234edec34e1d4eb22156 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Fri, 17 Aug 2018 23:03:00 -0700 Subject: [PATCH 05/19] Update github3.py library --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 673bce7..9a379eb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,7 +9,7 @@ click==6.7 cryptography==2.2.2 Flask==0.12.2 gitconsensus==0.7.2 -github3.py==1.0.2 +github3.py==1.1.0 github3apps.py==0.1.3 idna==2.6 itsdangerous==0.24 From aea95adb404cc7f63fcc37b953287a00106666e8 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Fri, 17 Aug 2018 23:13:09 -0700 Subject: [PATCH 06/19] Upgrade dependencies --- requirements.txt | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/requirements.txt b/requirements.txt index 9a379eb..17f0beb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,30 +1,31 @@ -amqp==2.2.2 +amqp==2.3.2 asn1crypto==0.24.0 -billiard==3.5.0.3 -celery==4.1.0 -certifi==2018.1.18 +billiard==3.5.0.4 +celery==4.2.1 +certifi==2018.8.13 cffi==1.11.5 chardet==3.0.4 click==6.7 -cryptography==2.2.2 -Flask==0.12.2 +cryptography==2.3.1 +Flask==1.0.2 gitconsensus==0.7.2 +gitconsensusservice==0.1.0 github3.py==1.1.0 github3apps.py==0.1.3 idna==2.6 itsdangerous==0.24 Jinja2==2.10 -kombu==4.1.0 +kombu==4.2.1 MarkupSafe==1.0 pycparser==2.18 -PyJWT==1.6.1 -python-dateutil==2.7.2 -pytz==2018.3 +PyJWT==1.6.4 +python-dateutil==2.7.3 +pytz==2018.5 PyYAML==3.12 requests==2.18.4 +semantic-version==2.6.0 six==1.11.0 uritemplate==3.0.0 -uritemplate.py==3.0.2 urllib3==1.22 vine==1.1.4 Werkzeug==0.14.1 From ffd140435012fa766b698bfecf2929e5ef5453b9 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Tue, 7 May 2019 23:23:21 -0700 Subject: [PATCH 07/19] Increase resiliency when there are repo or install specific errors --- gitconsensusservice/jobs/consensus.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/gitconsensusservice/jobs/consensus.py b/gitconsensusservice/jobs/consensus.py index 189e8ae..0537fcb 100644 --- a/gitconsensusservice/jobs/consensus.py +++ b/gitconsensusservice/jobs/consensus.py @@ -8,7 +8,11 @@ def process_installs(synchronous=False): installs = gh.get_installations() for install in installs: if synchronous: - process_installation(install, True) + try: + process_installation(install, True) + except Exception as error: + print('Failed to process install %s due to error:' % install) + print(error) else: process_installation.delay(install) @@ -20,7 +24,12 @@ def process_installation(installation_id, synchronous=False): repositories = installation.get_repositories() for repository in repositories: user, repo = repository.split('/') - process_repository(installation_id, user, repo, True) + try: + process_repository(installation_id, user, repo, True) + except Exception as error: + print('Failed to process %s/%s due to error:' % (user, repo)) + print(error) + @celery.task From e16d8e5393d0326190ae39185340130fc74d16a8 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Fri, 10 May 2019 23:33:18 -0700 Subject: [PATCH 08/19] dockerize, use celery beat for automatic scheduling --- Makefile | 6 +++- docker-compose.yaml | 19 ++++++++++++ docker/start_worker.sh | 19 ++++++++++++ dockerfile | 17 +++++++++++ gitconsensusservice/__init__.py | 7 +++++ gitconsensusservice/cli.py | 19 +++++++----- gitconsensusservice/worker.py | 11 ++++++- provisioning/etc/gitconsensus/celery | 29 ------------------- .../systemd/system/gitconsensusworker.service | 16 ---------- provisioning/setup.sh | 26 ----------------- requirements.txt | 1 - 11 files changed, 88 insertions(+), 82 deletions(-) create mode 100644 docker-compose.yaml create mode 100755 docker/start_worker.sh create mode 100644 dockerfile delete mode 100644 provisioning/etc/gitconsensus/celery delete mode 100644 provisioning/etc/systemd/system/gitconsensusworker.service delete mode 100755 provisioning/setup.sh diff --git a/Makefile b/Makefile index b45b0ad..bf0f32c 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,11 @@ fresh: clean dependencies fulluninstall: uninstall clean -install: +testenv: clean_testenv + docker-compose up --build + +clean_testenv: + docker-compose down dependencies: if [ ! -d $(ROOT_DIR)/venv ]; then python3 -m venv $(ROOT_DIR)/venv; fi diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..df5752b --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,19 @@ +version: "3" + +services: + worker: + build: + context: . + dockerfile: dockerfile + volumes: + - ./gitconsensusservice:/app/gitconsensusservice + - ./github_app.private-key.pem:/app/github_app.private-key.pem + environment: + - 'CELERY_BROKER=pyamqp://guest@rabbitmq//' + - 'DEBUG=true' + - 'GITHUB_APP_ID=9231' + depends_on: + - rabbitmq + + rabbitmq: + image: rabbitmq diff --git a/docker/start_worker.sh b/docker/start_worker.sh new file mode 100755 index 0000000..03f1164 --- /dev/null +++ b/docker/start_worker.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +if [[ ! -v 'MINIMUM_WORKERS' ]]; then + MINIMUM_WORKERS=2 +fi + +if [[ ! -v 'MAXIMUM_WORKERS' ]]; then + MAXIMUM_WORKERS=10 +fi + +if [ "$DISABLE_BEAT" = "true" ] +then + echo 'Launching celery worker without beat' + celery -A gitconsensusservice.worker.celery worker --loglevel=info --autoscale=$MAXIMUM_WORKERS,$MINIMUM_WORKERS +else + echo 'Launching celery worker with beat enabled' + rm -f ~/celerybeat-schedule + celery -A gitconsensusservice.worker.celery worker --loglevel=info --autoscale=$MAXIMUM_WORKERS,$MINIMUM_WORKERS -B -s ~/celerybeat-schedule +fi diff --git a/dockerfile b/dockerfile new file mode 100644 index 0000000..b0b3dce --- /dev/null +++ b/dockerfile @@ -0,0 +1,17 @@ +FROM python:3.6 + +ADD requirements.txt /app/requirements.txt +WORKDIR /app/ +RUN pip install -r requirements.txt + +ENV SETTINGS /app/settings.yaml +ENV GITHUB_PRIVATE_KEY /app/github_app.private-key.pem + +ADD ./gitconsensusservice/ /app/gitconsensusservice + +RUN useradd -ms /bin/bash gitconsensusservice +USER gitconsensusservice + +ADD ./docker/start_worker.sh /home/gitconsensusservice/start_worker.sh + +ENTRYPOINT /home/gitconsensusservice/start_worker.sh \ No newline at end of file diff --git a/gitconsensusservice/__init__.py b/gitconsensusservice/__init__.py index f1bdac6..f109808 100644 --- a/gitconsensusservice/__init__.py +++ b/gitconsensusservice/__init__.py @@ -11,6 +11,13 @@ with open(os.environ['SETTINGS'], 'r') as infile: app.config.update(yaml.load(infile.read())) + +SETTINGS = ['DEBUG', 'GITHUB_PRIVATE_KEY', 'GITHUB_APP_ID', 'GITHUB_WEBHOOK_SECRET', 'CELERY_BROKER'] +for setting in SETTINGS: + if setting in os.environ: + app.config[setting] = os.environ[setting] + + if 'CELERY_BROKER' in app.config: celery = Celery('gitconsensus', broker=app.config['CELERY_BROKER']) else: diff --git a/gitconsensusservice/cli.py b/gitconsensusservice/cli.py index 13295e1..685c213 100644 --- a/gitconsensusservice/cli.py +++ b/gitconsensusservice/cli.py @@ -41,14 +41,17 @@ def install_repos(install_id): def list_repos(): installs = gh.get_installations() for install_id in installs: - click.echo('Install %s:' % install_id) - installation = get_githubapp_install(install_id) - repos = installation.get_repositories() - for repo in repos: - user, repo = repo.split('/') - repository = installation.get_repository(user, repo) - if repository.rules: - click.echo('\t%s/%s' % (user, repo)) + try: + click.echo('Install %s:' % install_id) + installation = get_githubapp_install(install_id) + repos = installation.get_repositories() + for repo in repos: + user, repo = repo.split('/') + repository = installation.get_repository(user, repo) + if repository.rules: + click.echo('\t%s/%s' % (user, repo)) + except: + click.echo('Unable to process install %s' % install_id) @cli.command(short_help="List details about the current application.") diff --git a/gitconsensusservice/worker.py b/gitconsensusservice/worker.py index ceb6383..d740f73 100644 --- a/gitconsensusservice/worker.py +++ b/gitconsensusservice/worker.py @@ -1,2 +1,11 @@ -import gitconsensusservice.jobs.consensus +from celery.schedules import crontab +from gitconsensusservice.jobs import consensus from gitconsensusservice import celery + + +@celery.on_after_finalize.connect +def setup_periodic_tasks(sender, **kwargs): + sender.add_periodic_task( + 5 * 60.0, + consensus.process_installs.s(), + name='Root Task - Schedule Installation Jobs') diff --git a/provisioning/etc/gitconsensus/celery b/provisioning/etc/gitconsensus/celery deleted file mode 100644 index 32d4566..0000000 --- a/provisioning/etc/gitconsensus/celery +++ /dev/null @@ -1,29 +0,0 @@ - -# Where does gitconsensus live -CELERY_HOME="/opt/gitconsensus" - -# Name of nodes to start -# here we have a single node -CELERYD_NODES="w1" -# or we could have three nodes: -#CELERYD_NODES="w1 w2 w3" - -# Absolute or relative path to the 'celery' command: -CELERY_BIN="/opt/gitconsensus/venv/bin/celery" - -# App instance to use -# comment out this line if you don't use an app -CELERY_APP="gitconsensusservice.worker:celery" - -# How to call manage.py -CELERYD_MULTI="multi" - -# Extra command-line arguments to the worker -CELERYD_OPTS="--time-limit=120 --concurrency=4" - -# - %n will be replaced with the first part of the nodename. -# - %I will be replaced with the current child process index -# and is important when using the prefork pool to avoid race conditions. -CELERYD_PID_FILE="/var/run/gitconsensus/worker-%n.pid" -CELERYD_LOG_FILE="/var/log/gitconsensus/worker-%n%I.log" -CELERYD_LOG_LEVEL="INFO" diff --git a/provisioning/etc/systemd/system/gitconsensusworker.service b/provisioning/etc/systemd/system/gitconsensusworker.service deleted file mode 100644 index 045c696..0000000 --- a/provisioning/etc/systemd/system/gitconsensusworker.service +++ /dev/null @@ -1,16 +0,0 @@ -[Unit] -Description=GitConsensus Service -After=network.target - -[Service] -Type=forking -User=gitconsensus -Group=gitconsensus -EnvironmentFile=-/etc/gitconsensus/celery -WorkingDirectory=${CELERY_HOME} -ExecStart=/bin/bash -c 'source ${CELERY_HOME}/bin/envvar && ${CELERY_BIN} multi start ${CELERYD_NODES} -A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} --logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}' -ExecStop=/bin/bash -c 'source ${CELERY_HOME}/bin/envvar && ${CELERY_BIN} multi stopwait ${CELERYD_NODES} --pidfile=${CELERYD_PID_FILE}' -ExecReload=/bin/bash -c 'source ${CELERY_HOME}/bin/envvar && ${CELERY_BIN} multi restart ${CELERYD_NODES} -A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} --logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}' - -[Install] -WantedBy=multi-user.target diff --git a/provisioning/setup.sh b/provisioning/setup.sh deleted file mode 100755 index 7d1e472..0000000 --- a/provisioning/setup.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash - -if [[ -L "${BASH_SOURCE[0]}" ]] -then - DIR="$( cd "$( dirname $( readlink "${BASH_SOURCE[0]}" ) )" && pwd )" -else - DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -fi - -cd $DIR - -cp $DIR/etc/systemd/system/gitconsensusworker.service /etc/systemd/system/gitconsensusworker.service -cp $DIR/etc/gitconsensus/celery /etc/gitconsensus/celery - - -adduser --gecos "" --disabled-login gitconsensus - -mkdir /var/run/gitconsensus -chown gitconsensus:gitconsensus /var/run/gitconsensus -mkdir /var/log/gitconsensus -chown gitconsensus:gitconsensus /var/log/gitconsensus - -echo "d /var/run/celery 0755 celery celery -" >> /etc/tmpfiles.d/celery.conf -echo "d /var/log/celery 0755 celery celery - " >> /etc/tmpfiles.d/celery.conf - -systemctl daemon-reload diff --git a/requirements.txt b/requirements.txt index 17f0beb..e0599ad 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,7 +9,6 @@ click==6.7 cryptography==2.3.1 Flask==1.0.2 gitconsensus==0.7.2 -gitconsensusservice==0.1.0 github3.py==1.1.0 github3apps.py==0.1.3 idna==2.6 From 316d6edf8a639611dfd53cb97de8a41d21859b50 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sat, 11 May 2019 18:31:14 -0700 Subject: [PATCH 09/19] Add docker hub publishing via circleci --- .circleci/config.yml | 52 ++++++++++++++++++++++++++++++++++++++++++++ .dockerignore | 5 +++++ Makefile | 6 +++++ 3 files changed, 63 insertions(+) create mode 100644 .circleci/config.yml create mode 100644 .dockerignore diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..e0c2621 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,52 @@ +version: 2.1 +executors: + docker-publisher: + environment: + IMAGE_NAME: tedivm/gitconsensus_service + docker: + - image: circleci/buildpack-deps:stretch +jobs: + build: + executor: docker-publisher + steps: + - checkout + - setup_remote_docker + - run: + name: Build Docker image + command: | + docker build -t $IMAGE_NAME:latest . + - run: + name: Archive Docker image + command: docker save -o image.tar $IMAGE_NAME + - persist_to_workspace: + root: . + paths: + - ./image.tar + publish-latest: + executor: docker-publisher + steps: + - attach_workspace: + at: /tmp/workspace + - setup_remote_docker + - run: + name: Load archived Docker image + command: docker load -i /tmp/workspace/image.tar + - run: + name: Publish Docker Image to Docker Hub + command: | + echo "$DOCKERHUB_PASS" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin + docker push $IMAGE_NAME:latest +workflows: + version: 2 + build-master: + jobs: + - build: + filters: + branches: + only: master + - publish-latest: + requires: + - build + filters: + branches: + only: master \ No newline at end of file diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..8b25384 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +.git +venv +build +dist +*.pem diff --git a/Makefile b/Makefile index bf0f32c..ad54971 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,12 @@ testenv: clean_testenv clean_testenv: docker-compose down +build_image: + docker build -f $(ROOT_DIR)/dockerfile -t tedivm/gitconsensus_service:latest . + +publish_image: build_image + docker push tedivm/gitconsensus_service:latest + dependencies: if [ ! -d $(ROOT_DIR)/venv ]; then python3 -m venv $(ROOT_DIR)/venv; fi source $(ROOT_DIR)/venv/bin/activate; python -m pip install wheel; yes w | python -m pip install -e . From 29d5a6c5199c7df589bfcc2e861bb2e4ba1cc2d7 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sat, 11 May 2019 18:45:38 -0700 Subject: [PATCH 10/19] Rework circleci workflow for efficiency Archiving was taking longer than building did --- .circleci/config.yml | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index e0c2621..f4476b5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -15,38 +15,33 @@ jobs: name: Build Docker image command: | docker build -t $IMAGE_NAME:latest . - - run: - name: Archive Docker image - command: docker save -o image.tar $IMAGE_NAME - - persist_to_workspace: - root: . - paths: - - ./image.tar + publish-latest: executor: docker-publisher steps: - - attach_workspace: - at: /tmp/workspace + - checkout - setup_remote_docker - run: - name: Load archived Docker image - command: docker load -i /tmp/workspace/image.tar + name: Build Docker image + command: | + docker build -t $IMAGE_NAME:latest . | cat - run: name: Publish Docker Image to Docker Hub command: | echo "$DOCKERHUB_PASS" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin docker push $IMAGE_NAME:latest + workflows: version: 2 - build-master: + build: jobs: - build: filters: branches: - only: master + ignore: master + publish: + jobs: - publish-latest: - requires: - - build filters: branches: only: master \ No newline at end of file From d64c7e4fa69fcb1a17fdd84f220853eeabaf1892 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sat, 11 May 2019 19:04:55 -0700 Subject: [PATCH 11/19] Pipe commands to cat for cleaner output on circleci --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index f4476b5..d0ab1d0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -14,7 +14,7 @@ jobs: - run: name: Build Docker image command: | - docker build -t $IMAGE_NAME:latest . + docker build -t $IMAGE_NAME:latest . | cat publish-latest: executor: docker-publisher @@ -29,7 +29,7 @@ jobs: name: Publish Docker Image to Docker Hub command: | echo "$DOCKERHUB_PASS" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin - docker push $IMAGE_NAME:latest + docker push $IMAGE_NAME:latest | cat workflows: version: 2 From fca88f63d303a87f81b43bb1019aa0a8b9f74d70 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sat, 11 May 2019 20:24:43 -0700 Subject: [PATCH 12/19] Make interval between processing installs configurable --- docker-compose.yaml | 1 + gitconsensusservice/__init__.py | 8 +++++++- gitconsensusservice/worker.py | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index df5752b..0fdab38 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -12,6 +12,7 @@ services: - 'CELERY_BROKER=pyamqp://guest@rabbitmq//' - 'DEBUG=true' - 'GITHUB_APP_ID=9231' + - 'PROCESS_INSTALLS_INTERVAL=30' depends_on: - rabbitmq diff --git a/gitconsensusservice/__init__.py b/gitconsensusservice/__init__.py index f109808..32ec5ad 100644 --- a/gitconsensusservice/__init__.py +++ b/gitconsensusservice/__init__.py @@ -12,7 +12,13 @@ app.config.update(yaml.load(infile.read())) -SETTINGS = ['DEBUG', 'GITHUB_PRIVATE_KEY', 'GITHUB_APP_ID', 'GITHUB_WEBHOOK_SECRET', 'CELERY_BROKER'] +SETTINGS = [ + 'DEBUG', + 'GITHUB_PRIVATE_KEY', + 'GITHUB_APP_ID', + 'GITHUB_WEBHOOK_SECRET', + 'CELERY_BROKER', + 'PROCESS_INSTALLS_INTERVAL'] for setting in SETTINGS: if setting in os.environ: app.config[setting] = os.environ[setting] diff --git a/gitconsensusservice/worker.py b/gitconsensusservice/worker.py index d740f73..ff743db 100644 --- a/gitconsensusservice/worker.py +++ b/gitconsensusservice/worker.py @@ -1,11 +1,11 @@ from celery.schedules import crontab from gitconsensusservice.jobs import consensus -from gitconsensusservice import celery +from gitconsensusservice import celery, app @celery.on_after_finalize.connect def setup_periodic_tasks(sender, **kwargs): sender.add_periodic_task( - 5 * 60.0, + float(app.config.get('PROCESS_INSTALLS_INTERVAL', 5 * 60.0)), consensus.process_installs.s(), name='Root Task - Schedule Installation Jobs') From e758fd9d103910369c1cc30dcd7cfd9158c439ed Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sat, 11 May 2019 20:30:38 -0700 Subject: [PATCH 13/19] Simplify and Upgrade dependencies --- Makefile | 3 +++ bin/upgrade_dependencies.sh | 31 ++++++++++++++++++++++++++ requirements.txt | 44 +++++++++++++------------------------ 3 files changed, 49 insertions(+), 29 deletions(-) create mode 100755 bin/upgrade_dependencies.sh diff --git a/Makefile b/Makefile index ad54971..57843b3 100644 --- a/Makefile +++ b/Makefile @@ -26,6 +26,9 @@ dependencies: if [ ! -d $(ROOT_DIR)/venv ]; then python3 -m venv $(ROOT_DIR)/venv; fi source $(ROOT_DIR)/venv/bin/activate; python -m pip install wheel; yes w | python -m pip install -e . +upgrade_dependencies: venv + source $(ROOT_DIR)/venv/bin/activate; ./bin/upgrade_dependencies.sh $(ROOT_DIR)/requirements.txt + application: if [ ! -d $(ROOT_DIR)/venv ]; then python3 -m venv $(ROOT_DIR)/venv; fi source $(ROOT_DIR)/venv/bin/activate; python -m pip install wheel; yes w | python -m pip install -r requirements.txt diff --git a/bin/upgrade_dependencies.sh b/bin/upgrade_dependencies.sh new file mode 100755 index 0000000..a7398fb --- /dev/null +++ b/bin/upgrade_dependencies.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +REQUIREMENTS_FILE=$1 + +while read p; do + if [[ -z "${p// }" ]];then + continue + fi + if [[ "${p// }" == \#* ]];then + continue + fi + + count=$(echo ${p// } | wc -m) + if (( count < 3 )); then + continue + fi + + program=$(echo $p | cut -d= -f1) + curr_version=$(cat ./requirements.txt | grep "${program}==" | cut -d'=' -f3 | sed 's/[^0-9.]*//g') + PACKAGE_JSON_URL="https://pypi.python.org/pypi/${program}/json" + version=$(curl -L -s "$PACKAGE_JSON_URL" | jq -r '.releases | keys | .[]' | sed '/^[^[:alpha:]]*$/!d' | sort -V | tail -1 | sed 's/[^0-9.]*//g' ) + + if [ "$curr_version" != "$version" ]; then + echo "Updating requirements for ${program} from ${curr_version} to ${version}." + sed -i -e "s/${program}==.*/${program}==${version}/g" $REQUIREMENTS_FILE + fi + +done < $REQUIREMENTS_FILE + +# OSX Creates a backup file. +rm -f "${REQUIREMENTS_FILE}-e" diff --git a/requirements.txt b/requirements.txt index e0599ad..ed8549f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,30 +1,16 @@ -amqp==2.3.2 -asn1crypto==0.24.0 -billiard==3.5.0.4 -celery==4.2.1 -certifi==2018.8.13 -cffi==1.11.5 -chardet==3.0.4 -click==6.7 -cryptography==2.3.1 + +# Frameworks +celery==4.3.0 +click==7.0 Flask==1.0.2 -gitconsensus==0.7.2 -github3.py==1.1.0 -github3apps.py==0.1.3 -idna==2.6 -itsdangerous==0.24 -Jinja2==2.10 -kombu==4.2.1 -MarkupSafe==1.0 -pycparser==2.18 -PyJWT==1.6.4 -python-dateutil==2.7.3 -pytz==2018.5 -PyYAML==3.12 -requests==2.18.4 -semantic-version==2.6.0 -six==1.11.0 -uritemplate==3.0.0 -urllib3==1.22 -vine==1.1.4 -Werkzeug==0.14.1 + + +# Git +gitconsensus==0.7.3 +github3.py==1.3.0 +github3apps.py==0.1.4 + + +# Libraries +PyYAML==5.1 +requests==2.21.0 From 93b7340f26447a324ae2ca946aa3825f8b89119a Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sat, 11 May 2019 23:51:54 -0700 Subject: [PATCH 14/19] Upgrade upstream dependency to fix bug --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index ed8549f..504e752 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,7 +8,7 @@ Flask==1.0.2 # Git gitconsensus==0.7.3 github3.py==1.3.0 -github3apps.py==0.1.4 +github3apps.py==0.1.5 # Libraries From eba2d4db14139750f686282a02746d0a854c600c Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 12 May 2019 00:18:39 -0700 Subject: [PATCH 15/19] More upstream upgrades, process repositories asynchronously --- gitconsensusservice/jobs/consensus.py | 5 ++++- requirements.txt | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/gitconsensusservice/jobs/consensus.py b/gitconsensusservice/jobs/consensus.py index 0537fcb..8a2ecc8 100644 --- a/gitconsensusservice/jobs/consensus.py +++ b/gitconsensusservice/jobs/consensus.py @@ -25,7 +25,10 @@ def process_installation(installation_id, synchronous=False): for repository in repositories: user, repo = repository.split('/') try: - process_repository(installation_id, user, repo, True) + if synchronous: + process_repository(installation_id, user, repo, True) + else: + process_repository.delay(installation_id, user, repo, False) except Exception as error: print('Failed to process %s/%s due to error:' % (user, repo)) print(error) diff --git a/requirements.txt b/requirements.txt index 504e752..e17046c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,7 +6,7 @@ Flask==1.0.2 # Git -gitconsensus==0.7.3 +gitconsensus==0.7.4 github3.py==1.3.0 github3apps.py==0.1.5 From 4266d478e3c96d503c2fd3e27b5db2b2af00ae3c Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Thu, 22 Aug 2019 22:40:37 -0700 Subject: [PATCH 16/19] Add print statement to root task setup --- gitconsensusservice/worker.py | 1 + 1 file changed, 1 insertion(+) diff --git a/gitconsensusservice/worker.py b/gitconsensusservice/worker.py index ff743db..ea0758f 100644 --- a/gitconsensusservice/worker.py +++ b/gitconsensusservice/worker.py @@ -5,6 +5,7 @@ @celery.on_after_finalize.connect def setup_periodic_tasks(sender, **kwargs): + print('Root Task - Schedule Installation Jobs') sender.add_periodic_task( float(app.config.get('PROCESS_INSTALLS_INTERVAL', 5 * 60.0)), consensus.process_installs.s(), From 9879736bf041595d185a54b90e6b5c19a53eb669 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 25 Aug 2019 23:40:25 -0700 Subject: [PATCH 17/19] Update gitconsensus library --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index e17046c..dd76475 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,7 +6,7 @@ Flask==1.0.2 # Git -gitconsensus==0.7.4 +gitconsensus==0.7.5 github3.py==1.3.0 github3apps.py==0.1.5 From 62474e3752d262a07e8392144651f27629abd4c8 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 15 Sep 2019 15:31:26 -0700 Subject: [PATCH 18/19] Upgrade upstream gitconsensus library --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index dd76475..af4bab1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,7 +6,7 @@ Flask==1.0.2 # Git -gitconsensus==0.7.5 +gitconsensus==0.8.0 github3.py==1.3.0 github3apps.py==0.1.5 From c4c920eaf39aefdca2fa3d82a92c89e27da46506 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Wed, 5 Aug 2020 19:00:39 -0700 Subject: [PATCH 19/19] update github3apps.py to v0.2.0 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index af4bab1..fc3b1c5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,7 +8,7 @@ Flask==1.0.2 # Git gitconsensus==0.8.0 github3.py==1.3.0 -github3apps.py==0.1.5 +github3apps.py==0.2.0 # Libraries