Skip to content

Commit

Permalink
Merge pull request #1156 from Kisuke-CZE/master
Browse files Browse the repository at this point in the history
Updated packaging for RPM and DEB
  • Loading branch information
farirat authored Nov 23, 2023
2 parents 52962a5 + 50c6f03 commit 8be6917
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 102 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ on:
pull_request:
branches:
- 'master'
- '0.9'
- '0.10'
- '0.10.*'
- '0.10-develop'
- '0.11-develop'

env:
GITHUB_TOKEN: ${{ secrets.COVERALLS_TOKEN }}
Expand Down
2 changes: 2 additions & 0 deletions misc/config/jasmind.environment
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
JCLI_USERNAME='jcliadmin'
JCLI_PASSWORD='jclipwd'
2 changes: 1 addition & 1 deletion misc/config/systemd/jasmin-celery.service
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ SyslogIdentifier=jasmin-celery
PIDFile=/run/jasmin-celery.pid
User=jasmin
Group=jasmin
ExecStart=/bin/sh -c "celery -A jasmin.protocols.rest.tasks worker -l INFO -c 4 --autoscale=10,3"
ExecStart=/bin/sh -c "/opt/jasmin-sms-gateway/venv/bin/celery -A jasmin.protocols.rest.tasks worker -l INFO -c 4 --autoscale=10,3"

[Install]
WantedBy=multi-user.target
2 changes: 1 addition & 1 deletion misc/config/systemd/jasmin-dlrd.service
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ SyslogIdentifier=jasmin-dlrd
PIDFile=/run/jasmin-dlrd.pid
User=jasmin
Group=jasmin
ExecStart=/usr/local/bin/dlrd.py
ExecStart=/opt/jasmin-sms-gateway/venv/bin/dlrd.py

[Install]
WantedBy=multi-user.target
2 changes: 1 addition & 1 deletion misc/config/systemd/jasmin-dlrlookupd.service
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ SyslogIdentifier=jasmin-dlrlookupd
PIDFile=/run/jasmin-dlrlookupd.pid
User=jasmin
Group=jasmin
ExecStart=/usr/local/bin/dlrlookupd.py
ExecStart=/opt/jasmin-sms-gateway/venv/bin/dlrlookupd.py

[Install]
WantedBy=multi-user.target
2 changes: 1 addition & 1 deletion misc/config/systemd/jasmin-interceptord.service
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ SyslogIdentifier=interceptord
PIDFile=/run/interceptord.pid
User=jasmin
Group=jasmin
ExecStart=/usr/local/bin/interceptord.py
ExecStart=/opt/jasmin-sms-gateway/venv/bin/interceptord.py

[Install]
WantedBy=multi-user.target
2 changes: 1 addition & 1 deletion misc/config/systemd/jasmin-restapi.service
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ SyslogIdentifier=jasmin-restapi
PIDFile=/run/jasmin-restapi.pid
User=jasmin
Group=jasmin
ExecStart=/bin/sh -c "twistd3 -n --pidfile=/tmp/twistd-web-restapi.pid web --wsgi=jasmin.protocols.rest.api"
ExecStart=/bin/sh -c "/opt/jasmin-sms-gateway/venv/bin/twistd -n --pidfile=/tmp/twistd-web-restapi.pid web --wsgi=jasmin.protocols.rest.api --listen=tcp:1402"

[Install]
WantedBy=multi-user.target
3 changes: 2 additions & 1 deletion misc/config/systemd/jasmind.service
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ SyslogIdentifier=jasmind
PIDFile=/run/jasmind.pid
User=jasmin
Group=jasmin
ExecStart=/usr/local/bin/jasmind.py --username jcliadmin --password jclipwd
ExecStart=/opt/jasmin-sms-gateway/venv/bin/jasmind.py --enable-interceptor-client
EnvironmentFile=/etc/jasmin/jasmind.environment

[Install]
WantedBy=multi-user.target
63 changes: 40 additions & 23 deletions misc/packaging/scripts/common-postinstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,61 @@ set -e

JASMIN_USER="jasmin"
JASMIN_GROUP="jasmin"
JASMIN_VENV_DIR="/opt/jasmin-sms-gateway"
JASMIN_CFG_STORAGE="/var/log/jasmin"
JASMIN_LOG_DIR="/etc/jasmin/store"

PACKAGE_NAME="jasmin-sms-gateway"
PYPI_NAME="jasmin"

function create_dir {
if [ ! -d ${1} ]
then
mkdir ${1}
chown -R "${JASMIN_USER}:${JASMIN_GROUP}" ${1}
fi
}

# Provision user/group
getent group ${JASMIN_GROUP} || groupadd -r "${JASMIN_GROUP}"
grep -q "^${JASMIN_USER}:" /etc/passwd || useradd -r -g ${JASMIN_GROUP} \
-d ${JASMIN_VENV_DIR} -s /sbin/nologin \
-c "Jasmin SMS Gateway user" ${JASMIN_USER}

# If there is any VENV from previous version, just remove it (configs are safe in /etc ) - we do not want any conflicts
if [ -d ${JASMIN_VENV_DIR} ]
then
rm -rf ${JASMIN_VENV_DIR}
fi

# Create empty directories
create_dir ${JASMIN_CFG_STORAGE}
create_dir ${JASMIN_LOG_DIR}
create_dir ${JASMIN_VENV_DIR}

# Find latest installed python version available on system
LATEST_PYTHON="$(find /usr/bin/ -maxdepth 1 -regex '.*python3\.[0-9]+' | sort --version-sort | tail -n 1)"
# LATEST_PYTHON="$(basename ${LATEST_PYTHON})" # Not needed

# Get installed package version and install the related pypi package(s)
if [ "$(grep -Ei 'debian|buntu' /etc/*release)" ]; then
PACKAGE_VERSION=$(dpkg -s "$PACKAGE_NAME"|grep ^Version:|awk '{print $2}')
pip3 install "$PYPI_NAME"=="$PACKAGE_VERSION"
elif [ "$(grep -Ei 'centos|rhel|fedora' /etc/*release)" ]; then
PACKAGE_VERSION=$(rpm -qi "$PACKAGE_NAME"|grep ^Version|awk {'print $3'})
pip3 install "$PYPI_NAME"=="$PACKAGE_VERSION"
PACKAGE_VERSION=$(dpkg -s "${PACKAGE_NAME}"|grep ^Version:|awk -F '[- ]' '{print $2}' | sort --version-sort | tail -n 1)
elif [ "$(grep -Ei 'centos|rhel|fedora|almalinux' /etc/*release)" ]; then
PACKAGE_VERSION=$(rpm -qi "${PACKAGE_NAME}"|grep ^Version|awk {'print $3'} | sort --version-sort | tail -n 1)
else
echo "ERROR: Unsupported OS for this package."
exit 1
fi

# Provision user/group
getent group $JASMIN_GROUP || groupadd -r "$JASMIN_GROUP"
grep -q "^${JASMIN_USER}:" /etc/passwd || useradd -r -g $JASMIN_GROUP \
-d /usr/share/jasmin -s /sbin/nologin \
-c "Jasmin SMS Gateway user" $JASMIN_USER

# Create empty directories
mkdir /etc/jasmin/store
mkdir /var/log/jasmin

# Change owner of required folders
chown -R "$JASMIN_USER:$JASMIN_GROUP" /etc/jasmin/store/
chown -R "$JASMIN_USER:$JASMIN_GROUP" /var/log/jasmin
# Create VENV and install jasmin and all dependencies from pipy into that VENV
# sudo -u jasmin virtualenv -p ${LATEST_PYTHON} ${JASMIN_VENV_DIR}/venv
sudo -u "${JASMIN_USER}" ${LATEST_PYTHON} -m venv ${JASMIN_VENV_DIR}/venv
source ${JASMIN_VENV_DIR}/venv/bin/activate
sudo -u "${JASMIN_USER}" ${JASMIN_VENV_DIR}/venv/bin/pip install "${PYPI_NAME}"=="${PACKAGE_VERSION}"

if [ "$1" = configure ]; then
# Enable jasmind service
/bin/systemctl daemon-reload
/bin/systemctl enable jasmind
fi

# python3-falcon package is not available in centos/rhel 8
# this is a workaround
if [ "$(grep -Ei 'centos|rhel|fedora' /etc/*release)" ]; then
pip3 install falcon==2.0.0
fi
10 changes: 3 additions & 7 deletions misc/packaging/scripts/common-preremove.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@
set -e

PYPI_NAME="jasmin"

pip3 uninstall -y "$PYPI_NAME"
JASMIN_VENV_DIR="/opt/jasmin-sms-gateway/"

# Stop and disable jasmind service
/bin/systemctl stop jasmind
/bin/systemctl disable jasmind
/bin/systemctl daemon-reload

# python3-falcon package is not available in centos/rhel 8
# this is a workaround
if [ "$(grep -Ei 'centos|rhel|fedora' /etc/*release)" ]; then
pip3 uninstall -y falcon==2.0.0
fi
# Remove whole VENV whe jasmin lives
rm -rf "${JASMIN_VENV_DIR}"
85 changes: 22 additions & 63 deletions nfpm.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "jasmin-sms-gateway"
arch: "amd64"
arch: "all"
platform: "linux"
version: "v0.11.1"
section: "default"
Expand Down Expand Up @@ -35,16 +35,21 @@ provides:
contents:
- src: ./misc/config/jasmin.cfg
dst: "/etc/jasmin/jasmin.cfg"
type: config
type: config|noreplace
- src: ./misc/config/interceptor.cfg
dst: "/etc/jasmin/interceptor.cfg"
type: config
type: config|noreplace
- src: ./misc/config/dlr.cfg
dst: "/etc/jasmin/dlr.cfg"
type: config
type: config|noreplace
- src: ./misc/config/jasmind.environment
dst: "/etc/jasmin/jasmind.environment"
type: config|noreplace
file_info:
mode: 0660
- src: ./misc/config/dlrlookupd.cfg
dst: "/etc/jasmin/dlrlookupd.cfg"
type: config
type: config|noreplace
- src: ./misc/config/resource/amqp0-9-1.xml
dst: "/etc/jasmin/resource/amqp0-9-1.xml"
type: config
Expand All @@ -53,80 +58,34 @@ contents:
type: config
- src: ./misc/config/systemd/jasmind.service
dst: "/usr/lib/systemd/system/jasmind.service"
type: config
- src: ./misc/config/systemd/jasmin-celery.service
dst: "/usr/lib/systemd/system/jasmin-celery.service"
type: config
- src: ./misc/config/systemd/jasmin-dlrd.service
dst: "/usr/lib/systemd/system/jasmin-dlrd.service"
type: config
- src: ./misc/config/systemd/jasmin-dlrlookupd.service
dst: "/usr/lib/systemd/system/jasmin-dlrlookupd.service"
type: config
- src: ./misc/config/systemd/jasmin-interceptord.service
dst: "/usr/lib/systemd/system/jasmin-interceptord.service"
type: config
- src: ./misc/config/systemd/jasmin-restapi.service
dst: "/usr/lib/systemd/system/jasmin-restapi.service"
type: config
- src: ./jasmin/bin/jasmind.py
dst: "/usr/local/bin/jasmind.py"
- src: ./jasmin/bin/interceptord.py
dst: "/usr/local/bin/interceptord.py"
- src: ./jasmin/bin/dlrd.py
dst: "/usr/local/bin/dlrd.py"
- src: ./jasmin/bin/dlrlookupd.py
dst: "/usr/local/bin/dlrlookupd.py"
scripts:
postinstall: ./misc/packaging/scripts/common-postinstall.sh
preremove: ./misc/packaging/scripts/common-preremove.sh
rpm:
scripts:
posttrans: ./misc/packaging/scripts/common-postinstall.sh
overrides:
deb:
scripts:
postinstall: ./misc/packaging/scripts/common-postinstall.sh
depends:
- python3 (>= 3.8)
- adduser
- python3-twisted
- python3-dateutil
- python3-pyparsing
- python3-lockfile
- python3-requests
- python3-setuptools
- python3-mimeparse
- python3-celery
- python-celery-common
- python3-falcon
- python3-redis
- python3-amqp
- python3-tabulate
- python3-treq
# These dependencies come from Jookies package repository
- python3-jookies-messaging
- python3-txredisapi
- python3-txamqp3
- python3-smpp-pdu3
- python3-smpp-twisted3
- python3-venv
- sudo
# All dependecies all installed to VENV via pip
rpm:
depends:
- epel-release
- python3 (>= 3.8)
- python3-twisted
- python3-dateutil
- python3-pyparsing
- python3-lockfile
- python3-requests
- python3-setuptools
- python3-mimeparse
- python3-celery
- python3-redis
- python3-amqp
- python3-tabulate
- python3-treq
# These dependencies come from Jookies package repository
- python3-jookies-messaging
- python3-txredisapi
- python3-txamqp3
- python3-smpp-pdu3
- python3-smpp-twisted3
# There's no python3-falcon package for CentOS/RHEL 8
# It will be handled by the pre/post scripts
#- python3-falcon
- python(abi) >= 3.8
- sudo
# All dependecies all installed to VENV via pip
# Dependecy on epel-release removed - it's not needed on most RHEL version and you might have your own EPEL clone or another source for packages

0 comments on commit 8be6917

Please sign in to comment.