Skip to content
This repository has been archived by the owner on Jun 21, 2020. It is now read-only.

Release/0.5 #5

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 18 additions & 24 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
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-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

compose:
devpi:
image: muccg/devpi:latest

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

services:
devpi:
image: muccg/devpi:latest
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ secrets.yml
# Python stuffs
*.egg-info
*.pyc

data/
docker-compose.yml
2 changes: 1 addition & 1 deletion DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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 \
Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pip
setuptools
wheel
drone==0.3.0
devpi-client==2.4.1
devpi-client==2.7.0
25 changes: 20 additions & 5 deletions run_devpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -135,15 +136,29 @@ def check_vargs(vargs):
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()
61 changes: 32 additions & 29 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand All @@ -39,28 +37,29 @@ 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)
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)
run_devpi.login(
Expand All @@ -76,32 +75,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)
Expand Down