From f01cf50106ea4ffddbd803153dfe20a44936fcec Mon Sep 17 00:00:00 2001 From: Costin Bleotu Date: Fri, 14 Apr 2017 13:52:19 +0300 Subject: [PATCH 01/14] Added docker-composer.yml --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index b35eafc..054a247 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,6 @@ secrets.yml # Python stuffs *.egg-info *.pyc + +data/ +docker-compose.yml \ No newline at end of file From eb5a95d1ad53b135dcd2a76293576aeed2816ed9 Mon Sep 17 00:00:00 2001 From: Costin Bleotu Date: Fri, 14 Apr 2017 13:53:50 +0300 Subject: [PATCH 02/14] Docs for dron 0.5 --- DOCS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DOCS.md b/DOCS.md index 2399187..cced11e 100644 --- a/DOCS.md +++ b/DOCS.md @@ -10,7 +10,7 @@ Use the devpi plugin to deploy a Python package to a [devpi](http://doc.devpi.ne The following is an example configuration for your .drone.yml: ```yaml -publish: +pipeline: devpi: server: http://devpi.bigco.com:3141/ index: root/production From 97f8d17beeb2819d88625b5c129555cc15d82816 Mon Sep 17 00:00:00 2001 From: Costin Bleotu Date: Fri, 14 Apr 2017 13:55:33 +0300 Subject: [PATCH 03/14] Removed drone client --- Dockerfile | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 77abd4b..b66f143 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,13 @@ -FROM python:3.5.1-alpine +FROM python:3.5-alpine RUN apk add -U \ ca-certificates \ && rm -rf /var/cache/apk/* \ && pip install --no-cache-dir --upgrade \ pip \ - setuptools \ - wheel + setuptools + -ADD wheeldir /usr/src/app/ -WORKDIR /usr/src/app/ ADD requirements.txt . RUN pip install -r requirements.txt RUN pip install --use-wheel --no-index --find-links=wheeldir \ From 56615b57930a5c6c3ae2e5931dfe3b82c25f22b9 Mon Sep 17 00:00:00 2001 From: Costin Bleotu Date: Fri, 14 Apr 2017 13:55:48 +0300 Subject: [PATCH 04/14] Update dependencies --- requirements.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 9184acc..1a7c6ec 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,4 @@ pip setuptools wheel -drone==0.3.0 -devpi-client==2.4.1 +devpi-client==2.7.0 From d3748989aa5aca45571e366e96914431dc9b131c Mon Sep 17 00:00:00 2001 From: Costin Bleotu Date: Fri, 14 Apr 2017 13:56:24 +0300 Subject: [PATCH 05/14] Tests for new release --- test.py | 64 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/test.py b/test.py index 9115ba5..99763c6 100644 --- a/test.py +++ b/test.py @@ -12,16 +12,14 @@ class DevpiTestCase(unittest.TestCase): - basic_input = { - "workspace": { - "path": TEST_PACKAGE_PATH, - }, - "vargs": { - "server": "http://localhost:3141/", - "index": "root/devpitest", - "username": "root", - "password": "", - } + payload = { + 'DRONE_NETRC_MACHINE': 'localhost', + 'DRONE_REPO_OWNER': 'testpkg', + 'DRONE_REPO_NAME': 'testpkg', + 'PLUGIN_SERVER': 'http://localhost:3141', + 'PLUGIN_INDEX': 'root/devpitest', + 'PLUGIN_USERNAME': 'root', + 'PLUGIN_PASSWORD': '' } # We'll override the default clientdir while creating our index below. default_clientdir = '/tmp/devpi-testclientdir' @@ -30,7 +28,7 @@ class DevpiTestCase(unittest.TestCase): def setUpClass(cls): # We'll only do this once so we're not hammering the server if we # grow this test suite. - cls._wait_for_devpi_to_start(cls.basic_input, cls.default_clientdir) + cls._wait_for_devpi_to_start(cls.payload, cls.default_clientdir) def setUp(self): self.old_argv_val = sys.argv @@ -39,33 +37,37 @@ def tearDown(self): sys.argv = self.old_argv_val @classmethod - def _wait_for_devpi_to_start(cls, input_dict, clientdir): + def _wait_for_devpi_to_start(cls, env, clientdir): """ devpi is a bit... pokey while starting. We'll just harass it until it responds before doing the rest of the tests. """ + vargs = run_devpi.extract_vargs(env) retries_left = 30 while retries_left > 0: try: run_devpi.select_server( - input_dict['vargs']['server'], clientdir=clientdir) + vargs['server'], clientdir=clientdir) + print('serv ok') except SystemExit: retries_left -= 1 time.sleep(1) continue return - def _ensure_test_index_exists(self, input_dict, clientdir): + def _ensure_test_index_exists(self, env, clientdir): """ Since Drone fires up a new devpi server for each test run, we'll need to create an index before we can upload. """ - t_vargs = input_dict['vargs'] + t_vargs = run_devpi.extract_vargs(env) run_devpi.select_server( t_vargs['server'], clientdir=clientdir) + print('select ok') run_devpi.login( t_vargs['username'], t_vargs['password'], clientdir=self.default_clientdir) + print('login ok') try: run_devpi.create_index( t_vargs['index'], clientdir=clientdir) @@ -76,32 +78,36 @@ def test_upload(self): """ Tests a simple package upload to an existing DevPi server. """ + self._ensure_test_index_exists( - self.basic_input, self.default_clientdir) - sys.argv = ['--', json.dumps(self.basic_input)] - run_devpi.main() + self.payload, self.default_clientdir) + + vargs = run_devpi.extract_vargs(self.payload) + + run_devpi.select_server(vargs['server']) + run_devpi.login(vargs['username'], vargs['password']) + run_devpi.select_index(vargs['index']) + package_path = os.path.join( + self.payload['DRONE_REPO_NAME']) + run_devpi.upload_package(package_path) class ValidationTestCase(unittest.TestCase): def setUp(self): - self.basic_input = { - "workspace": { - "path": TEST_PACKAGE_PATH, - }, - "vargs": { - "server": "http://localhost:3141/", - "index": "root/devpitest", - "username": "root", - "password": "", + self.payload = { + 'PLUGIN_SERVER': 'http://localhost:3141/', + 'PLUGIN_INDEX': 'root/devpitest', + 'PLUGIN_USERNAME': 'root', + 'PLUGIN_PASSWORD': '' } - } def test_vargs_server_validation(self): """ Tests validation for vargs server keyword. """ - vargs = self.basic_input.copy()['vargs'] + + vargs = run_devpi.extract_vargs(self.payload) # Start the party with something weird. vargs['server'] = 'blah' self.assertRaises(SystemExit, run_devpi.check_vargs, vargs) From 10962c909d28dd35649db7746d8d70693b18e74a Mon Sep 17 00:00:00 2001 From: Costin Bleotu Date: Fri, 14 Apr 2017 13:57:00 +0300 Subject: [PATCH 06/14] Update to drone 0.5 --- run_devpi.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/run_devpi.py b/run_devpi.py index c2933a8..fb6e3d0 100644 --- a/run_devpi.py +++ b/run_devpi.py @@ -5,10 +5,11 @@ Recommended reading: http://doc.devpi.net/latest/quickstart-releaseprocess.html """ import sys -import urllib.parse -import drone +import os import subprocess +import urllib.parse + # devpi uses a 'clientdir' arg to determine where to store state. We make # this overridable below to facilitate the integration test process. @@ -134,16 +135,28 @@ def check_vargs(vargs): print("You must specify a password.") sys.exit(1) +def extract_vargs(payload): + vargs = {} + for k in payload: + if 'PLUGIN_' in k: + vargs[k.replace('PLUGIN_','').lower()] = payload[k] + return vargs + def main(): - payload = drone.plugin.get_input() - vargs = payload['vargs'] + payload = os.environ + vargs = extract_vargs(payload) check_vargs(vargs) select_server(vargs['server']) login(vargs['username'], vargs['password']) select_index(vargs['index']) - upload_package(payload['workspace']['path']) + package_path = os.path.join( + '/drone/src/', + payload['DRONE_NETRC_MACHINE'], + payload['DRONE_REPO_OWNER'], + payload['DRONE_REPO_NAME']) + upload_package(package_path) if __name__ == "__main__": main() From 74d0ab1ceca89f858c71b1229857179d9514985b Mon Sep 17 00:00:00 2001 From: Costin Bleotu Date: Fri, 14 Apr 2017 14:12:24 +0300 Subject: [PATCH 07/14] Update .drone.yml for 0.5 --- .drone.yml | 40 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/.drone.yml b/.drone.yml index d170a74..e855850 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,30 +1,22 @@ -build: - image: python:3.5.1-alpine - commands: - - pip install --no-cache-dir --upgrade pip setuptools wheel flake8 - - flake8 run_devpi.py - - pip wheel -r requirements.txt --wheel-dir=wheeldir --find-links=wheeldir - - pip install --use-wheel --no-index --find-links=wheeldir -r requirements.txt - - python test.py +pipeline: + build: + image: python:3.5.1-alpine + commands: + - pip install --no-cache-dir --upgrade pip setuptools wheel flake8 + - flake8 run_devpi.py + - pip wheel -r requirements.txt --wheel-dir=wheeldir --find-links=wheeldir + - pip install --use-wheel --no-index --find-links=wheeldir -r requirements.txt -compose: - devpi: + test: image: muccg/devpi:latest + commands: + - python test.py -publish: - docker: - username: $$DOCKER_USER - password: $$DOCKER_PASS - email: $$DOCKER_EMAIL + publish: + image: plugins/docker + username: ${DOCKER_USER} + password: ${DOCKER_PASS} + email: ${DOCKER_EMAIL} repo: plugins/drone-devpi when: branch: master - -plugin: - name: devpi - desc: Publish a package to the devpi package index. - type: publish - image: plugins/drone-devpi - labels: - - publish - - python From 01a90baa686cd5a89b0be5fb8808bda744e40e90 Mon Sep 17 00:00:00 2001 From: Costin Bleotu Date: Fri, 14 Apr 2017 14:16:20 +0300 Subject: [PATCH 08/14] Fixed whitespaces --- run_devpi.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/run_devpi.py b/run_devpi.py index fb6e3d0..8504403 100644 --- a/run_devpi.py +++ b/run_devpi.py @@ -135,11 +135,12 @@ def check_vargs(vargs): print("You must specify a password.") sys.exit(1) + def extract_vargs(payload): vargs = {} for k in payload: if 'PLUGIN_' in k: - vargs[k.replace('PLUGIN_','').lower()] = payload[k] + vargs[k.replace('PLUGIN_', '').lower()] = payload[k] return vargs @@ -152,11 +153,12 @@ def main(): login(vargs['username'], vargs['password']) select_index(vargs['index']) package_path = os.path.join( - '/drone/src/', - payload['DRONE_NETRC_MACHINE'], + '/drone/src/', + payload['DRONE_NETRC_MACHINE'], payload['DRONE_REPO_OWNER'], payload['DRONE_REPO_NAME']) upload_package(package_path) + if __name__ == "__main__": main() From ae490e4d8b822804b7183e8512b74736f5b89f8c Mon Sep 17 00:00:00 2001 From: Costin Bleotu Date: Fri, 14 Apr 2017 14:18:40 +0300 Subject: [PATCH 09/14] Build pipeline --- .drone.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.drone.yml b/.drone.yml index e855850..06af664 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,15 +1,11 @@ pipeline: build: - image: python:3.5.1-alpine + image: muccg/devpi:latest commands: - pip install --no-cache-dir --upgrade pip setuptools wheel flake8 - flake8 run_devpi.py - pip wheel -r requirements.txt --wheel-dir=wheeldir --find-links=wheeldir - pip install --use-wheel --no-index --find-links=wheeldir -r requirements.txt - - test: - image: muccg/devpi:latest - commands: - python test.py publish: From f4864bf673e6a78679275b6e25cefe90ec123e0b Mon Sep 17 00:00:00 2001 From: Costin Bleotu Date: Fri, 14 Apr 2017 14:23:30 +0300 Subject: [PATCH 10/14] Build pipeline with service --- .drone.yml | 8 +++++++- test.py | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.drone.yml b/.drone.yml index 06af664..01750dd 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,6 +1,6 @@ pipeline: build: - image: muccg/devpi:latest + image: python:3.5-alpine commands: - pip install --no-cache-dir --upgrade pip setuptools wheel flake8 - flake8 run_devpi.py @@ -8,6 +8,7 @@ pipeline: - pip install --use-wheel --no-index --find-links=wheeldir -r requirements.txt - python test.py + publish: image: plugins/docker username: ${DOCKER_USER} @@ -16,3 +17,8 @@ pipeline: repo: plugins/drone-devpi when: branch: master + + +services: + devpi: + image: muccg/devpi:latest \ No newline at end of file diff --git a/test.py b/test.py index 99763c6..842b7e9 100644 --- a/test.py +++ b/test.py @@ -16,7 +16,7 @@ class DevpiTestCase(unittest.TestCase): 'DRONE_NETRC_MACHINE': 'localhost', 'DRONE_REPO_OWNER': 'testpkg', 'DRONE_REPO_NAME': 'testpkg', - 'PLUGIN_SERVER': 'http://localhost:3141', + 'PLUGIN_SERVER': 'http://devpi:3141', 'PLUGIN_INDEX': 'root/devpitest', 'PLUGIN_USERNAME': 'root', 'PLUGIN_PASSWORD': '' From 201024bc6a361bece567f1789a5e78d79cb67510 Mon Sep 17 00:00:00 2001 From: Costin Bleotu Date: Tue, 18 Apr 2017 08:55:20 +0300 Subject: [PATCH 11/14] Wait for devpi service --- test.py | 1 - 1 file changed, 1 deletion(-) diff --git a/test.py b/test.py index 842b7e9..48fbdcb 100644 --- a/test.py +++ b/test.py @@ -48,7 +48,6 @@ def _wait_for_devpi_to_start(cls, env, clientdir): try: run_devpi.select_server( vargs['server'], clientdir=clientdir) - print('serv ok') except SystemExit: retries_left -= 1 time.sleep(1) From 2828d6a27677fefac43d4f45a68185087ddba7ea Mon Sep 17 00:00:00 2001 From: Costin Bleotu Date: Tue, 18 Apr 2017 08:56:21 +0300 Subject: [PATCH 12/14] devpi service host --- test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test.py b/test.py index 48fbdcb..ab6b34b 100644 --- a/test.py +++ b/test.py @@ -16,7 +16,7 @@ class DevpiTestCase(unittest.TestCase): 'DRONE_NETRC_MACHINE': 'localhost', 'DRONE_REPO_OWNER': 'testpkg', 'DRONE_REPO_NAME': 'testpkg', - 'PLUGIN_SERVER': 'http://devpi:3141', + 'PLUGIN_SERVER': 'http://127.0.0.1:3141', 'PLUGIN_INDEX': 'root/devpitest', 'PLUGIN_USERNAME': 'root', 'PLUGIN_PASSWORD': '' From d2180dd9e04b66381d67412a48dba1f9e351dcbb Mon Sep 17 00:00:00 2001 From: Costin Bleotu Date: Tue, 18 Apr 2017 09:13:09 +0300 Subject: [PATCH 13/14] Devpi service host update --- test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test.py b/test.py index ab6b34b..7d20546 100644 --- a/test.py +++ b/test.py @@ -16,7 +16,7 @@ class DevpiTestCase(unittest.TestCase): 'DRONE_NETRC_MACHINE': 'localhost', 'DRONE_REPO_OWNER': 'testpkg', 'DRONE_REPO_NAME': 'testpkg', - 'PLUGIN_SERVER': 'http://127.0.0.1:3141', + 'PLUGIN_SERVER': 'http://localhost:3141', 'PLUGIN_INDEX': 'root/devpitest', 'PLUGIN_USERNAME': 'root', 'PLUGIN_PASSWORD': '' From 5f738a08b6016752f6f491b946356f7cc6718cf9 Mon Sep 17 00:00:00 2001 From: Costin Bleotu Date: Tue, 18 Apr 2017 09:14:18 +0300 Subject: [PATCH 14/14] Remove print statements --- test.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/test.py b/test.py index 7d20546..8928ed9 100644 --- a/test.py +++ b/test.py @@ -62,11 +62,9 @@ def _ensure_test_index_exists(self, env, clientdir): t_vargs = run_devpi.extract_vargs(env) run_devpi.select_server( t_vargs['server'], clientdir=clientdir) - print('select ok') run_devpi.login( t_vargs['username'], t_vargs['password'], clientdir=self.default_clientdir) - print('login ok') try: run_devpi.create_index( t_vargs['index'], clientdir=clientdir)