Skip to content

Commit

Permalink
Merge pull request #55 from timgates42/feature/multiimage
Browse files Browse the repository at this point in the history
Move from pipenv-all to running each python version in its own image
  • Loading branch information
timgates42 committed Jan 5, 2021
2 parents 91c5869 + 231cf44 commit 57fcb4c
Show file tree
Hide file tree
Showing 26 changed files with 114 additions and 58 deletions.
7 changes: 5 additions & 2 deletions app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
FROM 3amigos/pipenv-all:latest
ENV PYTHONVERS "2.7 3.5 3.6 3.7 3.8"
ARG PYVER
FROM python:${PYVER}-alpine
ARG PYVER
ENV PYVER=${PYVER}
RUN apk add --no-cache bash
COPY install.sh /build/install.sh
COPY pip /build/pip
RUN /build/install.sh
Expand Down
33 changes: 17 additions & 16 deletions app/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@
set -euxo pipefail

BASEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

cd "${BASEDIR}"

apt-get update
apt-get install -qq -y aspell aspell-en
apt-get install -qq -y hunspell hunspell-en-au
apt-get install -qq -y shellcheck
apt-get install -qq -y git
apk add --no-cache \
build-base \
aspell aspell-en \
hunspell hunspell-en \
shellcheck \
git \
libxslt-dev \
libffi-dev \
openssl-dev

for PYVER in ${PYTHONVERS} ; do
cd "${BASEDIR}/pip/${PYVER}"
for reqfile in */requirements.txt ; do
if [ "$(wc -l < "${reqfile}")" -gt 0 ] ; then
"python${PYVER}" -m pip install -r "${reqfile}"
fi
done
# Display installation
"python${PYVER}" -m pip freeze
"python${PYVER}" -m safety check
cd "${BASEDIR}/pip/${PYVER}"
for reqfile in */requirements.txt ; do
if [ "$(wc -l < "${reqfile}")" -gt 0 ] ; then
"python${PYVER}" -m pip install -r "${reqfile}"
fi
done
# Display installation
"python${PYVER}" -m pip freeze
"python${PYVER}" -m safety check
2 changes: 1 addition & 1 deletion app/pip/2.7/test/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ isort
mock
pylint
pytest
pytest-azurepipelines42
pytest-azurepipelines
pytest-cov
pytest-xdist
safety
Expand Down
2 changes: 1 addition & 1 deletion app/pip/3.5/test/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ isort
mock
pylint
pytest
pytest-azurepipelines42
pytest-azurepipelines
pytest-cov
pytest-xdist
safety
Expand Down
1 change: 1 addition & 0 deletions app/pip/3.6/black/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
black
2 changes: 2 additions & 0 deletions app/pip/3.6/doco/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sphinx
sphinx_rtd_theme
4 changes: 4 additions & 0 deletions app/pip/3.6/spelling/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pyspelling
wcmatch<5.0
resplendent
unanimous
2 changes: 1 addition & 1 deletion app/pip/3.6/test/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ isort
mock
pylint
pytest
pytest-azurepipelines42
pytest-azurepipelines
pytest-cov
pytest-xdist
safety
Expand Down
1 change: 1 addition & 0 deletions app/pip/3.7/black/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
black
2 changes: 2 additions & 0 deletions app/pip/3.7/doco/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sphinx
sphinx_rtd_theme
4 changes: 4 additions & 0 deletions app/pip/3.7/spelling/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pyspelling
wcmatch<5.0
resplendent
unanimous
2 changes: 1 addition & 1 deletion app/pip/3.7/test/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ isort
mock
pylint
pytest
pytest-azurepipelines42
pytest-azurepipelines
pytest-cov
pytest-xdist
safety
Expand Down
2 changes: 1 addition & 1 deletion app/pip/3.8/test/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ isort
mock
pylint
pytest
pytest-azurepipelines42
pytest-azurepipelines
pytest-cov
pytest-xdist
safety
Expand Down
1 change: 1 addition & 0 deletions app/pip/3.9/app/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions app/pip/3.9/black/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
black
1 change: 1 addition & 0 deletions app/pip/3.9/coveralls/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
coveralls
2 changes: 2 additions & 0 deletions app/pip/3.9/doco/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sphinx
sphinx_rtd_theme
1 change: 1 addition & 0 deletions app/pip/3.9/news/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
towncrier
4 changes: 4 additions & 0 deletions app/pip/3.9/spelling/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pyspelling
wcmatch<5.0
resplendent
unanimous
14 changes: 14 additions & 0 deletions app/pip/3.9/test/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
bandit
dlint
flake8
isort
mock
pylint
pytest
pytest-azurepipelines
pytest-cov
pytest-xdist
safety
twine
wheel

1 change: 0 additions & 1 deletion ci/in_docker/news.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ BASEDIR="$( dirname "$( dirname "${THISDIR}" )" )"
# shellcheck source=/dev/null
source "${BASEDIR}/ci/in_docker/prepare.sh"

PYVER=3.8
cd "${BASEDIR}"
"python${PYVER}" -m towncrier "$@"
10 changes: 4 additions & 6 deletions ci/in_docker/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ source "${BASEDIR}/ci/in_docker/prepare.sh"

cd "${BASEDIR}/app"
rm -rf dist build
for PYVER in ${PYTHONVERS} ; do
"python${PYVER}" setup.py sdist bdist_wheel
done
python3.8 -m twine check dist/*
python3.8 -m twine upload --repository-url https://test.pypi.org/legacy/ dist/*
python3.8 -m twine upload dist/*
"python${PYVER}" setup.py sdist bdist_wheel
"python${PYVER}" -m twine check dist/*
"python${PYVER}" -m twine upload --repository-url https://test.pypi.org/legacy/ dist/*
"python${PYVER}" -m twine upload dist/*
37 changes: 16 additions & 21 deletions ci/in_docker/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,26 @@ source "${BASEDIR}/ci/in_docker/prepare.sh"

cd "${BASEDIR}"
find . -iname \*.sh -print0 | xargs -0 shellcheck
# Version independant checks
PYVER=3.8
# Run pyspelling in root to check docs
"python${PYVER}" -m pyspelling
# Run black to check all python on 3.8 only
# Run black to check all python
"python${PYVER}" -m black --check --diff "${BASEDIR}"
cd "${BASEDIR}/app"
# Version dependant checks
for PYVER in ${PYTHONVERS} ; do
"python${PYVER}" -m flake8 "${MODULES[@]}"
"python${PYVER}" -m isort -rc -c -m 3 -tc -w 88 --diff "${MODULES[@]}"
"python${PYVER}" -m bandit -r "${MODULES[@]}"
find "${MODULES[@]}" -iname \*.py -print0 | xargs -0 -n 1 "${BASEDIR}/ci/in_docker/pylint.sh" "python${PYVER}"
PYTEST_FAIL="NO"
if ! "python${PYVER}" -m pytest -n auto --cov-config=.coveragerc --cov-fail-under=100 "--cov=${MAIN_MODULE}" --cov-report=xml:test-cov.xml --cov-report=html ; then
PYTEST_FAIL="YES"
fi
if [ ! -z "${TRAVIS_JOB_ID:-}" ] ; then
"python${PYVER}" -m coveralls
fi
if [ "${PYTEST_FAIL}" == "YES" ] ; then
echo 'PyTest Failed!' >&2
exit 1
fi
done
"python${PYVER}" -m flake8 "${MODULES[@]}"
"python${PYVER}" -m isort -rc -c -m 3 -tc -w 88 --diff "${MODULES[@]}"
"python${PYVER}" -m bandit -r "${MODULES[@]}"
find "${MODULES[@]}" -iname \*.py -print0 | xargs -0 -n 1 "${BASEDIR}/ci/in_docker/pylint.sh" "python${PYVER}"
PYTEST_FAIL="NO"
if ! "python${PYVER}" -m pytest -n auto --cov-config=.coveragerc --cov-fail-under=100 "--cov=${MAIN_MODULE}" --cov-report=xml:test-cov.xml --cov-report=html ; then
PYTEST_FAIL="YES"
fi
if [ -n "${TRAVIS_JOB_ID:-}" ] ; then
"python${PYVER}" -m coveralls
fi
if [ "${PYTEST_FAIL}" == "YES" ] ; then
echo 'PyTest Failed!' >&2
exit 1
fi
# validate doco
"${BASEDIR}/ci/in_docker/doco.sh"
echo 'Testing Complete'
8 changes: 4 additions & 4 deletions ci/shared/_docker_helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

function docker_compose_run() {
USEROPT="$(id -u):$(id -g)"
docker-compose build
docker-compose up -d
docker-compose run --rm -u "${USEROPT}" "$@"
docker-compose down
docker-compose -p "py${PYVER}" build --build-arg PYVER="${PYVER}"
docker-compose -p "py${PYVER}" up -d
docker-compose -p "py${PYVER}" run --rm -u "${USEROPT}" "$@"
docker-compose -p "py${PYVER}" down
}
21 changes: 20 additions & 1 deletion ci/task.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ set -euxo pipefail
THISDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
BASEDIR="$( dirname "${THISDIR}" )"

: [ "${PYVER:=3.9}" ]
PYVERS=( "${PYVER}" "3.8" "3.7" "3.6" )

if ! which docker ; then
echo 'Docker is missing!' >&2
exit 1
Expand Down Expand Up @@ -35,6 +38,22 @@ fi
# shellcheck source=/dev/null
source "${BASEDIR}/ci/shared/_docker_helper.sh"

docker_compose_run "app" "${IN_DOCKER}" "${@:2}"
function saveenv {
cat <<EOF >"${BASEDIR}/.env"
PYVER=${PYVER}
EOF
}
case "${CMD}" in
test)
for PYVER in "${PYVERS[@]}" ; do
saveenv
docker_compose_run app "${IN_DOCKER}" "${@:2}"
done
;;
*)
saveenv
docker_compose_run app "${IN_DOCKER}" "${@:2}"
;;
esac


7 changes: 5 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ version: '3.7'
services:
# Service image
app:
image: module_goes_here:latest
build: app
image: module_goes_here:${PYVER}
build:
context: ./app
args:
- PYVER=${PYVER}
environment:
- HAS_JOSH_K_SEAL_OF_APPROVAL
- CI
Expand Down

0 comments on commit 57fcb4c

Please sign in to comment.