Skip to content
Snippets Groups Projects
Commit fc90bca9 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch 'rpm-package' into 'master'

rpm package

See merge request !425
parents e3c3c4ef 80c824e0
No related branches found
Tags v1.2.0
1 merge request!425rpm package
Pipeline #61772 passed
......@@ -46,5 +46,8 @@ smasch_*_amd64.build
smasch_*_amd64.changes
debian/
#rpm package tmp files
rpm
#OS generated folders
**/.DS_Store
\ No newline at end of file
**/.DS_Store
......@@ -149,7 +149,7 @@ test_install_debian_package_ubuntu_18:
#we need to wait a bit for gunicorn start
- sleep 15
- wget http://localhost:8888/account/login/?next=/
#test if we can login and list projects
#test if we can login
- test 302 = $(curl -X GET --write-out %{http_code} --silent --output /dev/null http://localhost:8888/)
- test 200 = $(curl -X GET --write-out %{http_code} --silent --output /dev/null http://localhost:8888/account/login/?next=/)
......@@ -228,3 +228,44 @@ lint:pep8:
- cp "local_settings_ci_sqlite.py" "smash/smash/local_settings.py"
- cd smash
- pycodestyle web
build_rpm:
stage: build
only:
- tags
artifacts:
# you cannot enforce never here yet
expire_in: 1000 yrs
paths:
- "rpm/RPMS/noarch/*.rpm"
script:
- apt-get update
- DEBIAN_FRONTEND=noninteractive apt-get install -y --allow-unauthenticated libsasl2-dev libssl-dev locales locales-all python3 dh-make build-essential lintian devscripts xsltproc fakeroot xsltproc docbook-xsl curl gnupg git gcc g++ make libsasl2-dev python-dev libldap2-dev libssl-dev rpm
- curl -sL https://deb.nodesource.com/setup_14.x | bash -
- DEBIAN_FRONTEND=noninteractive apt-get install -y nodejs
- pip install -r requirements.txt --default-timeout=180 -i https://pypi.lcsb.uni.lu/simple/
- pip install -r requirements-dev.txt --default-timeout=180 -i https://pypi.lcsb.uni.lu/simple/
- sh build_rpm.sh
test_install_rpm_package_rocky:
image: rockylinux
stage: test
only:
- tags
dependencies:
- build_rpm
script:
- ls -al
- yum -y localinstall rpm/RPMS/noarch/smasch-*.rpm
#systemd is not available on docker, so we need to start manually gunicorn (smasch.service is not tested)
- cd /usr/lib/smasch/
- /usr/lib/smasch/env/bin/gunicorn -b 127.0.0.1:8888 --pid smasch.pid smash.wsgi --error-logfile /var/log/smasch/gunicorn.log --log-level DEBUG --capture-output --limit-request-line 8192 &
#we need to wait a bit for gunicorn start
- sleep 15
- yum -y install wget curl
- wget http://localhost:8888/account/login/?next=/
#test if we can login
- test 302 = $(curl -X GET --write-out %{http_code} --silent --output /dev/null http://localhost:8888/)
- test 200 = $(curl -X GET --write-out %{http_code} --silent --output /dev/null http://localhost:8888/account/login/?next=/)
smasch (1.2.0~alpha.0-1) unstable; urgency=low
* small improvement: add possibility to include column
default_written_communication_language in the subject list as visible
smasch (1.2.0-1) unstable; urgency=low
* small improvement: rpm package is available
* small improvement: add possibility to include column
default_written_communication_language in the subject list as visible
column (#511)
* small improvement: export of subjects contains languages field (#507)
-- Carlos Vega <carlos.vega@uni.lu> Tue, 31 May 2022 12:15:00 +0200
-- Carlos Vega <carlos.vega@uni.lu> Thu, 16 Jun 2022 15:00:00 +0200
smasch (1.1.1-1) stable; urgency=medium
......
#!/bin/bash
CURRENT_VERSION=`cat CHANGELOG |grep smasch |head -1 | cut -f2 -d'(' | cut -f1 -d')' | cut -f1 -d'-' `
find . -name "*.py[co]" -exec rm -f {} \;
find . -name "__pycache__" -exec rm -rf {} \;
DIR=$(pwd)/rpm
rm -rf $DIR
mkdir -p $DIR/SPECS/
cp rpm-files/smasch.spec $DIR/SPECS/
sed -i "s/__CURRENT_VERSION__/$CURRENT_VERSION/g" $DIR/SPECS/smasch.spec
rpmbuild -v -ba --build-in-place --define "_topdir $DIR" $DIR/SPECS/smasch.spec
{
"lockfileVersion": 1
}
......@@ -121,12 +121,13 @@ pip install psycopg2 --global-option=build_ext --global-option="-I/usr/local/Cel
```
## Release new version
1. Create git tag (for example `v1.0.2`). This will trigger pipeline that will create deb package.
2. Login to LCSB repository `repo-r3lab.uni.lu` using ssh:
```
ssh 10.240.6.115 -p 8022
```
3. Download deb package artifact from `build_debian` job. The url of deb package can be found by: Select tag (`v1.0.2`)&rarr;Click hash (`0c664f23`)&rarr;Pipelines&rarr;Stages;build:passed&rarr;build_debian&rarr;Job artifacts&rarr;Browse&rarr;smasch_1.0.2-1_all.deb&rarr;Download. Not sure how to do it easier. For example:
3. Download deb package artifact from `build_debian` job and rpm package from `build_rpm` job. The url of deb package can be found by: Select tag (`v1.0.2`)&rarr;Click hash (`0c664f23`)&rarr;Pipelines&rarr;Stages;build:passed&rarr;build_debian&rarr;Job artifacts&rarr;Browse&rarr;smasch_1.0.2-1_all.deb&rarr;Download. Not sure how to do it easier. For example:
```
wget https://gitlab.lcsb.uni.lu/smasch/scheduling-system/-/jobs/282797/artifacts/raw/smasch_1.0.2-1_all.deb
```
......@@ -134,9 +135,17 @@ wget https://gitlab.lcsb.uni.lu/smasch/scheduling-system/-/jobs/282797/artifacts
```
sudo reprepro -b /var/www/html/debian includedeb stable smasch_1.0.2-1_all.deb
```
5. Put rpm file in repository.
```
sudo cp smasch-1.2.0~alpha.1-1.noarch.rpm /var/www/html/centOS/8/os/x86_64/
sudo rpm --addsign /var/www/html/centOS/8/os/x86_64/smasch-1.2.0~alpha.1-1.noarch.rpm
sudo createrepo --update /var/www/html/centOS/8/os/x86_64/
```
## Production deployment
### Debian/Ubuntu (deb package)
Smasch can be deployed using debian package provided in lcsb repository:
```bash
......@@ -146,6 +155,14 @@ apt-get update
apt-get install -y smasch
```
### CentOS (rpm package)
```bash
echo -e "[lcsbrepo]\nname=LCSB Repository\nbaseurl=https://repo-r3lab.uni.lu/centOS/8/os/x86_64/\nenabled=1\n" > /etc/yum.repos.d/lcsb.repo
rpmkeys --import https://repo-r3lab.uni.lu/LCSB-REPO-GPG-KEY
yum install smasch
```
Keep in mind that if you use selinux you need to configure it by yourself.
After smasch is installed you can start/stop it using systemd:
```bash
......
/var/log/smasch/gunicorn.log {
copytruncate
size 32k
weekly
dateext
rotate 52
compress
missingok
create 600 smasch smasch
}
/var/log/smasch/smasch.log {
copytruncate
size 32k
weekly
dateext
rotate 52
compress
missingok
create 600 smasch smasch
}
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'Paste long random string here' # Insert long random string
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
# Should the static/media files be served by Django
SERVE_STATIC = True
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': '/usr/lib/smasch/db.sqlite3',
}
}
STATIC_ROOT = '/usr/lib/smasch/data/static'
MEDIA_ROOT = '/usr/lib/smasch/data/media'
UPLOAD_ROOT = '/usr/lib/smasch/data/upload'
ETL_ROOT = '/usr/lib/smasch/data/etl'
ALLOWED_HOSTS = ["127.0.0.1", "localhost"]
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'file': {
'level': 'INFO',
'class': 'logging.FileHandler',
'filename': '/var/log/smasch/smasch.log',
'formatter': 'verbose'
},
'console': {
'class': 'logging.StreamHandler',
'level': 'DEBUG',
'formatter': 'simple'
},
},
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
},
'simple': {
'format': '%(levelname)s %(message)s'
},
},
'loggers': {
'django': {
'handlers': ['file'],
'level': 'INFO',
},
'web': {
'handlers': ['file'],
'level': 'DEBUG',
},
},
}
TWO_FACTOR_SMS_GATEWAY = "web.nexmo_gateway.Nexmo"
NPM_ROOT_PATH = '/usr/lib/smasch/'
[Unit]
Description=gunicorn daemon for smasch
After=network.target
[Service]
PIDFile=/run/smasch/pid
User=smasch
Group=smasch
RuntimeDirectory=smasch
WorkingDirectory=/usr/lib/smasch
ExecStart=/usr/lib/smasch/env/bin/gunicorn -b :8888 --pid /run/smasch/pid smash.wsgi --error-logfile /var/log/smasch/gunicorn.log --log-level DEBUG --capture-output --limit-request-line 0
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
Summary: SMart SCHeduling - research study scheduling program
Name: smasch
Version: __CURRENT_VERSION__
Release: 1%{?dist}
License: AGPLv3
URL: https://smasch.pages.uni.lu/
Group: Science
Packager: Piotr Gawron
Requires: libcurl-devel
Requires: libpng-devel
Requires: freetype-devel
Requires: postgresql-libs
Requires: postgresql-devel
Requires: gcc
Requires: gcc-toolset-11
Requires: python39-devel
Requires: gnutls-devel
Requires: libjpeg-devel
Requires: pkg-config
Requires: cronie
Requires: cyrus-sasl-devel
Requires: openldap-devel
Requires: openssl-devel
BuildRoot: rpm/
BuildArch: noarch
%install
ROOT_DIR=$(pwd)
rm -rf %{buildroot}
mkdir -p %{buildroot}%{_exec_prefix}/lib/%{name}
cp -r smash/web %{buildroot}%{_exec_prefix}/lib/%{name}/web
cp -r smash/package.json %{buildroot}%{_exec_prefix}/lib/%{name}
cp -r smash/smash %{buildroot}%{_exec_prefix}/lib/%{name}/smash
cp -r smash/db_scripts %{buildroot}%{_exec_prefix}/lib/%{name}/db_scripts
cp smash/manage.py %{buildroot}%{_exec_prefix}/lib/%{name}/manage.py
cp requirements.txt %{buildroot}%{_exec_prefix}/lib/%{name}
cp requirements-dev.txt %{buildroot}%{_exec_prefix}/lib/%{name}
cd %{buildroot}%{_exec_prefix}/lib/%{name}
echo "import os" > smash/local_settings.py
echo "STATIC_ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)),'../tmp-static')" >> smash/local_settings.py
echo "UPLOAD_ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)),'../tmp-static')" >> smash/local_settings.py
echo "SECRET_KEY ='tmp'" >> smash/local_settings.py
echo "STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage'" >> smash/local_settings.py
npm install
export PYTHONDONTWRITEBYTECODE=1
./manage.py collectstatic
rm -rf node_modules
mv tmp-static/npm node_modules
rm smash/local_settings.py
rm -rf tmp-static
cd $ROOT_DIR
mkdir -p %{buildroot}%{_sysconfdir}/%{name}/
cp rpm-files/smasch.py %{buildroot}%{_sysconfdir}/%{name}/
mkdir -p %{buildroot}%{_exec_prefix}/lib/systemd/system/
cp rpm-files/smasch.service %{buildroot}%{_exec_prefix}/lib/systemd/system/
mkdir -p %{buildroot}%{_sysconfdir}/logrotate.d/
cp rpm-files/smasch-logrotate %{buildroot}%{_sysconfdir}/logrotate.d/smasch
%files
#default config file
%config(noreplace) %{_sysconfdir}/%{name}/smasch.py
#logrotate config
%config %{_sysconfdir}/logrotate.d/smasch
#our app
%{_exec_prefix}/lib/%{name}/*
#systemd+gunicorn
%{_exec_prefix}/lib/systemd/system/smasch.service
%post
set -e
LOG_FILE=%{_localstatedir}/log/%{name}/install.log
if [ $1 -eq 1 ]; then
echo "First install complete"
id -u smasch &>/dev/null || useradd smasch
if ! getent group smasch >/dev/null; then
addgroup --quiet --system smasch
fi
ln -sf %{_sysconfdir}/%{name}/smasch.py %{_exec_prefix}/lib/%{name}/smash/local_settings.py
python3.9 -m venv %{_exec_prefix}/lib/%{name}/env
source %{_exec_prefix}/lib/%{name}/env/bin/activate && pip install --upgrade pip -q --log $LOG_FILE
chown smasch:smasch %{_sysconfdir}/%{name}/smasch.py
chmod 0600 %{_sysconfdir}/%{name}/smasch.py
mkdir -p %{_localstatedir}/log/%{name}
fi
echo "Installing python dependencies"
export PYCURL_SSL_LIBRARY=openssl #required by pycurl
{
source %{_exec_prefix}/lib/%{name}/env/bin/activate && pip install -r %{_exec_prefix}/lib/%{name}/requirements.txt -q --log $LOG_FILE
source %{_exec_prefix}/lib/%{name}/env/bin/activate && pip install -r %{_exec_prefix}/lib/%{name}/requirements-dev.txt -q --log $LOG_FILE
} || {
echo "There was an issue when installing python dependencies." >> $LOG_FILE
echo "There was an issue when installing python dependencies. Reinstall of smasch could help (in case you are upgrading smasch the data should not be lost in the process): "
echo "yum remove smasch"
echo "yum install smasch"
exit 1
}
echo "Collecting static files"
source %{_exec_prefix}/lib/%{name}/env/bin/activate && %{_exec_prefix}/lib/%{name}/manage.py collectstatic --no-input >> $LOG_FILE 2>&1
echo "Applying database changes"
source %{_exec_prefix}/lib/%{name}/env/bin/activate && %{_exec_prefix}/lib/%{name}/manage.py migrate --no-input >> $LOG_FILE 2>&1
chown -R smasch:smasch %{_exec_prefix}/lib/%{name}
chown -R smasch:smasch %{_localstatedir}/log/%{name}
if [ -d /run/systemd/system ]; then
systemctl --system daemon-reload >/dev/null || true
fi
crontab -u smasch -l 2>/dev/null | grep -v "runcrons" | { cat; echo "*/5 * * * * . /usr/lib/smasch/env/bin/activate && python /usr/lib/smasch/manage.py runcrons >> /var/log/smasch/cronjob.log 2>&1"; } | crontab -u smasch -
%postun
if [ -d /run/systemd/system ]; then
systemctl --system daemon-reload >/dev/null || true
fi
if [ $1 -eq 0 ]; then
rm -rf %{_exec_prefix}/lib/%{name}/env/
rm -rf %{_exec_prefix}/lib/%{name}/web/
rm -rf %{_exec_prefix}/lib/%{name}/smash/
fi
%preun
if [ -d /run/systemd/system ]; then
systemctl --system daemon-reload >/dev/null || true
systemctl stop smasch
fi
crontab -u smasch -l 2>/dev/null | grep -v "runcrons" | crontab -u smasch -
%description
SMart SCHeduling - research study scheduling program
The program controls and simplifies the scheduling, and is able to manage a
big data base of patients. Smasch is also used to organize the daily
planning's (delegation of tasks) for the different medical professionals
such as doctors, nurses and neuropsychologists.
\ No newline at end of file
......@@ -258,7 +258,7 @@ desired effect
{% block footer %}
<!-- To the right -->
<div class="pull-right hidden-xs">
Version: <strong>1.2.0~alpha.0</strong>
Version: <strong>1.2.0</strong>
</div>
<!-- Default to the left -->
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment