From 96aeb98cec2f7d02fb486c7f09f30c6d2b03cdee Mon Sep 17 00:00:00 2001 From: Igor Smirnov Date: Fri, 26 Jun 2020 12:17:38 +0300 Subject: [PATCH 01/39] Test pipeline --- .circleci/config.yml | 48 ++++++++++++++++++++++++++++++++++++++++++++ Dockerfile | 11 ++++++++++ app.py | 5 ++--- requirements.txt | 1 + start.sh | 2 +- 5 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 .circleci/config.yml create mode 100644 Dockerfile create mode 100644 requirements.txt diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..9d4d961 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,48 @@ +version: 2.1 +jobs: + lint: + docker: + - image: circleci/python:3.7.4 + steps: + - checkout + - run: + name: Create venv + command: | + echo 'export TAG=0.1.${CIRCLE_BUILD_NUM}' >> $BASH_ENV + echo 'export IMAGE_NAME=flask-ops' >> $BASH_ENV + virtualenv flaskops + - run: + name: Install python dependencies + command: | + . flaskops/bin/activate + pip install --no-cache-dir -r requirements.txt + - run: + name: Run Linter + command: | + . flaskops/bin/activate + pylint --load-plugins pylint_flask app.py + build: + steps: + - checkout + - run: + name: Build Docker Image + command: | + docker build -t smirnov_igor077/$IMAGE_NAME:$TAG . + push_image_to_registry: + steps: + -run: + name: Push Docker Image to DockerHub + command: | + docker login -u $DOCKER_LOGIN --password=$DOCKER_PWD + docker push smirnov_igor077/$IMAGE_NAME:$TAG +workflows: + version: 2 + flask-ops-cicd: + jobs: + - lint + - build: + requires: + - lint + - push_image_to_registry: + requires: + - build diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3f34974 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM python:3.7 +ENV PYTHONUNBUFFERED 1 +ENV PYTHONDONTWRITEBYTECODE=1 +RUN mkdir /flask-app +WORKDIR /flask-app +COPY requirements.txt /flask-app/ +EXPOSE 5000 +RUN pip install --upgrade pip +RUN pip install -r requirements.txt +COPY . /flask-app/ +CMD ["bash", "start.sh"] diff --git a/app.py b/app.py index 512a98e..6b07647 100644 --- a/app.py +++ b/app.py @@ -1,13 +1,12 @@ ### ACME CORP ### Customer session key generator. Protects PII. ### / 2020 - -from flask import Flask - import string import secrets import hashlib +from flask import Flask + app = Flask(__name__) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..7e10602 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +flask diff --git a/start.sh b/start.sh index b0b168a..03ea61d 100644 --- a/start.sh +++ b/start.sh @@ -1,4 +1,4 @@ #!/bin/bash export FLASK_APP=app.py -flask run +flask run --host=0.0.0.0 From 38e7cdedc14bde0c38623b957c7799ba2a4ae598 Mon Sep 17 00:00:00 2001 From: Igor Smirnov Date: Fri, 26 Jun 2020 12:33:29 +0300 Subject: [PATCH 02/39] Fix pipeline --- .circleci/config.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9d4d961..5806ed2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -22,15 +22,18 @@ jobs: . flaskops/bin/activate pylint --load-plugins pylint_flask app.py build: + machine: true steps: - checkout - run: name: Build Docker Image command: | - docker build -t smirnov_igor077/$IMAGE_NAME:$TAG . + docker build -t smirnov_igor077/$IMAGE_NAME:$TAG . push_image_to_registry: + machine: true steps: - -run: + - checkout + - run: name: Push Docker Image to DockerHub command: | docker login -u $DOCKER_LOGIN --password=$DOCKER_PWD From 2eeaa8512e62a625d7a27c556186a89bb4c3e0e3 Mon Sep 17 00:00:00 2001 From: Igor Smirnov Date: Fri, 26 Jun 2020 12:35:18 +0300 Subject: [PATCH 03/39] Add pylint to requirements --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 7e10602..ddd67a8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ flask +pylint-flask \ No newline at end of file From c87aec6bdc017c8bf613eb54154eee457df26003 Mon Sep 17 00:00:00 2001 From: Igor Smirnov Date: Fri, 26 Jun 2020 13:17:43 +0300 Subject: [PATCH 04/39] Fix pylint under score --- .circleci/config.yml | 2 +- app.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5806ed2..fff6fc3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -20,7 +20,7 @@ jobs: name: Run Linter command: | . flaskops/bin/activate - pylint --load-plugins pylint_flask app.py + pylint --load-plugins pylint_flask --fail-under=7 app.py build: machine: true steps: diff --git a/app.py b/app.py index 6b07647..634dfcb 100644 --- a/app.py +++ b/app.py @@ -1,6 +1,8 @@ +""" ### ACME CORP ### Customer session key generator. Protects PII. ### / 2020 +""" import string import secrets import hashlib @@ -11,17 +13,16 @@ # !! DON'T EXPOSE THIS KEY !! -super_secret_salt = "68874260280172957479" +SUPER_SECRET_SALT = "68874260280172957479" def encrypt_string(hash_string): sha_signature = \ - hashlib.sha256(hash_string.encode()).hexdigest() + hashlib.sha256(hash_string.encode()).hexdigest() return sha_signature -# Generate a simple key def generate(): rand_device = string.ascii_letters + string.digits - return encrypt_string((''.join(secrets.choice(rand_device) for i in range(8))).join(super_secret_salt)) + return encrypt_string((''.join(secrets.choice(rand_device) for i in range(8))).join(SUPER_SECRET_SALT)) @app.route('/') def signature(): From cbc4cd2284524e6e45c3f31d740d6eef4b91df79 Mon Sep 17 00:00:00 2001 From: Igor Smirnov Date: Fri, 26 Jun 2020 13:37:07 +0300 Subject: [PATCH 05/39] Fix build job --- .circleci/config.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index fff6fc3..df3fe2d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -8,8 +8,6 @@ jobs: - run: name: Create venv command: | - echo 'export TAG=0.1.${CIRCLE_BUILD_NUM}' >> $BASH_ENV - echo 'export IMAGE_NAME=flask-ops' >> $BASH_ENV virtualenv flaskops - run: name: Install python dependencies @@ -28,7 +26,9 @@ jobs: - run: name: Build Docker Image command: | - docker build -t smirnov_igor077/$IMAGE_NAME:$TAG . + echo 'export TAG=0.1.${CIRCLE_BUILD_NUM}' >> $BASH_ENV + echo 'export IMAGE_NAME=flask-ops' >> $BASH_ENV + docker build -t smirnovigor077/$IMAGE_NAME:$TAG . push_image_to_registry: machine: true steps: From 8a3bf20c48f61df02e377ac471a30e1226ccbfe1 Mon Sep 17 00:00:00 2001 From: Igor Smirnov Date: Fri, 26 Jun 2020 13:42:25 +0300 Subject: [PATCH 06/39] Fix build job --- .circleci/config.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index df3fe2d..e40baa6 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -26,8 +26,9 @@ jobs: - run: name: Build Docker Image command: | - echo 'export TAG=0.1.${CIRCLE_BUILD_NUM}' >> $BASH_ENV - echo 'export IMAGE_NAME=flask-ops' >> $BASH_ENV + echo 'export TAG=0.1.${CIRCLE_BUILD_NUM}' + echo 'export IMAGE_NAME=flask-ops' + echo $IMAGE_NAME docker build -t smirnovigor077/$IMAGE_NAME:$TAG . push_image_to_registry: machine: true From f861d54077ec1a118a2be5a8e970223200291b24 Mon Sep 17 00:00:00 2001 From: Igor Smirnov Date: Fri, 26 Jun 2020 15:46:46 +0300 Subject: [PATCH 07/39] Fix build job --- .circleci/config.yml | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index e40baa6..e4b2448 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -26,19 +26,12 @@ jobs: - run: name: Build Docker Image command: | - echo 'export TAG=0.1.${CIRCLE_BUILD_NUM}' - echo 'export IMAGE_NAME=flask-ops' - echo $IMAGE_NAME - docker build -t smirnovigor077/$IMAGE_NAME:$TAG . - push_image_to_registry: - machine: true - steps: - - checkout + docker build -t smirnovigor077/flask-ops:{CIRCLE_SHA1} . - run: name: Push Docker Image to DockerHub command: | docker login -u $DOCKER_LOGIN --password=$DOCKER_PWD - docker push smirnov_igor077/$IMAGE_NAME:$TAG + docker push smirnovigor077/flask-ops:{CIRCLE_SHA1} workflows: version: 2 flask-ops-cicd: @@ -47,6 +40,3 @@ workflows: - build: requires: - lint - - push_image_to_registry: - requires: - - build From e9aa34cd7c158b15fd1ee1f09d42302d7d9aea6a Mon Sep 17 00:00:00 2001 From: Igor Smirnov Date: Fri, 26 Jun 2020 15:51:10 +0300 Subject: [PATCH 08/39] Fix build job --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index e4b2448..bc54035 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -26,12 +26,12 @@ jobs: - run: name: Build Docker Image command: | - docker build -t smirnovigor077/flask-ops:{CIRCLE_SHA1} . + docker build -t smirnovigor077/flask-ops:${CIRCLE_SHA1} . - run: name: Push Docker Image to DockerHub command: | docker login -u $DOCKER_LOGIN --password=$DOCKER_PWD - docker push smirnovigor077/flask-ops:{CIRCLE_SHA1} + docker push smirnovigor077/flask-ops:${CIRCLE_SHA1} workflows: version: 2 flask-ops-cicd: From 42de50ecd58ece2b79177c24e0429402460e907e Mon Sep 17 00:00:00 2001 From: Igor Smirnov Date: Fri, 26 Jun 2020 22:14:33 +0300 Subject: [PATCH 09/39] Add tests to pipeline --- .circleci/config.yml | 10 ++++++++++ .gitignore | 3 +++ app.py | 9 ++++++--- tests.py | 23 +++++++++++++++++++++++ 4 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 tests.py diff --git a/.circleci/config.yml b/.circleci/config.yml index bc54035..bc807dc 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -32,6 +32,16 @@ jobs: command: | docker login -u $DOCKER_LOGIN --password=$DOCKER_PWD docker push smirnovigor077/flask-ops:${CIRCLE_SHA1} + tests: + machine: true + steps: + - checkout + - run: + name: Test Image + command: | + docker login -u $DOCKER_LOGIN -p $DOCKER_PWD + docker pull smirnovigor077/flask-ops:${CIRCLE_SHA1} + docker run --rm -it smirnovigor077/flask-ops:${CIRCLE_SHA1} python tests.py workflows: version: 2 flask-ops-cicd: diff --git a/.gitignore b/.gitignore index b6e4761..abeac14 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,9 @@ __pycache__/ # C extensions *.so +# Pycharm +.idea/ + # Distribution / packaging .Python build/ diff --git a/app.py b/app.py index 634dfcb..84df511 100644 --- a/app.py +++ b/app.py @@ -11,18 +11,21 @@ app = Flask(__name__) - # !! DON'T EXPOSE THIS KEY !! SUPER_SECRET_SALT = "68874260280172957479" + def encrypt_string(hash_string): sha_signature = \ - hashlib.sha256(hash_string.encode()).hexdigest() + hashlib.sha256(hash_string.encode()).hexdigest() return sha_signature + def generate(): rand_device = string.ascii_letters + string.digits - return encrypt_string((''.join(secrets.choice(rand_device) for i in range(8))).join(SUPER_SECRET_SALT)) + return encrypt_string((''.join(secrets.choice(rand_device) + for i in range(8))).join(SUPER_SECRET_SALT)) + @app.route('/') def signature(): diff --git a/tests.py b/tests.py new file mode 100644 index 0000000..c020754 --- /dev/null +++ b/tests.py @@ -0,0 +1,23 @@ +""" +Unit tests for flask-ops application +""" +import unittest + +from app import encrypt_string + + +class TestApp(unittest.TestCase): + """ + Test app.py + """ + def test_encrypt_string_empty(self): + self.assertEqual(encrypt_string(''), + 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855') + + def test_encrypt_string_lower_block_size(self): + self.assertEqual(encrypt_string('qwerty'), + '65e84be33532fb784c48129675f9eff3a682b27168c0ea744b2cf58ee02337c5') + + def test_encrypt_string_equal_block_size(self): + self.assertEqual(encrypt_string('a' * 64), + 'ffe054fe7ae0cb6dc65c3af9b61d5209f439851db43d0ba5997337df154668eb') From d39caeeff783e6770f430a59bfea4e68a7625f05 Mon Sep 17 00:00:00 2001 From: Igor Smirnov Date: Fri, 26 Jun 2020 22:16:05 +0300 Subject: [PATCH 10/39] Add tests to workflow --- .circleci/config.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index bc807dc..aed9013 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -50,3 +50,6 @@ workflows: - build: requires: - lint + - tests: + requires: + - build From 3a2ac29de37ee54d847fbdf8c00052abd9c21330 Mon Sep 17 00:00:00 2001 From: Igor Smirnov Date: Sat, 27 Jun 2020 11:43:22 +0300 Subject: [PATCH 11/39] Hide secret and add healthcheck test --- .circleci/config.yml | 8 ++++++-- Dockerfile | 2 ++ app.py | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index aed9013..82b32ec 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -26,7 +26,7 @@ jobs: - run: name: Build Docker Image command: | - docker build -t smirnovigor077/flask-ops:${CIRCLE_SHA1} . + docker build --build-arg salt=${SECRET_SALT} -t smirnovigor077/flask-ops:${CIRCLE_SHA1} . - run: name: Push Docker Image to DockerHub command: | @@ -37,11 +37,15 @@ jobs: steps: - checkout - run: - name: Test Image + name: Unit tests command: | docker login -u $DOCKER_LOGIN -p $DOCKER_PWD docker pull smirnovigor077/flask-ops:${CIRCLE_SHA1} docker run --rm -it smirnovigor077/flask-ops:${CIRCLE_SHA1} python tests.py + - run: + name: Health check + command: | + curl -sI 0.0.0.0:5000 | grep "HTTP/1.0 200" workflows: version: 2 flask-ops-cicd: diff --git a/Dockerfile b/Dockerfile index 3f34974..5545174 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,6 @@ FROM python:3.7 +ARG salt +ENV SALT=$salt ENV PYTHONUNBUFFERED 1 ENV PYTHONDONTWRITEBYTECODE=1 RUN mkdir /flask-app diff --git a/app.py b/app.py index 84df511..8cfb01c 100644 --- a/app.py +++ b/app.py @@ -3,6 +3,7 @@ ### Customer session key generator. Protects PII. ### / 2020 """ +import os import string import secrets import hashlib @@ -11,8 +12,7 @@ app = Flask(__name__) -# !! DON'T EXPOSE THIS KEY !! -SUPER_SECRET_SALT = "68874260280172957479" +SUPER_SECRET_SALT = os.environ.get('SALT') def encrypt_string(hash_string): From 6939f0525cc827f45a115f230104a41148f5d9e7 Mon Sep 17 00:00:00 2001 From: Igor Smirnov Date: Sat, 27 Jun 2020 11:50:54 +0300 Subject: [PATCH 12/39] Fix healthcheck --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 82b32ec..2c4a59a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -41,7 +41,7 @@ jobs: command: | docker login -u $DOCKER_LOGIN -p $DOCKER_PWD docker pull smirnovigor077/flask-ops:${CIRCLE_SHA1} - docker run --rm -it smirnovigor077/flask-ops:${CIRCLE_SHA1} python tests.py + docker run --rm -it -d -p 5000:5000 smirnovigor077/flask-ops:${CIRCLE_SHA1} python tests.py - run: name: Health check command: | From 1e00d21fc2d74e59175cf494257d0342b7709a97 Mon Sep 17 00:00:00 2001 From: Igor Smirnov Date: Sun, 28 Jun 2020 12:34:50 +0300 Subject: [PATCH 13/39] Change registry --- .circleci/config.yml | 27 ++++++++++++++++----------- Dockerfile | 2 +- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2c4a59a..696ca7d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,6 +1,6 @@ version: 2.1 jobs: - lint: + linter: docker: - image: circleci/python:3.7.4 steps: @@ -26,12 +26,12 @@ jobs: - run: name: Build Docker Image command: | - docker build --build-arg salt=${SECRET_SALT} -t smirnovigor077/flask-ops:${CIRCLE_SHA1} . + docker build --build-arg salt=${SECRET_SALT} -t registry.heroku.com/flask-ops:${CIRCLE_SHA1} . - run: - name: Push Docker Image to DockerHub + name: Push Docker Image to Heroku Registry command: | - docker login -u $DOCKER_LOGIN --password=$DOCKER_PWD - docker push smirnovigor077/flask-ops:${CIRCLE_SHA1} + echo $HEROKU_API_KEY | docker login --username=_ --password-stdin registry.heroku.com + docker push registry.heroku.com/flask-ops:${CIRCLE_SHA1} tests: machine: true steps: @@ -39,13 +39,18 @@ jobs: - run: name: Unit tests command: | - docker login -u $DOCKER_LOGIN -p $DOCKER_PWD - docker pull smirnovigor077/flask-ops:${CIRCLE_SHA1} - docker run --rm -it -d -p 5000:5000 smirnovigor077/flask-ops:${CIRCLE_SHA1} python tests.py + echo $HEROKU_API_KEY | docker login --username=_ --password-stdin registry.heroku.com + docker pull registry.heroku.com/flask-ops:${CIRCLE_SHA1} + docker run --rm -it registry.heroku.com/flask-ops:${CIRCLE_SHA1} python tests.py + deploy: + machine: true + steps: + - checkout - run: - name: Health check + name: Deploy to Heroku command: | - curl -sI 0.0.0.0:5000 | grep "HTTP/1.0 200" + echo $HEROKU_API_KEY | docker login --username=_ --password-stdin registry.heroku.com + workflows: version: 2 flask-ops-cicd: @@ -53,7 +58,7 @@ workflows: - lint - build: requires: - - lint + - linter - tests: requires: - build diff --git a/Dockerfile b/Dockerfile index 5545174..928da03 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM python:3.7 ARG salt ENV SALT=$salt -ENV PYTHONUNBUFFERED 1 +ENV PYTHONUNBUFFERED=1 ENV PYTHONDONTWRITEBYTECODE=1 RUN mkdir /flask-app WORKDIR /flask-app From 37006ef4b8659a627f60447fdb17f74c90d1be88 Mon Sep 17 00:00:00 2001 From: Igor Smirnov Date: Sun, 28 Jun 2020 12:35:53 +0300 Subject: [PATCH 14/39] Fix workflow --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 696ca7d..ae5f3b8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -50,12 +50,12 @@ jobs: name: Deploy to Heroku command: | echo $HEROKU_API_KEY | docker login --username=_ --password-stdin registry.heroku.com - + workflows: version: 2 flask-ops-cicd: jobs: - - lint + - linter - build: requires: - linter From 8158d24e2702c2f3836afea64214682a625854ac Mon Sep 17 00:00:00 2001 From: Igor Smirnov Date: Sun, 28 Jun 2020 13:19:12 +0300 Subject: [PATCH 15/39] Fix workflow --- .circleci/config.yml | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ae5f3b8..ecf8f18 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -26,22 +26,16 @@ jobs: - run: name: Build Docker Image command: | - docker build --build-arg salt=${SECRET_SALT} -t registry.heroku.com/flask-ops:${CIRCLE_SHA1} . + docker build --build-arg salt=${SECRET_SALT} -t registry.heroku.com/${HEROKU_APP_NAME}:${CIRCLE_SHA1}/web . + - run: + name: Tests + command: | + docker run --rm -it registry.heroku.com/${HEROKU_APP_NAME}:${CIRCLE_SHA1} python tests.py - run: name: Push Docker Image to Heroku Registry command: | echo $HEROKU_API_KEY | docker login --username=_ --password-stdin registry.heroku.com - docker push registry.heroku.com/flask-ops:${CIRCLE_SHA1} - tests: - machine: true - steps: - - checkout - - run: - name: Unit tests - command: | - echo $HEROKU_API_KEY | docker login --username=_ --password-stdin registry.heroku.com - docker pull registry.heroku.com/flask-ops:${CIRCLE_SHA1} - docker run --rm -it registry.heroku.com/flask-ops:${CIRCLE_SHA1} python tests.py + docker push registry.heroku.com/${HEROKU_APP_NAME}:${CIRCLE_SHA1}/web deploy: machine: true steps: @@ -50,7 +44,7 @@ jobs: name: Deploy to Heroku command: | echo $HEROKU_API_KEY | docker login --username=_ --password-stdin registry.heroku.com - + docker push registry.heroku.com/${HEROKU_APP_NAME}:${CIRCLE_SHA1}/web workflows: version: 2 flask-ops-cicd: @@ -59,6 +53,6 @@ workflows: - build: requires: - linter - - tests: + - deploy: requires: - - build + - tests From b6917f8d6396020edad6c5385e3eca258204b5eb Mon Sep 17 00:00:00 2001 From: Igor Smirnov Date: Sun, 28 Jun 2020 13:20:28 +0300 Subject: [PATCH 16/39] Fix workflow --- .circleci/config.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ecf8f18..c5ea7d5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -53,6 +53,4 @@ workflows: - build: requires: - linter - - deploy: - requires: - - tests + - deploy From c2136a92470c08a3fa7773f9f18ad3dfe0e0ce0d Mon Sep 17 00:00:00 2001 From: Igor Smirnov Date: Sun, 28 Jun 2020 13:21:44 +0300 Subject: [PATCH 17/39] Fix workflow --- .circleci/config.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c5ea7d5..064dc31 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -53,4 +53,6 @@ workflows: - build: requires: - linter - - deploy + - deploy: + requires: + - build From 0e1fd8fe3b94df1ee5700675dfa18db3e3c2b6c0 Mon Sep 17 00:00:00 2001 From: Igor Smirnov Date: Sun, 28 Jun 2020 13:26:57 +0300 Subject: [PATCH 18/39] Fix workflow --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 064dc31..bc81de9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -26,11 +26,11 @@ jobs: - run: name: Build Docker Image command: | - docker build --build-arg salt=${SECRET_SALT} -t registry.heroku.com/${HEROKU_APP_NAME}:${CIRCLE_SHA1}/web . + docker build --build-arg salt=${SECRET_SALT} -t registry.heroku.com/$flask-ops:${CIRCLE_SHA1}/web . - run: name: Tests command: | - docker run --rm -it registry.heroku.com/${HEROKU_APP_NAME}:${CIRCLE_SHA1} python tests.py + docker run --rm -it registry.heroku.com/${HEROKU_APP_NAME}:${CIRCLE_SHA1}/web python tests.py - run: name: Push Docker Image to Heroku Registry command: | From f533a272e05958cf45511986eb71a7a4167e695f Mon Sep 17 00:00:00 2001 From: Igor Smirnov Date: Sun, 28 Jun 2020 13:28:18 +0300 Subject: [PATCH 19/39] Fix workflow --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index bc81de9..f347a41 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -26,7 +26,7 @@ jobs: - run: name: Build Docker Image command: | - docker build --build-arg salt=${SECRET_SALT} -t registry.heroku.com/$flask-ops:${CIRCLE_SHA1}/web . + docker build --build-arg salt=${SECRET_SALT} -t registry.heroku.com/flask-ops:${CIRCLE_SHA1}/web . - run: name: Tests command: | From b064a95d1338d5bf5951488cac4d3c695d99444e Mon Sep 17 00:00:00 2001 From: Igor Smirnov Date: Sun, 28 Jun 2020 13:31:21 +0300 Subject: [PATCH 20/39] Fix workflow --- .circleci/config.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index f347a41..5313250 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -26,16 +26,16 @@ jobs: - run: name: Build Docker Image command: | - docker build --build-arg salt=${SECRET_SALT} -t registry.heroku.com/flask-ops:${CIRCLE_SHA1}/web . + docker build --build-arg salt=${SECRET_SALT} -t registry.heroku.com/${HEROKU_APP_NAME}/web . - run: name: Tests command: | - docker run --rm -it registry.heroku.com/${HEROKU_APP_NAME}:${CIRCLE_SHA1}/web python tests.py + docker run --rm -it registry.heroku.com/${HEROKU_APP_NAME}/web python tests.py - run: name: Push Docker Image to Heroku Registry command: | echo $HEROKU_API_KEY | docker login --username=_ --password-stdin registry.heroku.com - docker push registry.heroku.com/${HEROKU_APP_NAME}:${CIRCLE_SHA1}/web + docker push registry.heroku.com/${HEROKU_APP_NAME}/web deploy: machine: true steps: From 8c04c4d8136f9fbf989dd943d189bb0faadc0913 Mon Sep 17 00:00:00 2001 From: Igor Smirnov Date: Sun, 28 Jun 2020 13:50:33 +0300 Subject: [PATCH 21/39] Fix workflow --- .circleci/config.yml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5313250..ce5f614 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -43,8 +43,17 @@ jobs: - run: name: Deploy to Heroku command: | - echo $HEROKU_API_KEY | docker login --username=_ --password-stdin registry.heroku.com - docker push registry.heroku.com/${HEROKU_APP_NAME}:${CIRCLE_SHA1}/web + wget https://cli-assets.heroku.com/branches/stable/heroku-linux-amd64.tar.gz + sudo mkdir -p /usr/local/lib /usr/local/bin + sudo tar -xvzf heroku-linux-amd64.tar.gz -C /usr/local/lib + sudo ln -s /usr/local/lib/heroku/bin/heroku /usr/local/bin/heroku + + cat > ~/.netrc << EOF + machine api.heroku.com + login $HEROKU_LOGIN + password $HEROKU_API_KEY + EOF + heroku container:${HEROKU_APP_NAME} release workflows: version: 2 flask-ops-cicd: From 589c935edc224b01115aca82589510a034567f99 Mon Sep 17 00:00:00 2001 From: Igor Smirnov Date: Sun, 28 Jun 2020 13:53:33 +0300 Subject: [PATCH 22/39] Fix workflow --- .circleci/config.yml | 11 +---------- setup-heroku.sh | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 10 deletions(-) create mode 100644 setup-heroku.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index ce5f614..fcebda1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -43,16 +43,7 @@ jobs: - run: name: Deploy to Heroku command: | - wget https://cli-assets.heroku.com/branches/stable/heroku-linux-amd64.tar.gz - sudo mkdir -p /usr/local/lib /usr/local/bin - sudo tar -xvzf heroku-linux-amd64.tar.gz -C /usr/local/lib - sudo ln -s /usr/local/lib/heroku/bin/heroku /usr/local/bin/heroku - - cat > ~/.netrc << EOF - machine api.heroku.com - login $HEROKU_LOGIN - password $HEROKU_API_KEY - EOF + bash setup-heroku.sh heroku container:${HEROKU_APP_NAME} release workflows: version: 2 diff --git a/setup-heroku.sh b/setup-heroku.sh new file mode 100644 index 0000000..e030d78 --- /dev/null +++ b/setup-heroku.sh @@ -0,0 +1,15 @@ +#!/bin/bash +git remote add heroku https://git.heroku.com/circleci-demo-python-flask.git +wget https://cli-assets.heroku.com/branches/stable/heroku-linux-amd64.tar.gz +sudo mkdir -p /usr/local/lib /usr/local/bin +sudo tar -xvzf heroku-linux-amd64.tar.gz -C /usr/local/lib +sudo ln -s /usr/local/lib/heroku/bin/heroku /usr/local/bin/heroku + +cat > ~/.netrc << EOF +machine api.heroku.com + login $HEROKU_LOGIN + password $HEROKU_API_KEY +machine git.heroku.com + login $HEROKU_LOGIN + password $HEROKU_API_KEY +EOF \ No newline at end of file From 8d16646d853b68d87fcb55fb85a751d458e2807f Mon Sep 17 00:00:00 2001 From: Igor Smirnov Date: Sun, 28 Jun 2020 14:24:39 +0300 Subject: [PATCH 23/39] Fix workflow --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index fcebda1..51dab20 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -44,7 +44,7 @@ jobs: name: Deploy to Heroku command: | bash setup-heroku.sh - heroku container:${HEROKU_APP_NAME} release + heroku container:push web --app ${HEROKU_APP_NAME} workflows: version: 2 flask-ops-cicd: From ddee17911e5a346e245c68d79734a92c60fafcaa Mon Sep 17 00:00:00 2001 From: Igor Smirnov Date: Sun, 28 Jun 2020 14:28:31 +0300 Subject: [PATCH 24/39] Fix workflow --- .circleci/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 51dab20..c41a662 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -44,6 +44,7 @@ jobs: name: Deploy to Heroku command: | bash setup-heroku.sh + echo $HEROKU_API_KEY | docker login --username=_ --password-stdin registry.heroku.com heroku container:push web --app ${HEROKU_APP_NAME} workflows: version: 2 From 568c3a3359fc68b1825a0f888a7daae355ef24f8 Mon Sep 17 00:00:00 2001 From: Igor Smirnov Date: Sun, 28 Jun 2020 14:34:31 +0300 Subject: [PATCH 25/39] Fix workflow --- .circleci/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index c41a662..05e7aca 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -46,6 +46,7 @@ jobs: bash setup-heroku.sh echo $HEROKU_API_KEY | docker login --username=_ --password-stdin registry.heroku.com heroku container:push web --app ${HEROKU_APP_NAME} + heroku container:release web workflows: version: 2 flask-ops-cicd: From e09e415da6a7e01d10ed9b07759c562d9e73cca1 Mon Sep 17 00:00:00 2001 From: Igor Smirnov Date: Sun, 28 Jun 2020 14:40:25 +0300 Subject: [PATCH 26/39] Fix workflow --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 05e7aca..fbe2133 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -46,7 +46,7 @@ jobs: bash setup-heroku.sh echo $HEROKU_API_KEY | docker login --username=_ --password-stdin registry.heroku.com heroku container:push web --app ${HEROKU_APP_NAME} - heroku container:release web + heroku container:release web --app ${HEROKU_APP_NAME} workflows: version: 2 flask-ops-cicd: From 9b927cc803f78a1be1cc1fd06536c1349cc37997 Mon Sep 17 00:00:00 2001 From: Igor Smirnov Date: Sun, 28 Jun 2020 15:01:13 +0300 Subject: [PATCH 27/39] Fix workflow --- start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/start.sh b/start.sh index 03ea61d..cdee207 100644 --- a/start.sh +++ b/start.sh @@ -1,4 +1,4 @@ #!/bin/bash export FLASK_APP=app.py -flask run --host=0.0.0.0 +flask run --host=0.0.0.0 --port=5000 From d9bbe0049f69f521bbb161161a24e81537a27d6f Mon Sep 17 00:00:00 2001 From: Igor Smirnov Date: Sun, 28 Jun 2020 15:13:31 +0300 Subject: [PATCH 28/39] Fix workflow --- start.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/start.sh b/start.sh index cdee207..a600437 100644 --- a/start.sh +++ b/start.sh @@ -1,4 +1,9 @@ #!/bin/bash export FLASK_APP=app.py -flask run --host=0.0.0.0 --port=5000 +if [ -z "$PORT" ] +then + flask run --host=0.0.0.0 --port=5000 +else + flask run --host=0.0.0.0 --port="$PORT" +fi \ No newline at end of file From 6c13dc9080a2875d464be311fc02c13ba166ae9e Mon Sep 17 00:00:00 2001 From: Igor Smirnov Date: Sun, 28 Jun 2020 17:16:36 +0300 Subject: [PATCH 29/39] Add integration test --- .circleci/config.yml | 17 +++++++++++++++-- app.py | 11 +++++------ requirements.txt | 3 ++- tests.py | 4 ++++ tests/conftest.py | 23 +++++++++++++++++++++++ tests/test_app.py | 3 +++ 6 files changed, 52 insertions(+), 9 deletions(-) create mode 100644 tests/conftest.py create mode 100644 tests/test_app.py diff --git a/.circleci/config.yml b/.circleci/config.yml index fbe2133..79e6c54 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -18,7 +18,21 @@ jobs: name: Run Linter command: | . flaskops/bin/activate - pylint --load-plugins pylint_flask --fail-under=7 app.py + pylint --load-plugins pylint_flask --fail-under=7 app.py tests.py + unittests: + docker: + - image: circleci/python:3.7.4 + steps: + - checkout + - run: + name: Run unittests + command: | + python tests.py + - store_artifacts: + path: test-reports/ + destination: tr:${CIRCLE_SHA1} + - store_test_results: + path: test-reports/ build: machine: true steps: @@ -45,7 +59,6 @@ jobs: command: | bash setup-heroku.sh echo $HEROKU_API_KEY | docker login --username=_ --password-stdin registry.heroku.com - heroku container:push web --app ${HEROKU_APP_NAME} heroku container:release web --app ${HEROKU_APP_NAME} workflows: version: 2 diff --git a/app.py b/app.py index 8cfb01c..67ed165 100644 --- a/app.py +++ b/app.py @@ -3,10 +3,10 @@ ### Customer session key generator. Protects PII. ### / 2020 """ +import hashlib import os -import string import secrets -import hashlib +import string from flask import Flask @@ -21,12 +21,11 @@ def encrypt_string(hash_string): return sha_signature -def generate(): +def generate(salt): rand_device = string.ascii_letters + string.digits - return encrypt_string((''.join(secrets.choice(rand_device) - for i in range(8))).join(SUPER_SECRET_SALT)) + return encrypt_string((''.join(secrets.choice(rand_device) for i in range(8))).join(salt)) @app.route('/') def signature(): - return generate() + return generate(SUPER_SECRET_SALT) diff --git a/requirements.txt b/requirements.txt index ddd67a8..17b49c7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ flask -pylint-flask \ No newline at end of file +pylint-flask +pytest \ No newline at end of file diff --git a/tests.py b/tests.py index c020754..5d373c3 100644 --- a/tests.py +++ b/tests.py @@ -21,3 +21,7 @@ def test_encrypt_string_lower_block_size(self): def test_encrypt_string_equal_block_size(self): self.assertEqual(encrypt_string('a' * 64), 'ffe054fe7ae0cb6dc65c3af9b61d5209f439851db43d0ba5997337df154668eb') + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..decf752 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,23 @@ +import os + +import pytest +from flask import Flask + +from app import generate + + +@pytest.fixture() +def app(): + app = Flask(__name__) + + test_salt = os.environ.get('TEST_SALT') + + @app.route('/') + def signature(): + return generate(test_salt) + return app + + +@pytest.fixture +def client(app): + return app.test_client() diff --git a/tests/test_app.py b/tests/test_app.py new file mode 100644 index 0000000..59ad3e3 --- /dev/null +++ b/tests/test_app.py @@ -0,0 +1,3 @@ +def test_health(app, client): + res = client.get('/') + assert res.status_code == 200 From 6ef66515f200f444eb938308e90f13bad31bda66 Mon Sep 17 00:00:00 2001 From: Igor Smirnov Date: Sun, 28 Jun 2020 17:19:04 +0300 Subject: [PATCH 30/39] Fix workflow --- .circleci/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 79e6c54..9cd1844 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -65,6 +65,7 @@ workflows: flask-ops-cicd: jobs: - linter + - unittests - build: requires: - linter From 41f952e4dd3f575964e67b0fc07e872df9fbe9a2 Mon Sep 17 00:00:00 2001 From: Igor Smirnov Date: Sun, 28 Jun 2020 17:21:19 +0300 Subject: [PATCH 31/39] Fix workflow --- .circleci/config.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9cd1844..04dee80 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -24,6 +24,10 @@ jobs: - image: circleci/python:3.7.4 steps: - checkout + - run: + name: Install python dependencies + command: | + pip install --no-cache-dir -r requirements.txt - run: name: Run unittests command: | From b758533d9d533f2a75497398a730cc0b18e91b43 Mon Sep 17 00:00:00 2001 From: Igor Smirnov Date: Sun, 28 Jun 2020 17:24:29 +0300 Subject: [PATCH 32/39] Fix workflow --- .circleci/config.yml | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 04dee80..b0091d0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,6 +1,6 @@ version: 2.1 jobs: - linter: + tests: docker: - image: circleci/python:3.7.4 steps: @@ -19,18 +19,10 @@ jobs: command: | . flaskops/bin/activate pylint --load-plugins pylint_flask --fail-under=7 app.py tests.py - unittests: - docker: - - image: circleci/python:3.7.4 - steps: - - checkout - run: - name: Install python dependencies - command: | - pip install --no-cache-dir -r requirements.txt - - run: - name: Run unittests + name: Run Unit tests command: | + . flaskops/bin/activate python tests.py - store_artifacts: path: test-reports/ @@ -46,9 +38,9 @@ jobs: command: | docker build --build-arg salt=${SECRET_SALT} -t registry.heroku.com/${HEROKU_APP_NAME}/web . - run: - name: Tests + name: Integration Tests command: | - docker run --rm -it registry.heroku.com/${HEROKU_APP_NAME}/web python tests.py + docker run --rm -it registry.heroku.com/${HEROKU_APP_NAME}/web python -m pytest -vv - run: name: Push Docker Image to Heroku Registry command: | @@ -68,11 +60,10 @@ workflows: version: 2 flask-ops-cicd: jobs: - - linter - - unittests + - tests - build: requires: - - linter + - tests - deploy: requires: - build From ebf306adca5d23b8a81497e3e7b26a9257522177 Mon Sep 17 00:00:00 2001 From: Igor Smirnov Date: Sun, 28 Jun 2020 17:34:23 +0300 Subject: [PATCH 33/39] Fix workflow --- .circleci/config.yml | 2 +- Dockerfile | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index b0091d0..a909667 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -36,7 +36,7 @@ jobs: - run: name: Build Docker Image command: | - docker build --build-arg salt=${SECRET_SALT} -t registry.heroku.com/${HEROKU_APP_NAME}/web . + docker build --build-arg secret_salt=${SECRET_SALT} test_salt=${TEST_SALT} -t registry.heroku.com/${HEROKU_APP_NAME}/web . - run: name: Integration Tests command: | diff --git a/Dockerfile b/Dockerfile index 928da03..1b9d8ea 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,8 @@ FROM python:3.7 -ARG salt -ENV SALT=$salt +ARG secret_salt +ARG test_salt +ENV SALT=$secret_salt +ENV TEST_SALT=$test_salt ENV PYTHONUNBUFFERED=1 ENV PYTHONDONTWRITEBYTECODE=1 RUN mkdir /flask-app From da62d8cc4fe53f6445cabde5a4502cd4dd6f7c9f Mon Sep 17 00:00:00 2001 From: Igor Smirnov Date: Sun, 28 Jun 2020 17:38:47 +0300 Subject: [PATCH 34/39] Fix workflow --- .circleci/config.yml | 2 +- Dockerfile | 2 -- tests/conftest.py | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a909667..8a00c2a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -36,7 +36,7 @@ jobs: - run: name: Build Docker Image command: | - docker build --build-arg secret_salt=${SECRET_SALT} test_salt=${TEST_SALT} -t registry.heroku.com/${HEROKU_APP_NAME}/web . + docker build --build-arg secret_salt=${SECRET_SALT} -t registry.heroku.com/${HEROKU_APP_NAME}/web . - run: name: Integration Tests command: | diff --git a/Dockerfile b/Dockerfile index 1b9d8ea..247ef0e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,6 @@ FROM python:3.7 ARG secret_salt -ARG test_salt ENV SALT=$secret_salt -ENV TEST_SALT=$test_salt ENV PYTHONUNBUFFERED=1 ENV PYTHONDONTWRITEBYTECODE=1 RUN mkdir /flask-app diff --git a/tests/conftest.py b/tests/conftest.py index decf752..e0f1a83 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -10,7 +10,7 @@ def app(): app = Flask(__name__) - test_salt = os.environ.get('TEST_SALT') + test_salt = 124325246546379565 @app.route('/') def signature(): From bdf9597f1887f28295bbf227dbf956a033633843 Mon Sep 17 00:00:00 2001 From: Igor Smirnov Date: Sun, 28 Jun 2020 17:46:12 +0300 Subject: [PATCH 35/39] Fix conftest --- tests/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index e0f1a83..ec0b280 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -10,7 +10,7 @@ def app(): app = Flask(__name__) - test_salt = 124325246546379565 + test_salt = "124325246546379565" @app.route('/') def signature(): From ec208907160d97dd3d4d97e74cc59b03e02a8741 Mon Sep 17 00:00:00 2001 From: Igor Smirnov Date: Sun, 28 Jun 2020 21:39:38 +0300 Subject: [PATCH 36/39] Add tests --- setup-heroku.sh => .circleci/setup-heroku.sh | 0 tests/conftest.py | 6 ++++-- tests/test_app.py | 12 ++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) rename setup-heroku.sh => .circleci/setup-heroku.sh (100%) diff --git a/setup-heroku.sh b/.circleci/setup-heroku.sh similarity index 100% rename from setup-heroku.sh rename to .circleci/setup-heroku.sh diff --git a/tests/conftest.py b/tests/conftest.py index ec0b280..0f6e6fd 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,5 +1,3 @@ -import os - import pytest from flask import Flask @@ -18,6 +16,10 @@ def signature(): return app +@pytest.fixture() +def request_qty(): + return 1 + @pytest.fixture def client(app): return app.test_client() diff --git a/tests/test_app.py b/tests/test_app.py index 59ad3e3..a2fbbf6 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -1,3 +1,15 @@ +import pytest + + def test_health(app, client): res = client.get('/') assert res.status_code == 200 + + +@pytest.mark.parametrize('request_qty', [1, 10, 20, 50]) +def test_uniq_responses(app, client, request_qty): + responses = set() + for request in range(request_qty): + res = client.get('/') + responses.add(res.data) + assert len(responses) == request_qty From c0be80d2e46e105844845ec3ed28dccc07155e54 Mon Sep 17 00:00:00 2001 From: Igor Smirnov Date: Sun, 28 Jun 2020 21:50:09 +0300 Subject: [PATCH 37/39] Fix deployment script path --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 8a00c2a..af40948 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -53,7 +53,7 @@ jobs: - run: name: Deploy to Heroku command: | - bash setup-heroku.sh + bash .circleci/setup-heroku.sh echo $HEROKU_API_KEY | docker login --username=_ --password-stdin registry.heroku.com heroku container:release web --app ${HEROKU_APP_NAME} workflows: From 584c5defaa1c61675a6f7a000601f25060daf2ca Mon Sep 17 00:00:00 2001 From: Igor Smirnov Date: Mon, 29 Jun 2020 01:20:54 +0300 Subject: [PATCH 38/39] Fix scripts --- start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/start.sh b/start.sh index a600437..95bad94 100644 --- a/start.sh +++ b/start.sh @@ -6,4 +6,4 @@ then flask run --host=0.0.0.0 --port=5000 else flask run --host=0.0.0.0 --port="$PORT" -fi \ No newline at end of file +fi From 8cd828e161cdd31982cbee1061752256daf35f3b Mon Sep 17 00:00:00 2001 From: Igor Smirnov Date: Mon, 29 Jun 2020 01:21:59 +0300 Subject: [PATCH 39/39] Fix scripts --- .circleci/setup-heroku.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/setup-heroku.sh b/.circleci/setup-heroku.sh index e030d78..2ae7ef7 100644 --- a/.circleci/setup-heroku.sh +++ b/.circleci/setup-heroku.sh @@ -12,4 +12,4 @@ machine api.heroku.com machine git.heroku.com login $HEROKU_LOGIN password $HEROKU_API_KEY -EOF \ No newline at end of file +EOF