setup.py optimization and debian packaging

This commit is contained in:
s3lph 2018-09-15 02:12:16 +02:00
parent b3a1df9e18
commit 15a0a3a184
14 changed files with 167 additions and 26 deletions

View file

@ -6,31 +6,80 @@ stages:
- build
- staging
before_script:
- export MATEMAT_VERSION=$(python -c 'from matemat import __version__; print(__version__)')
test:
stage: test
script:
- pip3 install -r requirements.txt
- sudo -u matemat python3 -m coverage run --rcfile=setup.cfg -m unittest discover matemat
- sudo -u matemat python3 -m coverage combine
- sudo -u matemat python3 -m coverage report --rcfile=setup.cfg
- pip3 install -u .
- sudo -u matemat python3.7 -m coverage run --rcfile=setup.cfg -m unittest discover matemat
- sudo -u matemat python3.7 -m coverage combine
- sudo -u matemat python3.7 -m coverage report --rcfile=setup.cfg
codestyle:
stage: test
script:
- pip3 install -r requirements.txt
- pip3 install -u .
- sudo -u matemat pycodestyle matemat
build:
build_docker:
stage: build
script:
- docker build -t "registry.gitlab.com/s3lph/matemat:$(git rev-parse HEAD)" .
- docker tag "registry.gitlab.com/s3lph/matemat:$CI_COMMIT_SHA" "registry.gitlab.com/s3lph/matemat:latest-$([[ $CI_COMMIT_REF_NAME == "master" ]] && echo stable || echo staging)"
- docker build -t "registry.gitlab.com/s3lph/matemat:$CI_COMMIT_SHA" package/docker
- docker tag "registry.gitlab.com/s3lph/matemat:$CI_COMMIT_SHA" "registry.gitlab.com/s3lph/matemat:$CI_COMMIT_REF_NAME"
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_TOKEN registry.gitlab.com
- docker push "registry.gitlab.com/s3lph/matemat:$CI_COMMIT_SHA"
- docker push registry.gitlab.com/s3lph/matemat:latest-$([[ $CI_COMMIT_REF_NAME == "master" ]] && echo stable || echo staging)
- docker push "registry.gitlab.com/s3lph/matemat:$CI_COMMIT_REF_NAME"
only:
- staging
- master
- tags
build_wheel:
stage: build
script:
- python3.7 setup.py egg_info --tag-build "+$CI_COMMIT_SHA" --tag-date bdist_wheel
- python3.7 setup.py egg_info --tag-build "+$CI_COMMIT_REF_NAME" --tag-date bdist_wheel
artifacts:
paths:
- "dist/*.whl"
only:
- staging
- master
- tags
# This is only useful once Debian either defaults python3 to 3.7 or provides python3.7- packages
# for the needed dependencies... But it SHOULD work...
#build_deb:
# stage: build
# script:
# - cp -r static/ package/debian/matemat/usr/lib/matemat/static/
# - cp -r templates/ package/debian/matemat/usr/lib/matemat/templates/
# - python3.7 setup.py egg_info -d -b +master install --root=package/debian/matemat/ --prefix=/usr --optimize=1
# - export PYTHON_BIN=$(which python3)
# - cd package/debian
# - mv matemat/usr/lib/python3.7/{site,dist}-packages
# - mv matemat/usr/bin/matemat matemat/usr/lib/matemat/matemat
# - rm -r matemat/usr/bin
# - find . -type f -exec sed -re "s#${PYTHON_BIN}#/usr/bin/python3.7#g" -i {} \;
# - dpkg-deb --build matemat
# - mv matemat.deb "matemat_${MATEMAT_VERSION}+${CI_COMMIT_REF_NAME}-1_all.deb"
# artifacts:
# paths:
# - "package/debian/*.deb"
# only:
# - staging
# - master
# - tags
staging:
stage: staging

View file

@ -1,2 +1,2 @@
__version__ = '2.0'
__version__ = '0.1'

View file

@ -3,14 +3,15 @@ from typing import Any, Dict, Iterable, Union
import sys
from matemat.webserver import MatematWebserver
from matemat.webserver import parse_config_file
if __name__ == '__main__':
# Those imports are actually needed, as they implicitly register pagelets.
# noinspection PyUnresolvedReferences
from matemat.webserver.pagelets import *
from matemat.webserver import MatematWebserver
# Those imports are actually needed, as they implicitly register pagelets.
# noinspection PyUnresolvedReferences
from matemat.webserver.pagelets import *
def main():
# Use config file name from command line, if present
configfile: Union[str, Iterable[str]] = '/etc/matemat.conf'
if len(sys.argv) > 1:
@ -21,3 +22,7 @@ if __name__ == '__main__':
# Start the web server
MatematWebserver(**config).start()
if __name__ == '__main__':
main()

View file

@ -0,0 +1,5 @@
matemat (0.1-1) UNRELEASED; urgency=medium
* Initial release.
-- s3lph <account-gitlab-ideynizv@kernelpanic.lol> Wed, 12 Sep 2018 02:04:12 +0000

View file

@ -0,0 +1 @@
10

View file

@ -0,0 +1,11 @@
Package: matemat
Version: 0.1
Maintainer: s3lph <account-gitlab-ideynizv@kernelpanic.lol>
Section: web
Priority: extra
Architecture: all
Depends: python3 >= 3.7, python3-jinja2, python3-magic, python3-pil
Description: A soda machine stock-keeping webservice
A web service for automated stock-keeping of a soda machine written in Python.
It provides a touch-input-friendly user interface (as most input happens through the
soda machine's touch screen).

View file

@ -0,0 +1,16 @@
Copyright 2018 s3lph
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -0,0 +1 @@
/usr/lib/matemat/static/upload /var/lib/matemat/upload

View file

@ -0,0 +1,22 @@
#!/bin/bash
set -e
if [[ "$1" == "configure" ]]; then
if ! getent group matemat >/dev/null; then
addgroup --quiet --system matemat
fi
if ! getent passwd matemat >/dev/null; then
adduser --quiet --system --create-home --ingroup matemat --home /var/lib/matemat --shell /usr/sbin/nologin \
matemat
fi
chown matemat:matemat -R /var/lib/matemat
find /var/lib/matemat -type d -exec chmod 0750 {}
find /var/lib/matemat -type f -exec chmod 0640 {}
setcap CAP_NET_BIND_SERVICE=+eip /usr/bin/matemat
fi

View file

@ -0,0 +1,3 @@
#!/usr/bin/make -f
%:
dh $@

View file

@ -0,0 +1,10 @@
[Unit]
Description=matemat
After=networking.target
[Service]
Exec=/usr/lib/matemat/matemat /etc/matemat.conf /usr/lib/matemat/matemat.conf
User=matemat
[Install]
WantedBy=multi-user.target

View file

@ -1,10 +1,10 @@
FROM python:3.7-alpine
ADD . /
ADD ../.. /
RUN mkdir -p /var/matemat/db /var/matemat/upload \
&& apk --update add libmagic zlib jpeg zlib-dev jpeg-dev build-base \
&& pip3 install -r /requirements.txt \
&& pip3 install -u . \
&& apk del zlib-dev jpeg-dev build-base \
&& rm -rf /var/cache/apk /root/.cache/pip

View file

@ -1,3 +1 @@
file-magic
jinja2
Pillow
.

View file

@ -1,12 +1,32 @@
from setuptools import setup
from setuptools import setup, find_packages
from matemat import __version__
setup(
name='matemat',
version='2.0',
packages=['matemat'],
url='',
license='',
version=__version__,
url='https://gitlab.com/s3lph/matemat',
license='MIT',
author='s3lph',
author_email='',
description='Replacement for the original Ruby matemat software.'
description='Soda machine stock-keeping webservice',
long_description='''
A web service for automated stock-keeping of a soda machine written in Python.
It provides a touch-input-friendly user interface (as most input happens through the
soda machine's touch screen).
''',
packages=find_packages(exclude=['*.test']),
python_requires='>=3.7',
install_requires=[
'file-magic',
'jinja2',
'Pillow'
],
test_loader='unittest:TestLoader',
entry_points={
'console_scripts': [
'matemat = matemat.__main__:main'
]
}
)