From edfe0e545014f56e826078000e765184fae8e681 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Tue, 26 Feb 2019 12:34:51 +0100 Subject: [PATCH] fix broken Docker build and helm package --- .gitlab-ci.yml | 4 ++-- helm/passbook/Chart.yaml | 2 +- .../core/management/commands/nexus_upload.py | 22 ++++++------------- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5e273225b..f9314a3d6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -52,7 +52,7 @@ package-docker: name: gcr.io/kaniko-project/executor:debug entrypoint: [""] before_script: - - echo "{\"auths\":{\"https://docker.$NEXUS_URL/\":{\"username\":\"$NEXUS_USER\",\"password\":\"$NEXUS_PASS\"}}}" > /kaniko/.docker/config.json + - echo "{\"auths\":{\"docker.$NEXUS_URL\":{\"auth\":\"$NEXUS_AUTH\"}}}" > /kaniko/.docker/config.json script: - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination docker.pkg.beryju.org/passbook:latest --destination docker.pkg.beryju.org/passbook:0.0.8-alpha stage: build @@ -65,7 +65,7 @@ package-helm: - curl https://raw.githubusercontent.com/helm/helm/master/scripts/get | bash - helm init --client-only - helm package helm/passbook - - ./manage.py nexus_upload --method put --url $NEXUS_URL --user $NEXUS_USER --password $NEXUS_PASS --repo helm *.tgz + - ./manage.py nexus_upload --method put --url $NEXUS_URL --auth $NEXUS_AUTH --repo helm *.tgz only: - tags - /^version/.*$/ diff --git a/helm/passbook/Chart.yaml b/helm/passbook/Chart.yaml index f79e83a26..8ac575f17 100644 --- a/helm/passbook/Chart.yaml +++ b/helm/passbook/Chart.yaml @@ -2,5 +2,5 @@ apiVersion: v1 appVersion: "0.0.8-alpha" description: A Helm chart for passbook. name: passbook -version: 1.0.0 +version: "0.0.8-alpha" icon: https://passbook.beryju.org/images/logo.png diff --git a/passbook/core/management/commands/nexus_upload.py b/passbook/core/management/commands/nexus_upload.py index ae6deb76a..cc65a326c 100644 --- a/passbook/core/management/commands/nexus_upload.py +++ b/passbook/core/management/commands/nexus_upload.py @@ -1,5 +1,5 @@ """passbook nexus_upload management command""" -from getpass import getpass +from base64 import b64decode import requests from django.core.management.base import BaseCommand @@ -24,9 +24,9 @@ class Command(BaseCommand): help='Nexus root URL', required=True) parser.add_argument( - '--user', + '--auth', action='store', - help='Username to use for Nexus upload', + help='base64-encoded string of username:password', required=True) parser.add_argument( '--method', @@ -37,29 +37,21 @@ class Command(BaseCommand): help=('Method used for uploading files to nexus. ' 'Apt repositories use post, Helm uses put.'), required=True) - parser.add_argument( - '--password', - action='store', - help=("Password to use for Nexus upload. " - "If parameter not given, we'll interactively ask")) # Positional arguments parser.add_argument('file', nargs='+', type=str) def handle(self, *args, **options): """Upload debian package to nexus repository""" - if options.get('password') is None: - options['password'] = getpass() + auth = tuple(b64decode(options.get('auth')).decode('utf-8').split(':', 1)) responses = {} - url = 'https://%(url)s/repository/%(repo)s//' % options + url = 'https://%(url)s/repository/%(repo)s/' % options method = options.get('method') exit_code = 0 for file in options.get('file'): if method == 'post': - responses[file] = requests.post(url, data=open(file, mode='rb'), - auth=(options.get('user'), options.get('password'))) + responses[file] = requests.post(url, data=open(file, mode='rb'), auth=auth) else: - responses[file] = requests.put(url+file, data=open(file, mode='rb'), - auth=(options.get('user'), options.get('password'))) + responses[file] = requests.put(url+file, data=open(file, mode='rb'), auth=auth) self.stdout.write('Upload results:\n') sep = '-' * 60 self.stdout.write('%s\n' % sep)