diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..d831b123 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +# Hack to upload version to Pypi + +FROM registry.opensource.zalan.do/stups/python AS builder +ARG VERSION +RUN apt-get update && \ + apt-get install -q -y python3-pip && \ + pip3 install -U tox setuptools +COPY . /build +WORKDIR /build +RUN sed -i "s/__version__ = .*/__version__ = '${VERSION}'/" */__init__.py +RUN python3 setup.py sdist bdist_wheel + +FROM pierone.stups.zalan.do/teapot/python-cdp-release:latest +COPY --from=builder /build/dist /pydist diff --git a/delivery.yaml b/delivery.yaml new file mode 100644 index 00000000..a60ce140 --- /dev/null +++ b/delivery.yaml @@ -0,0 +1,51 @@ +version: "2017-09-20" +notifications: + hipchat: + rooms: + - cdp-notifications-test +pipeline: + - id: build + type: script + overlay: ci/python + commands: + - desc: "Install dependencies" + cmd: pip install -r requirements.txt + - desc: "Run Tests" + cmd: python3 setup.py test + - desc: "Check code style" + cmd: python3 setup.py flake8 + - desc: "Build docker image that will upload package" + cmd: | + VERSION=$(./next-version) + + if [[ -z "${CDP_PULL_REQUEST_NUMBER}" ]]; then + DOCKER_IMAGE="pierone.stups.zalan.do/automata/senza-release:${CDP_TARGET_REPOSITORY_COUNTER}" + else + DOCKER_IMAGE="pierone.stups.zalan.do/automata/senza-release:${CDP_TARGET_REPOSITORY_COUNTER}-snapshot" + fi + + docker build --build-arg VERSION="$VERSION" -t "$DOCKER_IMAGE" . + + if [[ -z "${CDP_PULL_REQUEST_NUMBER}" ]]; then + docker push "$DOCKER_IMAGE" + git gh-tag "$VERSION" + fi + - id: release + type: process + desc: Release to TestPyPI + target: stups + process: microservice_standard_deployment + config: + apply_permanent_resources: + image: pierone.stups.zalan.do/automata/senza-release:#{CDP_TARGET_REPOSITORY_COUNTER} + env: + - name: USERNAME + valueFrom: + secretKeyRef: + name: teapot-pypi-credentials + key: username + - name: PASSWORD + valueFrom: + secretKeyRef: + name: teapot-pypi-credentials + key: password diff --git a/next-version b/next-version new file mode 100755 index 00000000..4de09b6e --- /dev/null +++ b/next-version @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 + +import subprocess + +MAJOR_VERSION = 2 +MINOR_VERSION = 1 + + +def get_latest_version() -> (int, int, int): + """ + Gets latest version based on Git Tags. + """ + proc = subprocess.run(['git', 'tag'], stdout=subprocess.PIPE) + + versions = sorted(map(lambda version: tuple(int(sub) + for sub + in version.split('.')), + proc.stdout.decode().splitlines())) + return versions[-1] + + +if __name__ == '__main__': + major, minor, build = get_latest_version() + + if major != MAJOR_VERSION or minor != MINOR_VERSION: + new_build = 0 + else: + new_build = build + 1 + + print(f"{MAJOR_VERSION}.{MINOR_VERSION}.{new_build}") diff --git a/release.sh b/release.sh deleted file mode 100755 index ce92b9d3..00000000 --- a/release.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/sh - -if [ $# -ne 1 ]; then - >&2 echo "usage: $0 " - exit 1 -fi - -set -xe - -python3 --version -git --version - -version=$1 - -sed -i "s/__version__ = .*/__version__ = '${version}'/" */__init__.py - -# Do not tag/push on Go CD -if [ -z "$GO_PIPELINE_LABEL" ]; then - python3 setup.py clean - python3 setup.py test - python3 setup.py flake8 - - git add */__init__.py - - git commit -m "Bumped version to $version" - git push -fi - -python3 setup.py sdist bdist_wheel upload - -if [ -z "$GO_PIPELINE_LABEL" ]; then - git tag ${version} - git push --tags -fi