setup.py optimization and debian packaging
This commit is contained in:
parent
b3a1df9e18
commit
15a0a3a184
14 changed files with 167 additions and 26 deletions
|
@ -6,31 +6,80 @@ stages:
|
||||||
- build
|
- build
|
||||||
- staging
|
- staging
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- export MATEMAT_VERSION=$(python -c 'from matemat import __version__; print(__version__)')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
test:
|
test:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- pip3 install -r requirements.txt
|
- pip3 install -u .
|
||||||
- sudo -u matemat python3 -m coverage run --rcfile=setup.cfg -m unittest discover matemat
|
- sudo -u matemat python3.7 -m coverage run --rcfile=setup.cfg -m unittest discover matemat
|
||||||
- sudo -u matemat python3 -m coverage combine
|
- sudo -u matemat python3.7 -m coverage combine
|
||||||
- sudo -u matemat python3 -m coverage report --rcfile=setup.cfg
|
- sudo -u matemat python3.7 -m coverage report --rcfile=setup.cfg
|
||||||
|
|
||||||
codestyle:
|
codestyle:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- pip3 install -r requirements.txt
|
- pip3 install -u .
|
||||||
- sudo -u matemat pycodestyle matemat
|
- sudo -u matemat pycodestyle matemat
|
||||||
|
|
||||||
build:
|
|
||||||
|
|
||||||
|
build_docker:
|
||||||
stage: build
|
stage: build
|
||||||
script:
|
script:
|
||||||
- docker build -t "registry.gitlab.com/s3lph/matemat:$(git rev-parse HEAD)" .
|
- 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:latest-$([[ $CI_COMMIT_REF_NAME == "master" ]] && echo stable || echo staging)"
|
- 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 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:$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:
|
only:
|
||||||
- staging
|
- staging
|
||||||
- master
|
- 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:
|
staging:
|
||||||
stage: staging
|
stage: staging
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
|
|
||||||
__version__ = '2.0'
|
__version__ = '0.1'
|
||||||
|
|
|
@ -3,14 +3,15 @@ from typing import Any, Dict, Iterable, Union
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from matemat.webserver import MatematWebserver
|
||||||
from matemat.webserver import parse_config_file
|
from matemat.webserver import parse_config_file
|
||||||
|
|
||||||
if __name__ == '__main__':
|
# Those imports are actually needed, as they implicitly register pagelets.
|
||||||
# Those imports are actually needed, as they implicitly register pagelets.
|
# noinspection PyUnresolvedReferences
|
||||||
# noinspection PyUnresolvedReferences
|
from matemat.webserver.pagelets import *
|
||||||
from matemat.webserver.pagelets import *
|
|
||||||
from matemat.webserver import MatematWebserver
|
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
# Use config file name from command line, if present
|
# Use config file name from command line, if present
|
||||||
configfile: Union[str, Iterable[str]] = '/etc/matemat.conf'
|
configfile: Union[str, Iterable[str]] = '/etc/matemat.conf'
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
|
@ -21,3 +22,7 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
# Start the web server
|
# Start the web server
|
||||||
MatematWebserver(**config).start()
|
MatematWebserver(**config).start()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
|
5
package/debian/matemat/DEBIAN/changelog
Normal file
5
package/debian/matemat/DEBIAN/changelog
Normal 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
|
1
package/debian/matemat/DEBIAN/compat
Normal file
1
package/debian/matemat/DEBIAN/compat
Normal file
|
@ -0,0 +1 @@
|
||||||
|
10
|
11
package/debian/matemat/DEBIAN/control
Normal file
11
package/debian/matemat/DEBIAN/control
Normal 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).
|
16
package/debian/matemat/DEBIAN/copyright
Normal file
16
package/debian/matemat/DEBIAN/copyright
Normal 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.
|
1
package/debian/matemat/DEBIAN/matemat.links
Normal file
1
package/debian/matemat/DEBIAN/matemat.links
Normal file
|
@ -0,0 +1 @@
|
||||||
|
/usr/lib/matemat/static/upload /var/lib/matemat/upload
|
22
package/debian/matemat/DEBIAN/postinst
Executable file
22
package/debian/matemat/DEBIAN/postinst
Executable 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
|
3
package/debian/matemat/DEBIAN/rules
Executable file
3
package/debian/matemat/DEBIAN/rules
Executable file
|
@ -0,0 +1,3 @@
|
||||||
|
#!/usr/bin/make -f
|
||||||
|
%:
|
||||||
|
dh $@
|
|
@ -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
|
|
@ -1,10 +1,10 @@
|
||||||
|
|
||||||
FROM python:3.7-alpine
|
FROM python:3.7-alpine
|
||||||
|
|
||||||
ADD . /
|
ADD ../.. /
|
||||||
RUN mkdir -p /var/matemat/db /var/matemat/upload \
|
RUN mkdir -p /var/matemat/db /var/matemat/upload \
|
||||||
&& apk --update add libmagic zlib jpeg zlib-dev jpeg-dev build-base \
|
&& 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 \
|
&& apk del zlib-dev jpeg-dev build-base \
|
||||||
&& rm -rf /var/cache/apk /root/.cache/pip
|
&& rm -rf /var/cache/apk /root/.cache/pip
|
||||||
|
|
|
@ -1,3 +1 @@
|
||||||
file-magic
|
.
|
||||||
jinja2
|
|
||||||
Pillow
|
|
||||||
|
|
32
setup.py
32
setup.py
|
@ -1,12 +1,32 @@
|
||||||
from setuptools import setup
|
from setuptools import setup, find_packages
|
||||||
|
|
||||||
|
from matemat import __version__
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='matemat',
|
name='matemat',
|
||||||
version='2.0',
|
version=__version__,
|
||||||
packages=['matemat'],
|
url='https://gitlab.com/s3lph/matemat',
|
||||||
url='',
|
license='MIT',
|
||||||
license='',
|
|
||||||
author='s3lph',
|
author='s3lph',
|
||||||
author_email='',
|
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'
|
||||||
|
]
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue