Skip to content

Commit

Permalink
docker setup & images releaser for multiple archs
Browse files Browse the repository at this point in the history
This superseds and closes #93 & #96.
  • Loading branch information
kiorky committed Oct 25, 2024
1 parent b27788c commit 97936a9
Show file tree
Hide file tree
Showing 14 changed files with 209 additions and 48 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Dockerfile
docker-compose*
.git
76 changes: 54 additions & 22 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,72 @@
name: croniter
on: [workflow_dispatch, push, pull_request]
name: CI/CD
on:
push:
pull_request:
workflow_dispatch:
schedule: [{cron: '1 0 * * 6'}]
env:
DOCKER_BUILDKIT: "1"
COMPOSE_DOCKER_CLI_BUILD: "1"
BUILDKIT_PROGRESS: "plain"
RELEASABLE_REPOS: "^kiorky/"
RELEASABLE_BRANCHES: "^(refs/heads/)?(master|main|new-packaging)$"
jobs:
build-py2:
test-py2:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["2.7"]
strategy: {fail-fast: false}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Cache tox environments
uses: actions/cache@v4
with:
path: .cache
key: ${{ runner.os }}-py27
- name: install dependencies && test on py27
run: |
set -ex
export PIP_CACHE_DIR=$(pwd)/.cache/pip;export PIP_DOWNLOAD_CACHE=$PIP_CACHE_DIR
mkdir -pv $PIP_CACHE_DIR || true
sudo apt update && sudo apt install -y python2.7
# install py 2 with eg: apt install python2.7
mkdir venv2 && curl -sSL "https://github.com/pypa/get-virtualenv/blob/20.27.0/public/2.7/virtualenv.pyz?raw=true" > venv2/venv && python2.7 venv2/venv venv2
venv2/bin/python2 -m pip install -r ./requirements/test.txt
venv2/bin/tox --direct -e "py${pyver//\.}-{std,coverage}"
# we need the latest py2 compatible pytest which is not the latest available
venv2/bin/python2 -m pip install pytest -r <(grep -v pytest ./requirements/base.txt)
venv2/bin/pytest src
build-py3:
test-py3:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Cache tox environments
uses: actions/cache@v4
with:
path: .tox
key: ${{ runner.os }}-${{ matrix.python }}-tox
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with: {python-version: "${{ matrix.python-version }}", cache: pip, cache-dependency-path: 'requirements/*.txt'}
- name: install tests dependencies
run: pip install -r requirements/test.txt -r requirements/lint.txt -r requirements/tox.txt
- name: run lint
run: tox --current-env -e lint
- name: run tests with coverage
run: tox --current-env -e cov

test-32bits:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cache tox environments
uses: actions/cache@v4
with:
python-version: ${{ matrix.python-version }}
- name: install dependencies && test on py3
path: .dockertox
key: ${{ runner.os }}-${{ matrix.python }}-dockertox
- name: Test with pytest
run: |
set -ex
python -m pip install --upgrade --use-pep517 pip
pip install --use-pep517 -r requirements/test.txt
pyver=$(python --version 2>&1 | awk '{print substr($2, 0, 4)}' | awk '{ sub(/[ \t]+$/, ""); print }')
tox --direct -e "py${pyver//\.}-{std,coverage}"
docker compose build --build-arg BASE=corpusops/croniter:32bits
docker compose run --rm app tox --current-env -e test
env: {COMPOSE_FILE: "docker-compose.yml:docker-compose-32bits.yml"}

51 changes: 51 additions & 0 deletions .github/workflows/dockerimages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: docker images builder
on:
push:
pull_request:
workflow_dispatch:
schedule: [{cron: '1 0 * * 6'}]
env:
DOCKER_BUILDKIT: "1"
COMPOSE_DOCKER_CLI_BUILD: "1"
BUILDKIT_PROGRESS: "plain"
RELEASABLE_REPOS: "^kiorky/"
RELEASABLE_BRANCHES: "^(refs/heads/)?(master|main|new-packaging)$"
jobs:
docker-build:
runs-on: ubuntu-24.04
strategy:
max-parallel: 5
fail-fast: false
matrix:
FLAVOR: [32bits, latest]
env: {FLAVOR: "${{matrix.FLAVOR}}"}
steps:
- name: Set vars
run: |-
if ( echo "$GITHUB_REF" | egrep -q "${RELEASABLE_BRANCHES}" ) \
&& ( echo "$GITHUB_REPOSITORY" | egrep -q "${RELEASABLE_REPOS}" )
then releasable=true;else releasable=false;fi
echo "releasable=$releasable" >> $GITHUB_OUTPUT
id: v
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- uses: actions/checkout@v4
- name: Build
run: |
set -ex
export COMPOSE_FILE="docker-compose.yml:docker-compose-build.yml"
if ( echo "${{matrix.FLAVOR}}" | grep -q 32 );then
export COMPOSE_FILE="${COMPOSE_FILE}:docker-compose-32bits.yml:docker-compose-build-32bits.yml"
fi
echo ${COMPOSE_FILE}
docker compose build
- name: test
run: set -ex && docker compose run --rm app tox --current-env
- name: Release
run: |
if [ "x${{steps.v.outputs.releasable}}" = "xtrue" ];then
set -ex && docker push corpusops/croniter:${{matrix.FLAVOR}}
fi
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/.tox
/.*tox
.env
/dist
\.*.cfg
*.egg-info
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Changelog

- Fix overflow on 32bits systems (#87) [kiorky]
- Fix python2 testing (related to #93) [kiorky]
- Modernize packaging. Special thanks to Aarni Koskela (akx) for all the inputs. [kiorky]
- Modernize packaging. Special thanks to Aarni Koskela (akx) for all the inputs. [kiorky, akx]

3.0.3 (2024-07-26)
------------------
Expand Down
63 changes: 54 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,57 @@
ARG RSYNC=corpusops/rsync
ARG PY_VER=3.12.1
FROM python:${PY_VER}
ARG BASE=${BASE:-corpusops/ubuntu-bare:24.04}
FROM $BASE AS base
ENV CFLAGS="-I/usr/include/python3.12/"
ADD apt.txt ./
RUN <<EOF
set -ex
apt update
sed -re "/^# dev deps/,$ d" /apt.txt|grep -vE "^\s*#"|tr "\n" " " > apt.runtime
apt-get install -qq -y --no-install-recommends $( cat apt.runtime )
if ! ( python --version );then
ln -s /usr/bin/python3 /usr/bin/python
fi
if ! ( pip --version );then
wget https://bootstrap.pypa.io/get-pip.py
chmod +x get-pip.py
./get-pip.py --break-system-packages
fi
rm -rf /var/lib/apt/lists/*
EOF
FROM base AS final
RUN <<EOF
set -ex
apt update && apt-get install -qq -y --no-install-recommends $( grep -Ev '^#' apt.txt )
( mkdir src || true ) && touch src/__init__.py
EOF
WORKDIR app
ADD *.rst LICENSE MANIFEST.in *.txt *.cfg *.py *.ini ./
ADD ./src/ src/
ADD requirements/test.txt requirements/base.txt requirements/
RUN pip install --no-cache-dir --break-system-packages -r req*/test.txt
ADD requirements/lint.txt requirements/
RUN pip install --no-cache-dir --break-system-packages -r req*/lint.txt
ADD requirements/release.txt requirements/
RUN pip install --no-cache-dir --break-system-packages -r req*/release.txt
ADD requirements/tox.txt requirements/
RUN pip install --no-cache-dir --break-system-packages -r req*/tox.txt
RUN <<EOF
set -ex
apt remove -y python3-dev libpython3-dev cargo
apt autoremove -y
rm -rf /var/lib/apt/lists/*
EOF

# SQUASH Stage
FROM $RSYNC AS squashed-rsync
FROM base AS squashed-ancestor
WORKDIR /app
ADD *.rst LICENSE MANIFEST.in *.txt *.cfg *.py *.ini ./
ADD requirements/ ./requirements/
RUN mkdir src/ && touch src/__init__.py
RUN pip install -r req*/base.txt
RUN pip install -r req*/release.txt
RUN pip install -r req*/test.txt
ADD *.rst LICENSE MANIFEST.in *.txt *.sh *.cfg *.py *.ini ./
ARG ROOTFS="/BASE_ROOTFS_TO_COPY_THAT_WONT_COLLIDE_1234567890"
ARG PATH="${ROOTFS}_rsync/bin:$PATH"
RUN --mount=type=bind,from=final,target=$ROOTFS --mount=type=bind,from=squashed-rsync,target=${ROOTFS}_rsync \
rsync -Aaz --delete ${ROOTFS}/ / --exclude=/proc --exclude=/sys --exclude=/etc/resolv.conf --exclude=/etc/hosts --exclude=$ROOTFS* --exclude=dev/shm --exclude=dev/pts --exclude=dev/mqueue
ADD *.rst LICENSE MANIFEST.in *.txt *.cfg *.py *.ini *sh ./
ADD src/ src/
ENTRYPOINT /app/docker-entry.sh
ENTRYPOINT ["/app/docker-entry.sh"]
CMD []
15 changes: 7 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,9 @@ Develop this package

git clone https://github.com/kiorky/croniter.git
cd croniter
virtualenv --no-site-packages venv
. venv/bin/activate
pip install --upgrade -r requirements/test.txt
py.test src
virtualenv --no-site-packages venv3
venv3/bin/pip install --upgrade -r requirements/test.txt -r requirements/lint.txt -r requirements/tox.txt
venv3/bin/tox --current-env -e lint,test


Testing under py2
Expand All @@ -336,7 +335,7 @@ Install prerequisisites ::

Run tests::

./venv2/bin/tox --direct -e py27-std
./venv2/bin/pytest src


Make a new release
Expand All @@ -346,16 +345,16 @@ We use zest.fullreleaser, a great release infrastructure.
Do and follow these instructions
::

. venv/bin/activate
pip install --upgrade -r requirements/release.txt
venv3/bin/pip install --upgrade -r requirements/release.txt
./release.sh


Contributors
===============
Thanks to all who have contributed to this project!
If you have contributed and your name is not listed below please let me know.
If you have contributed and your name is not listed below please let us know.

- Aarni Koskela (akx)
- mrmachine
- Hinnack
- shazow
Expand Down
7 changes: 7 additions & 0 deletions apt.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
python3

# dev deps
python3-dev
libpython3-dev
cargo
git-core
3 changes: 3 additions & 0 deletions docker-compose-32bits.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
services:
app:
image: "${CRONITER_IMAGE:-corpusops/croniter:32bits}"
6 changes: 6 additions & 0 deletions docker-compose-build-32bits.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
services:
app:
build:
cache_from: ["${CRONITER_IMAGE:-corpusops/croniter:32bits}"]
args:
BASE: "corpusops/debian-32:trixie"
7 changes: 7 additions & 0 deletions docker-compose-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:
app:
build:
cache_from: ["${CRONITER_IMAGE:-corpusops/croniter:latest}"]
context: .
args:
BUILDKIT_INLINE_CACHE: "1"
10 changes: 6 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
version: "3.8"
services:
app:
build: {context: .}
image: "${CRONITER_IMAGE:-corpusops/croniter:latest}"
volumes:
- ./src:/app/src
- ./setup.py:/app/setup.py
- ./docker-entry.sh:/app/docker-entry.sh
- ./.dockertox:/app/.tox
- ./setup.cfg:/app/setup.cfg
- ./setup.py:/app/setup.py
- ./src:/app/src
- ./tox.ini:/app/tox.ini
9 changes: 7 additions & 2 deletions docker-entry.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#!/usr/bin/env bash
[[ -n "${SDEBUG}" ]] && set -x
cd /app
python setup.py develop >/dev/null 2>&1
exec bash $@
# vim:set et sts=4 ts=4 tw=80:
if [[ -z $@ ]];then
exec bash
else
exec "$@"
fi
# vim:set et sts=4 ts=4 tw=0:
2 changes: 1 addition & 1 deletion release.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
set -ex
. venv/bin/activate
. venv3/bin/activate
fullrelease
git push taichino && git push taichino --tags
# vim:set et sts=4 ts=4 tw=80:

0 comments on commit 97936a9

Please sign in to comment.