diff --git a/.woodpecker.yml b/.woodpecker.yml index 8cf2c15..b1d9f41 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -5,16 +5,9 @@ clone: pipeline: test: - image: brenard/debian-python-deb + image: brenard/mylib:dev-master commands: - - DEBIAN_FRONTEND=noninteractive apt-get -qq update < /dev/null > /dev/null - - DEBIAN_FRONTEND=noninteractive apt-get -y -qq upgrade < /dev/null > /dev/null - - DEBIAN_FRONTEND=noninteractive apt-get -qq -y install --no-install-recommends pkg-config libsystemd-dev libldap2-dev libsasl2-dev libpq-dev libmariadb-dev wget unzip < /dev/null > /dev/null - - wget --no-verbose -O /opt/instantclient-basic-linux.x64-21.4.0.0.0dbru.zip https://download.oracle.com/otn_software/linux/instantclient/214000/instantclient-basic-linux.x64-21.4.0.0.0dbru.zip - - unzip -qq -d /opt /opt/instantclient-basic-linux.x64-21.4.0.0.0dbru.zip - - echo /opt/instantclient_* > /etc/ld.so.conf.d/oracle-instantclient.conf - - ldconfig - - ./tests.sh --quiet + - ./tests.sh --no-venv build: image: brenard/debian-python-deb diff --git a/docker/dev-master/Dockerfile b/docker/dev-master/Dockerfile index 7ed2f33..bfc2328 100644 --- a/docker/dev-master/Dockerfile +++ b/docker/dev-master/Dockerfile @@ -1,3 +1,5 @@ FROM brenard/mylib:latest RUN apt-get remove -y python3-mylib RUN python3 -m pip install -U git+https://gitea.zionetrix.net/bn8/python-mylib.git +RUN git clone https://gitea.zionetrix.net/bn8/python-mylib.git /usr/local/src/python-mylib && pip install /usr/local/src/python-mylib[dev] +RUN cd /usr/local/src/python-mylib && pre-commit run --all-files diff --git a/docker/latest/Dockerfile b/docker/latest/Dockerfile index 2d655ee..605fcdb 100644 --- a/docker/latest/Dockerfile +++ b/docker/latest/Dockerfile @@ -1,4 +1,5 @@ FROM debian:latest RUN echo "deb http://debian.zionetrix.net stable main" > /etc/apt/sources.list.d/zionetrix.list && apt-get -o Acquire::AllowInsecureRepositories=true -o Acquire::AllowDowngradeToInsecureRepositories=true update && apt-get -o APT::Get::AllowUnauthenticated=true install --yes zionetrix-archive-keyring && apt-get clean && rm -fr rm -rf /var/lib/apt/lists/* -RUN apt-get update && apt-get upgrade -y && apt-get install -y python3-all python3-dev python3-pip python3-venv python3-mylib build-essential git && apt-get clean && rm -fr rm -rf /var/lib/apt/lists/* -RUN python3 -m pip install pylint pytest flake8 flake8-junit-report pylint-junit junitparser +RUN apt-get update && apt-get upgrade -y && apt-get install -y python3-all python3-dev python3-pip python3-venv python3-mylib build-essential git libldap2-dev libsasl2-dev pkg-config libsystemd-dev libpq-dev libmariadb-dev wget unzip && apt-get clean && rm -fr rm -rf /var/lib/apt/lists/* +RUN python3 -m pip install pylint pytest flake8 flake8-junit-report pylint-junit junitparser pre-commit +RUN wget --no-verbose -O /opt/instantclient-basic-linux.x64-21.4.0.0.0dbru.zip https://download.oracle.com/otn_software/linux/instantclient/214000/instantclient-basic-linux.x64-21.4.0.0.0dbru.zip && unzip -qq -d /opt /opt/instantclient-basic-linux.x64-21.4.0.0.0dbru.zip && echo /opt/instantclient_* > /etc/ld.so.conf.d/oracle-instantclient.conf && ldconfig diff --git a/tests.sh b/tests.sh index 0deaf4b..d4c86d2 100755 --- a/tests.sh +++ b/tests.sh @@ -1,31 +1,72 @@ #!/bin/bash QUIET_ARG="" +NO_VENV=0 + +function usage() { + [ -n "$1" ] && echo -e "$1\n" > /dev/stderr + echo "Usage: $0 [-x] [-q|--quiet] [--no-venv]" + echo " -h/--help Show usage message" + echo " -q/--quiet Enable quiet mode" + echo " -n/--no-venv Disable venv creation and run tests on system environment" + echo " -x Enable debug mode" + [ -n "$1" ] && exit 1 + exit 0 +} + +idx=1 +while [ $idx -le $# ] +do + OPT=${!idx} + case $OPT in + -h|--help) + usage + ;; + -q|--quiet) + QUIET_ARG="--quiet" + ;; + -n|--no-venv) + NO_VENV=1 + ;; + -x) + set -x + ;; + *) + usage "Unkown parameter '$OPT'" + esac + let idx=idx+1 +done [ "$1" == "--quiet" ] && QUIET_ARG="--quiet" # Enter source directory cd $( dirname $0 ) -if [ -d venv ] +TEMP_VENV=0 +VENV="" +if [ $NO_VENV -eq 1 ] then - VENV=$( realpath venv ) - TEMP_VENV=0 + echo "Run tests in system environment..." +elif [ -d venv ] +then + VENV=$( realpath venv ) + echo "Using existing virtualenv ($VENV)..." else - # Create a temporary venv - VENV=$(mktemp -d) - echo "Create a temporary virtualenv in $VENV to install dependencies..." - TEMP_VENV=1 - python3 -m venv $VENV + # Create a temporary venv + VENV=$(mktemp -d) + echo "Create a temporary virtualenv in $VENV..." + TEMP_VENV=1 + python3 -m venv $VENV fi -echo "Install package with dev dependencies using pip..." -$VENV/bin/python3 -m pip install -e ".[dev]" $QUIET_ARG - -RES=0 +if [ -n "$VENV" ] +then + echo "Install package with dev dependencies using pip in virtualenv..." + $VENV/bin/python3 -m pip install -e ".[dev]" $QUIET_ARG + source $VENV/bin/activate +fi # Run pre-commit echo "Run pre-commit..." -source $VENV/bin/activate pre-commit run --all-files [ $? -ne 0 ] && RES=1