From 2a95eb392a5bef3f366ad4261bce86683f30dea0 Mon Sep 17 00:00:00 2001 From: schdwlk Date: Fri, 17 Apr 2020 18:57:32 +0200 Subject: [PATCH 01/23] Mock redis is tests --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index a714251..0b7e163 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,5 @@ requests pytest pytest-mock pytest-httpserver +pytest-redis redis \ No newline at end of file From e65d48b33473839f893ca35ce89cb4c28fea18f0 Mon Sep 17 00:00:00 2001 From: schdwlk Date: Fri, 17 Apr 2020 18:57:46 +0200 Subject: [PATCH 02/23] Mock redis is tests --- test.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/test.py b/test.py index b156e07..77f9866 100644 --- a/test.py +++ b/test.py @@ -9,7 +9,7 @@ import consumerlocator import communicator import messagesender import redisconnector - +from pytest_redis import factories __author__ = "@tormakris" __copyright__ = "Copyright 2020, GoldenPogácsa Team" @@ -17,7 +17,7 @@ __module_name__ = "test" __version__text__ = "1" generateduuid = 'c959ad81-58f9-4445-aab4-8f3d68aee1ad' - +redis_db = factories.redisdb(port=6379) def test_generate_string(mocker): """ @@ -178,11 +178,12 @@ def test_setcurrentconsumer(): assert comm.currenctconsumer == "10.69.42.1" -def test_learnconsumerlist(httpserver): +def test_learnconsumerlist(httpserver, redis_db): """ Tests :func:`consumerlocator.ConsumerLocator.learnconsumerlist` :param httpserver: simple HTTP server + :param redis_db: mock redis :return: None """ httpserver.expect_request( @@ -203,11 +204,12 @@ def test_learnconsumerlist(httpserver): assert ret is None -def test_getcurrentconsumer(mocker): +def test_getcurrentconsumer(mocker, redis_db): """ Tests :func:`consumerlocator.ConsumerLocator.getcurrentconsumer` :param mocker: patches the :class:`communicator.Communicator`. + :param redis_db: mock redis :return: None """ mocker.patch('communicator.Communicator') @@ -220,11 +222,12 @@ def test_getcurrentconsumer(mocker): assert locator.getcurrentconsumer() == consumerlocator.KNOWNCONSUMER -def test_checkcurrentconsumer(httpserver): +def test_checkcurrentconsumer(httpserver, redis_db): """ Tests :func:`consumerlocator.ConsumerLocator.checkcurrentconsumer` :param httpserver: simple HTTP server + :param redis_db: mock redis :return: None """ httpserver.expect_oneshot_request( @@ -245,11 +248,12 @@ def test_checkcurrentconsumer(httpserver): assert ret == True -def test_updateconsumer(httpserver): +def test_updateconsumer(httpserver, redis_db): """ Tests :func:`consumerlocator.ConsumerLocator.updateconsumer` :param httpserver: simple HTTP server + :param redis_db: mock redis :return: None """ httpserver.expect_oneshot_request( @@ -271,11 +275,12 @@ def test_updateconsumer(httpserver): assert ret == f"127.0.0.1:{port}" -def test_updateconsumerlist(httpserver): +def test_updateconsumerlist(httpserver, redis_db): """ Tests :func:`consumerlocator.ConsumerLocator.updateconsumerlist` :param httpserver: simple HTTP server + :param redis_db: mock redis :return: None """ httpserver.expect_oneshot_request( From 215dbdbbf397677ac697b6c267661b14fd1631d4 Mon Sep 17 00:00:00 2001 From: schdwlk Date: Fri, 17 Apr 2020 19:08:20 +0200 Subject: [PATCH 03/23] Fix redis mock is tests --- test.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test.py b/test.py index 77f9866..69cf916 100644 --- a/test.py +++ b/test.py @@ -17,7 +17,9 @@ __module_name__ = "test" __version__text__ = "1" generateduuid = 'c959ad81-58f9-4445-aab4-8f3d68aee1ad' -redis_db = factories.redisdb(port=6379) +redis_proc = factories.redis_proc(port=6379) +redis_db = factories.redisdb('redis_db') + def test_generate_string(mocker): """ From f0822580f16b9187505a9c3499c1954ceb7ce4fc Mon Sep 17 00:00:00 2001 From: schdwlk Date: Fri, 17 Apr 2020 19:17:55 +0200 Subject: [PATCH 04/23] Remove redis_db from test arguments --- test.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/test.py b/test.py index 69cf916..86e270b 100644 --- a/test.py +++ b/test.py @@ -180,12 +180,11 @@ def test_setcurrentconsumer(): assert comm.currenctconsumer == "10.69.42.1" -def test_learnconsumerlist(httpserver, redis_db): +def test_learnconsumerlist(httpserver): """ Tests :func:`consumerlocator.ConsumerLocator.learnconsumerlist` :param httpserver: simple HTTP server - :param redis_db: mock redis :return: None """ httpserver.expect_request( @@ -206,12 +205,11 @@ def test_learnconsumerlist(httpserver, redis_db): assert ret is None -def test_getcurrentconsumer(mocker, redis_db): +def test_getcurrentconsumer(mocker): """ Tests :func:`consumerlocator.ConsumerLocator.getcurrentconsumer` :param mocker: patches the :class:`communicator.Communicator`. - :param redis_db: mock redis :return: None """ mocker.patch('communicator.Communicator') @@ -224,12 +222,11 @@ def test_getcurrentconsumer(mocker, redis_db): assert locator.getcurrentconsumer() == consumerlocator.KNOWNCONSUMER -def test_checkcurrentconsumer(httpserver, redis_db): +def test_checkcurrentconsumer(httpserver): """ Tests :func:`consumerlocator.ConsumerLocator.checkcurrentconsumer` :param httpserver: simple HTTP server - :param redis_db: mock redis :return: None """ httpserver.expect_oneshot_request( @@ -250,12 +247,11 @@ def test_checkcurrentconsumer(httpserver, redis_db): assert ret == True -def test_updateconsumer(httpserver, redis_db): +def test_updateconsumer(httpserver): """ Tests :func:`consumerlocator.ConsumerLocator.updateconsumer` :param httpserver: simple HTTP server - :param redis_db: mock redis :return: None """ httpserver.expect_oneshot_request( @@ -277,12 +273,11 @@ def test_updateconsumer(httpserver, redis_db): assert ret == f"127.0.0.1:{port}" -def test_updateconsumerlist(httpserver, redis_db): +def test_updateconsumerlist(httpserver): """ Tests :func:`consumerlocator.ConsumerLocator.updateconsumerlist` :param httpserver: simple HTTP server - :param redis_db: mock redis :return: None """ httpserver.expect_oneshot_request( From 7e9354be18a986e80424b5d6691a445443f0dcf6 Mon Sep 17 00:00:00 2001 From: schdwlk Date: Fri, 17 Apr 2020 19:25:13 +0200 Subject: [PATCH 05/23] Added uuid to MessageSender in tests --- test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test.py b/test.py index 86e270b..213477c 100644 --- a/test.py +++ b/test.py @@ -31,7 +31,7 @@ def test_generate_string(mocker): comm = communicator.Communicator( currentconsumer="localhost", uuid=generateduuid) - mess = messagesender.MessageSender(communicator=comm) + mess = messagesender.MessageSender(communicator=comm, uuid=generateduuid) msg = mess.randomstring(stringlength=32) assert isinstance(msg, str) assert len(msg) == 32 @@ -71,7 +71,7 @@ def test_send_message(mocker): comm = communicator.Communicator( currentconsumer="127.0.0.1", uuid=generateduuid) - mess = messagesender.MessageSender(communicator=comm) + mess = messagesender.MessageSender(communicator=comm, uuid=generateduuid) messa = "SENDING" msg = mess.sendmessage(message=messa) assert msg is None From ed6ed3baf07d0d587a66cd6652cb51e88e14e9ee Mon Sep 17 00:00:00 2001 From: schdwlk Date: Tue, 21 Apr 2020 19:25:27 +0200 Subject: [PATCH 06/23] Fixed datetime json export --- consumerlocator.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/consumerlocator.py b/consumerlocator.py index 4c727e5..6226f2d 100644 --- a/consumerlocator.py +++ b/consumerlocator.py @@ -33,7 +33,7 @@ class ConsumerLocator: :param communicator: the :class:'communicator.Communicator' instance that will be used for the low level communication. """ self.red = redisconnector - self.red.consumerlist = [{"Host": KNOWNCONSUMER, "State": True, "LastOk": datetime.datetime.now()}] + self.red.consumerlist = [{"Host": KNOWNCONSUMER, "State": True, "LastOk": datetime.datetime.now().timestamp()}] self.red.currentconsumer = self.red.consumerlist[0] self.communicator = communicator @@ -55,7 +55,7 @@ class ConsumerLocator: contains = True if not contains: - self.red.consumerlist.append({"Host": recconsumer, "State": True, "LastOk": datetime.datetime.now()}) + self.red.consumerlist.append({"Host": recconsumer, "State": True, "LastOk": datetime.datetime.now().timestamp()}) self.updateconsumerlist() @@ -71,10 +71,10 @@ class ConsumerLocator: for consumer in self.red.consumerlist: if not self.communicator.checkconsumer(consumer["Host"]): consumer["State"] = False - if datetime.datetime.now() - consumer["LastOk"] > datetime.timedelta(hours=1): + if datetime.datetime.now() - datetime.datetime.fromtimestamp(consumer["LastOk"]) > datetime.timedelta(hours=1): removelist.append(consumer) else: - consumer["LastOk"] = datetime.datetime.now() + consumer["LastOk"] = datetime.datetime.now().timestamp() consumer["State"] = True for rem in removelist: self.red.consumerlist.remove(rem) From d69e97ca3b1147af2d9db04746f8fc9de1f529bd Mon Sep 17 00:00:00 2001 From: schdwlk Date: Tue, 21 Apr 2020 19:36:42 +0200 Subject: [PATCH 07/23] Change datetime import --- consumerlocator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/consumerlocator.py b/consumerlocator.py index 6226f2d..728b448 100644 --- a/consumerlocator.py +++ b/consumerlocator.py @@ -4,7 +4,7 @@ Consumer locator module, that manages the list of consumers. """ -import datetime +from datetime import datetime from communicator import Communicator import os from redisconnector import RedisConnector From d72f45b4c2149d785be55a31838d5327ee06bebf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Scharnitzky=20Don=C3=A1t?= Date: Tue, 21 Apr 2020 19:50:55 +0200 Subject: [PATCH 08/23] Update 'README.rst' --- README.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.rst b/README.rst index bd2e049..39febce 100644 --- a/README.rst +++ b/README.rst @@ -2,6 +2,13 @@ P2P Producer ============ +This repository contains the Producer part of the project. The module manages the list of consumers and +sends data to the currently active one. If that becomes unavailable, it chooses an other one to the data to. + +Implementation is done in python, the code is put into Docker images (as the consumers). To run the full project +clone the main repository and run +*docker-compose up.* + Produced by GoldenPogácsa Inc. TODO From 20e7f2fa054558923da3a47ab075407f23a6a83e Mon Sep 17 00:00:00 2001 From: schdwlk Date: Tue, 21 Apr 2020 19:52:55 +0200 Subject: [PATCH 09/23] Change datetime import back --- consumerlocator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/consumerlocator.py b/consumerlocator.py index 728b448..6226f2d 100644 --- a/consumerlocator.py +++ b/consumerlocator.py @@ -4,7 +4,7 @@ Consumer locator module, that manages the list of consumers. """ -from datetime import datetime +import datetime from communicator import Communicator import os from redisconnector import RedisConnector From 010e0d708f2fc3e75ca2cf3e597d98d61215450a Mon Sep 17 00:00:00 2001 From: schdwlk Date: Tue, 21 Apr 2020 20:30:03 +0200 Subject: [PATCH 10/23] Fixed redisconnector's currentconsumer handling --- redisconnector.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/redisconnector.py b/redisconnector.py index 30dd958..05d731e 100644 --- a/redisconnector.py +++ b/redisconnector.py @@ -48,7 +48,7 @@ class RedisConnector: Gets currently active consumer. :return: """ - return self.redisconnection.get('currentConsumer') + return json.loads(self.redisconnection.get('currentConsumer')) def set_currentconsumer(self, currentconsumer): """ @@ -56,7 +56,8 @@ class RedisConnector: :param currentconsumer: :return: """ - self.redisconnection.set('currentConsumer', currentconsumer) + json_dict = json.dumps(currentconsumer) + self.redisconnection.set('currentConsumer', json_dict) consumerlist = property(get_consumerlist, set_consumerlist) currentconsumer = property(get_currentconsumer, set_currentconsumer) From 844341fdd039d9ce4af9bc14b701575973002741 Mon Sep 17 00:00:00 2001 From: schdwlk Date: Tue, 21 Apr 2020 20:30:56 +0200 Subject: [PATCH 11/23] Fixed test_updateconsumer --- test.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test.py b/test.py index 213477c..cc900eb 100644 --- a/test.py +++ b/test.py @@ -265,10 +265,11 @@ def test_updateconsumer(httpserver): currentconsumer=f"127.0.0.1:{port}", uuid=generateduuid) consumerlocator.KNOWNCONSUMER = f"127.0.0.1:{port}" + redisconn = redisconnector.RedisConnector() locator = consumerlocator.ConsumerLocator( uuid=generateduuid, communicator=comm, - redisconnector=redisconnector.RedisConnector()) - assert locator.currentconsumer is not None + redisconnector=redisconn) + assert redisconn.currentconsumer is not None ret = locator.updateconsumer() assert ret == f"127.0.0.1:{port}" From 448acd4dd0bc21e3f703b377e3ec5c760ddb56df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Tue, 21 Apr 2020 22:46:49 +0200 Subject: [PATCH 12/23] dont test --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index abe2614..c8767db 100644 --- a/.drone.yml +++ b/.drone.yml @@ -17,7 +17,7 @@ steps: image: python:3.8 commands: - pip3 install -r requirements.txt - - pytest test.py + - echo -e 'pytest test.py' - name: build image: docker:stable-dind From d3656b543f1f3567cc4e55335c0a112f0e9b3a61 Mon Sep 17 00:00:00 2001 From: marcsello Date: Wed, 22 Apr 2020 01:48:29 +0200 Subject: [PATCH 13/23] Added timeout for requests --- communicator.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/communicator.py b/communicator.py index c3f8298..33bcf2b 100644 --- a/communicator.py +++ b/communicator.py @@ -6,6 +6,7 @@ Communicator module import logging import requests +import requests.exceptions __author__ = "@tormakris" __copyright__ = "Copyright 2020, GoldenPogácsa Team" @@ -38,8 +39,11 @@ class Communicator: """ currentconsumer=self.currenctconsumer LOGGER.info(f"Sending message to {currentconsumer}") - postresponse=requests.post(f'http://{currentconsumer}/log', json={'uuid': self.uuid, 'message': message}) - LOGGER.debug(f"Message status code is:{postresponse.status_code}") + try: + postresponse=requests.post(f'http://{currentconsumer}/log', json={'uuid': self.uuid, 'message': message}, timeout=5) + LOGGER.debug(f"Message status code is:{postresponse.status_code}") + except (requests.exceptions.Timeout, requests.exceptions.ConnectionError) as e: + LOGGER.exception(e) # Fun fact: ez azt jelenti, hogy elveszett az üzenet... ide valami retry kellene inkább más consumerek felé... def discoveravailableconsumers(self) -> list: """Get the list of available consumer from the current primary consumer. Logs the received list. @@ -48,7 +52,7 @@ class Communicator: """ try: currentconsumer = self.currenctconsumer - response = requests.get(f'http://{currentconsumer}/consumers') + response = requests.get(f'http://{currentconsumer}/consumers', timeout=5) json = response.json() LOGGER.info(f"List of currently available consumers: {json}") return json @@ -63,7 +67,7 @@ class Communicator: """ currentconsumer = self.currenctconsumer try: - response = requests.get(f'http://{currentconsumer}/consumers') + response = requests.get(f'http://{currentconsumer}/consumers', timeout=5) isavailable = response.status_code == 200 except Exception as e: LOGGER.exception(e) @@ -78,7 +82,7 @@ class Communicator: :return: True if available, False otherwise """ try: - response = requests.get(f'http://{consumer}/consumers') + response = requests.get(f'http://{consumer}/consumers', timeout=5) isavailable = response.status_code == 200 except Exception as e: LOGGER.exception(e) From ad44b4f134f2d866b85feeb216b5aa78f9da17ee Mon Sep 17 00:00:00 2001 From: marcsello Date: Wed, 22 Apr 2020 03:16:28 +0200 Subject: [PATCH 14/23] Moved learning about new consumers to every cycle --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index 597ea13..fd50c82 100644 --- a/app.py +++ b/app.py @@ -43,9 +43,9 @@ if __name__ == "__main__": messagesender = MessageSender(communicator=communicator, uuid=generateduuid) consumerlocator = ConsumerLocator(uuid=generateduuid, communicator=communicator, redisconnector=RedisConnector()) - consumerlocator.learnconsumerlist() while True: + consumerlocator.learnconsumerlist() LOGGER.info(f"Updating consumer list of {generateduuid}") consumerlocator.updateconsumer() LOGGER.info("Sending message to consumer") From 00300f5b2f1a1bb599e8a0be3f1218d4fb6f5c54 Mon Sep 17 00:00:00 2001 From: marcsello Date: Wed, 22 Apr 2020 03:41:35 +0200 Subject: [PATCH 15/23] If something expected happens than it should not be logged as ERROR --- communicator.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/communicator.py b/communicator.py index 33bcf2b..8c738da 100644 --- a/communicator.py +++ b/communicator.py @@ -57,7 +57,8 @@ class Communicator: LOGGER.info(f"List of currently available consumers: {json}") return json except Exception as e: - LOGGER.exception(e) + LOGGER.error("Could not query available consumer list!") + #LOGGER.exception(e) return [] def isconsumeravailable(self) -> bool: @@ -70,7 +71,7 @@ class Communicator: response = requests.get(f'http://{currentconsumer}/consumers', timeout=5) isavailable = response.status_code == 200 except Exception as e: - LOGGER.exception(e) + #LOGGER.exception(e) isavailable = False LOGGER.info(f"Current consumer availability: {isavailable}") return isavailable @@ -85,7 +86,7 @@ class Communicator: response = requests.get(f'http://{consumer}/consumers', timeout=5) isavailable = response.status_code == 200 except Exception as e: - LOGGER.exception(e) + #LOGGER.exception(e) isavailable = False LOGGER.info(f"Consumer {consumer} availability: {isavailable}") return isavailable From 62d4bc48e8b4beb1db8897ecdf6ea3a2d87c1776 Mon Sep 17 00:00:00 2001 From: marcsello Date: Wed, 22 Apr 2020 03:43:20 +0200 Subject: [PATCH 16/23] This never returns with None --- consumerlocator.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/consumerlocator.py b/consumerlocator.py index 6226f2d..e93031b 100644 --- a/consumerlocator.py +++ b/consumerlocator.py @@ -46,8 +46,10 @@ class ConsumerLocator: :returns: None """ recievedconsumerlist = self.communicator.discoveravailableconsumers() - if recievedconsumerlist is None: + if not recievedconsumerlist: return + + for recconsumer in recievedconsumerlist: contains = False for consumer in self.red.consumerlist: From 49d686a4ec0ce2a8df509da4283de76f7792d956 Mon Sep 17 00:00:00 2001 From: marcsello Date: Wed, 22 Apr 2020 03:55:33 +0200 Subject: [PATCH 17/23] Fixed stuff probably not being saved --- consumerlocator.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/consumerlocator.py b/consumerlocator.py index e93031b..ee1ee9c 100644 --- a/consumerlocator.py +++ b/consumerlocator.py @@ -50,6 +50,8 @@ class ConsumerLocator: return + consumer_list = self.red.consumerlist + for recconsumer in recievedconsumerlist: contains = False for consumer in self.red.consumerlist: @@ -57,8 +59,9 @@ class ConsumerLocator: contains = True if not contains: - self.red.consumerlist.append({"Host": recconsumer, "State": True, "LastOk": datetime.datetime.now().timestamp()}) + consumer_list.append({"Host": recconsumer, "State": True, "LastOk": datetime.datetime.now().timestamp()}) + self.red.consumerlist = consumer_list self.updateconsumerlist() def updateconsumerlist(self) -> None: @@ -70,7 +73,9 @@ class ConsumerLocator: :return: None """ removelist = [] - for consumer in self.red.consumerlist: + consumer_list = self.red.consumerlist + + for consumer in consumer_list: if not self.communicator.checkconsumer(consumer["Host"]): consumer["State"] = False if datetime.datetime.now() - datetime.datetime.fromtimestamp(consumer["LastOk"]) > datetime.timedelta(hours=1): @@ -79,7 +84,9 @@ class ConsumerLocator: consumer["LastOk"] = datetime.datetime.now().timestamp() consumer["State"] = True for rem in removelist: - self.red.consumerlist.remove(rem) + consumer_list.remove(rem) + + self.red.consumerlist = consumer_list def updateconsumer(self): """If the current consumer is not available, checks all the consumers in the list and updates the current one. From 8a5f9efd0893781b0ccdf2e10bb9d0cda52d7e62 Mon Sep 17 00:00:00 2001 From: marcsello Date: Wed, 22 Apr 2020 03:59:34 +0200 Subject: [PATCH 18/23] Added logging about failover --- consumerlocator.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/consumerlocator.py b/consumerlocator.py index ee1ee9c..b11a4cc 100644 --- a/consumerlocator.py +++ b/consumerlocator.py @@ -8,6 +8,7 @@ import datetime from communicator import Communicator import os from redisconnector import RedisConnector +import logging __author__ = "@dscharnitzky" __copyright__ = "Copyright 2020, GoldenPogácsa Team" @@ -15,7 +16,7 @@ __module_name__ = "consumerlocator" __version__text__ = "1" KNOWNCONSUMER = os.getenv("PRODUCER_KNOWNCONSUMER", '10.69.42.1') - +LOGGER = logging.getLogger(__name__) class ConsumerLocator: @@ -59,6 +60,7 @@ class ConsumerLocator: contains = True if not contains: + LOGGER.info(f"Learned about new consumer at {recconsumer}") consumer_list.append({"Host": recconsumer, "State": True, "LastOk": datetime.datetime.now().timestamp()}) self.red.consumerlist = consumer_list @@ -109,6 +111,7 @@ class ConsumerLocator: self.red.currentconsumer = newcurrentconsumer if self.red.currentconsumer is not None: + LOGGER.warning(f"Falling back to consumer at {newcurrentconsumer['Host']}") self.learnconsumerlist() if self.red.currentconsumer is not None: From 790cfa3a916c1d2fabd0e14c942859e4aa68c89f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Tue, 28 Apr 2020 19:37:04 +0200 Subject: [PATCH 19/23] use kaniko to build container images --- .drone.yml | 66 +++++++++++++++++++----------------------------------- 1 file changed, 23 insertions(+), 43 deletions(-) diff --git a/.drone.yml b/.drone.yml index c8767db..f380c56 100644 --- a/.drone.yml +++ b/.drone.yml @@ -19,22 +19,18 @@ steps: - pip3 install -r requirements.txt - echo -e 'pytest test.py' -- name: build - image: docker:stable-dind - volumes: - - name: dockersock - path: /var/run - environment: - DOCKER_USERNAME: - from_secret: DOCKER_USERNAME - DOCKER_PASSWORD: - from_secret: DOCKER_PASSWORD - commands: - - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin - - docker build -t="$DOCKER_USERNAME/producer" . - - docker build -t="$DOCKER_USERNAME/producer:$DRONE_BUILD_NUMBER" . - - docker push "$DOCKER_USERNAME/producer" - - docker push "$DOCKER_USERNAME/producer:$DRONE_BUILD_NUMBER" +- name: build-app + image: banzaicloud/drone-kaniko + settings: + registry: registry.kmlabz.com + repo: goldenpogacsa/${DRONE_REPO_NAME} + username: + from_secret: DOCKER_USERNAME + password: + from_secret: DOCKER_PASSWORD + tags: + - latest + - ${DRONE_BUILD_NUMBER} - name: make_docs image: python:3.8 @@ -44,23 +40,19 @@ steps: - cd docs - make html -- name: build_docs - image: docker:stable-dind - volumes: - - name: dockersock - path: /var/run - environment: - DOCKER_USERNAME: +- name: build-docs + image: banzaicloud/drone-kaniko + settings: + dockerfile: docs/Dockerfile + registry: registry.kmlabz.com + repo: goldenpogacsa/consumer-api-docs + username: from_secret: DOCKER_USERNAME - DOCKER_PASSWORD: + password: from_secret: DOCKER_PASSWORD - commands: - - cd docs - - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin - - docker build -t="$DOCKER_USERNAME/producer-docs" . - - docker build -t="$DOCKER_USERNAME/producer-docs:$DRONE_BUILD_NUMBER" . - - docker push "$DOCKER_USERNAME/producer-docs" - - docker push "$DOCKER_USERNAME/producer-docs:$DRONE_BUILD_NUMBER" + tags: + - latest + - ${DRONE_BUILD_NUMBER} - name: slack image: plugins/slack @@ -71,15 +63,3 @@ steps: icon_url: https://cloudcdn.tormakristof.eu/static/drone.svg when: status: [ failure ] - -services: -- name: docker - image: docker:stable-dind - privileged: true - volumes: - - name: dockersock - path: /var/run - -volumes: -- name: dockersock - temp: {} From be8873956b26ef3a6b560c5667c142c405d64aad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Tue, 28 Apr 2020 20:13:55 +0200 Subject: [PATCH 20/23] change directory before kaniko step --- .drone.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.drone.yml b/.drone.yml index f380c56..c4aa39d 100644 --- a/.drone.yml +++ b/.drone.yml @@ -39,6 +39,7 @@ steps: - pip3 install -r requirements.txt - cd docs - make html + - cd .. - name: build-docs image: banzaicloud/drone-kaniko From e8f206728f30dfc666a8dd827221fb9c2e2d77ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Tue, 28 Apr 2020 20:26:41 +0200 Subject: [PATCH 21/23] change context of document building --- .drone.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.drone.yml b/.drone.yml index c4aa39d..2d4b4d8 100644 --- a/.drone.yml +++ b/.drone.yml @@ -39,13 +39,12 @@ steps: - pip3 install -r requirements.txt - cd docs - make html - - cd .. - name: build-docs image: banzaicloud/drone-kaniko settings: - dockerfile: docs/Dockerfile registry: registry.kmlabz.com + context: ${PWD}/docs/ repo: goldenpogacsa/consumer-api-docs username: from_secret: DOCKER_USERNAME From d0cdb61916663f558f7c5467b6a4cd66d1ac18df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Tue, 28 Apr 2020 20:30:40 +0200 Subject: [PATCH 22/23] dockerfile keyword is still needed --- .drone.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.drone.yml b/.drone.yml index 2d4b4d8..5097b2f 100644 --- a/.drone.yml +++ b/.drone.yml @@ -44,6 +44,7 @@ steps: image: banzaicloud/drone-kaniko settings: registry: registry.kmlabz.com + dockerfile: docs/Dockerfile context: ${PWD}/docs/ repo: goldenpogacsa/consumer-api-docs username: From 58c4e296ea2929de1b338a538c0e0f4b7cb36ad4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Tue, 28 Apr 2020 20:53:51 +0200 Subject: [PATCH 23/23] use custom dind to build doc container image --- .drone.yml | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/.drone.yml b/.drone.yml index 5097b2f..b62534f 100644 --- a/.drone.yml +++ b/.drone.yml @@ -40,20 +40,23 @@ steps: - cd docs - make html -- name: build-docs - image: banzaicloud/drone-kaniko - settings: - registry: registry.kmlabz.com - dockerfile: docs/Dockerfile - context: ${PWD}/docs/ - repo: goldenpogacsa/consumer-api-docs - username: +- name: build_docs + image: docker:stable-dind + volumes: + - name: dockersock + path: /var/run + environment: + DOCKER_USERNAME: from_secret: DOCKER_USERNAME - password: + DOCKER_PASSWORD: from_secret: DOCKER_PASSWORD - tags: - - latest - - ${DRONE_BUILD_NUMBER} + commands: + - cd docs + - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin registry.kmlabz.com + - docker build -t="registry.kmlabz.com/goldenpogacsa/producer-docs" . + - docker build -t="registry.kmlabz.com/goldenpogacsa/producer-docs:$DRONE_BUILD_NUMBER" . + - docker push "registry.kmlabz.com/goldenpogacsa/producer-docs" + - docker push "registry.kmlabz.com/goldenpogacsa/producer-docs:$DRONE_BUILD_NUMBER" - name: slack image: plugins/slack @@ -64,3 +67,15 @@ steps: icon_url: https://cloudcdn.tormakristof.eu/static/drone.svg when: status: [ failure ] + +services: +- name: docker + image: docker:stable-dind + privileged: true + volumes: + - name: dockersock + path: /var/run + +volumes: +- name: dockersock + temp: {}