From 5af72221099c508cbafbfe12ba9279e94032ec33 Mon Sep 17 00:00:00 2001 From: Matias Aguirre Date: Sat, 30 May 2020 00:54:09 -0300 Subject: [PATCH] Updated release and tests mechanism --- .gitignore | 2 ++ Makefile | 25 +++++++++------------ docker-compose.yml | 27 ++++++++++++++++++++++ files/local.env.template | 2 ++ files/release/Dockerfile | 15 +++++++++++++ files/release/entrypoint.sh | 42 +++++++++++++++++++++++++++++++++++ files/release/pypirc.template | 7 ++++++ files/tests/Dockerfile | 22 ++++++++++++++++++ files/tests/entrypoint.sh | 10 +++++++++ files/tests/pyenv.sh | 20 +++++++++++++++++ 10 files changed, 157 insertions(+), 15 deletions(-) create mode 100644 docker-compose.yml create mode 100644 files/local.env.template create mode 100644 files/release/Dockerfile create mode 100755 files/release/entrypoint.sh create mode 100644 files/release/pypirc.template create mode 100644 files/tests/Dockerfile create mode 100755 files/tests/entrypoint.sh create mode 100755 files/tests/pyenv.sh diff --git a/.gitignore b/.gitignore index 7c2001d4..e295dd4c 100644 --- a/.gitignore +++ b/.gitignore @@ -49,3 +49,5 @@ changelog.sh \#*\# .python-version + +files/local.env diff --git a/Makefile b/Makefile index dcccb672..92dc4627 100644 --- a/Makefile +++ b/Makefile @@ -1,25 +1,20 @@ build: - @ python setup.py sdist - @ python setup.py bdist_wheel --python-tag py2 + @ BUILD_VERSION=2 python setup.py sdist + @ BUILD_VERSION=2 python setup.py bdist_wheel --python-tag py2 @ BUILD_VERSION=3 python setup.py bdist_wheel --python-tag py3 publish: - @ python setup.py sdist upload - @ python setup.py bdist_wheel --python-tag py2 upload - @ BUILD_VERSION=3 python setup.py bdist_wheel --python-tag py3 upload + @ twine upload dist/* + +release: + @ docker-compose run social-release + +tests: + @ docker-compose run social-tests clean: @ find . -name '*.py[co]' -delete @ find . -name '__pycache__' -delete @ rm -rf *.egg-info dist build -docker-tox-build: - @ docker inspect omab/psa-social-app-django >/dev/null 2>&1 || ( \ - docker build -t omab/psa-social-app-django . \ - ) - -docker-tox: docker-tox-build - @ docker run -it --rm \ - --name psa-social-app-django-test \ - -v "`pwd`:/src" \ - omab/psa-social-app-django tox +.PHONY: tests diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..c3978c9b --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,27 @@ +version: "3.7" + +services: + social-release: + image: omab/social-auth-release + build: + context: . + dockerfile: ./files/release/Dockerfile + environment: + - PROJECT_NAME=social-app-django + - PROJECT_DIR=social_django + env_file: + - ./files/local.env + volumes: + - .:/code + + social-tests: + image: omab/social-auth-tests + build: + context: . + dockerfile: ./files/tests/Dockerfile + args: + - PYTHON_VERSIONS=2.7.17 3.5.9 3.6.10 3.7.7 3.8.2 3.9-dev + environment: + - PYTHON_VERSIONS=2.7.17 3.5.9 3.6.10 3.7.7 3.8.2 3.9-dev + volumes: + - .:/code diff --git a/files/local.env.template b/files/local.env.template new file mode 100644 index 00000000..f3ecd73e --- /dev/null +++ b/files/local.env.template @@ -0,0 +1,2 @@ +PYPI_USERNAME= +PYPI_PASSWORD= diff --git a/files/release/Dockerfile b/files/release/Dockerfile new file mode 100644 index 00000000..3960e177 --- /dev/null +++ b/files/release/Dockerfile @@ -0,0 +1,15 @@ +FROM python:3.8.2-slim-buster + +RUN apt-get update && \ + apt-get install -y --no-install-recommends make gettext git curl && \ + pip install -U pip && \ + pip install -U setuptools && \ + pip install -U twine + +COPY ./files/release/pypirc.template / +COPY ./files/release/entrypoint.sh / +ADD . /code + +WORKDIR /code + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/files/release/entrypoint.sh b/files/release/entrypoint.sh new file mode 100755 index 00000000..23a0ac9b --- /dev/null +++ b/files/release/entrypoint.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +set -e + +if [ -z "${PYPI_USERNAME}" ] || [ -z "${PYPI_PASSWORD}" ]; then + echo "=====================================================================" + echo "Error: missing PYPI_USERNAME or PYPI_PASSWORD environment values" + echo "=====================================================================" + exit 1; +fi + +if [ -z "${PROJECT_DIR}" ] || [ -z "${PROJECT_NAME}" ]; then + echo "=====================================================================" + echo "Error: missing PROJECT_DIR or PROJECT_NAME environment values" + echo "=====================================================================" + exit 1; +fi + +envsubst < /pypirc.template > ~/.pypirc + +# This will fail if tag doesn't exist +CURRENT_VERSION=$(head -n1 ${PROJECT_DIR}/__init__.py | awk '{print $3}' | sed 's/[^0-9\.]//g') +CURRENT_TAG=$(git describe --tags --abbrev=0) + +if [ "${CURRENT_VERSION}" != "${CURRENT_TAG}" ]; then + echo "=====================================================================" + echo "Error: version '${CURRENT_VERSION}' not tagged" + echo "=====================================================================" + exit 1; +fi + +PYPI_URL="https://pypi.org/project/${PROJECT_NAME}/${CURRENT_VERSION}/" +VERSION_PAGE_STATUS=$(curl -s -I ${PYPI_URL} | head -n1 | awk '{print $2}') + +if [ "${VERSION_PAGE_STATUS}" == "200" ]; then + echo "=====================================================================" + echo "Error: version '${CURRENT_VERSION}' already exists" + echo "=====================================================================" + exit 1; +fi + +make clean build publish diff --git a/files/release/pypirc.template b/files/release/pypirc.template new file mode 100644 index 00000000..61a15041 --- /dev/null +++ b/files/release/pypirc.template @@ -0,0 +1,7 @@ +[distutils] +index-servers = + pypi + +[pypi] +username: ${PYPI_USERNAME} +password: ${PYPI_PASSWORD} diff --git a/files/tests/Dockerfile b/files/tests/Dockerfile new file mode 100644 index 00000000..b66cf555 --- /dev/null +++ b/files/tests/Dockerfile @@ -0,0 +1,22 @@ +FROM python:3.8.2-slim-buster + +ARG PYTHON_VERSIONS=${PYTHON_VERSIONS} +ENV PYTHON_VERSIONS=${PYTHON_VERSIONS} + +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + make git pkg-config ca-certificates wget curl llvm build-essential \ + python-openssl libssl-dev zlib1g-dev libbz2-dev libreadline-dev \ + libsqlite3-dev libncurses5-dev libncursesw5-dev xz-utils libxml2-dev \ + libxmlsec1-dev libffi-dev tk-dev liblzma-dev + +COPY ./files/tests/pyenv.sh / +RUN /pyenv.sh + +COPY ./files/tests/entrypoint.sh / + +ADD . /code + +WORKDIR /code + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/files/tests/entrypoint.sh b/files/tests/entrypoint.sh new file mode 100755 index 00000000..504f745b --- /dev/null +++ b/files/tests/entrypoint.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +set -e + +export PATH=~/.pyenv/shims:~/.pyenv/bin:${PATH} +export PYENV_ROOT=~/.pyenv + +eval "$(pyenv init -)" + +tox diff --git a/files/tests/pyenv.sh b/files/tests/pyenv.sh new file mode 100755 index 00000000..a9aca225 --- /dev/null +++ b/files/tests/pyenv.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +set -e + +export PATH=~/.pyenv/shims:~/.pyenv/bin:${PATH} +export PYENV_ROOT=~/.pyenv +export PYTHON_VERSIONS=${PYTHON_VERSIONS} + +curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash + +eval "$(pyenv init -)" + +for version in ${PYTHON_VERSIONS}; do + pyenv install "${version}" + pyenv local "${version}" + pip install --upgrade setuptools pip tox + pyenv local --unset +done + +pyenv local ${PYTHON_VERSIONS}