Skip to content

Commit

Permalink
build: fix pyver, remove upx req, change msgs"
Browse files Browse the repository at this point in the history
  • Loading branch information
silv3rr committed Aug 9, 2024
1 parent e334998 commit 28fd929
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 69 deletions.
30 changes: 4 additions & 26 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,8 @@ jobs:
- uses: actions/checkout@v4
- name: Run apt, venv, pip, build and upload artifacts
run: |
DEB="upx-ucl_3.96-2_amd64.deb"
export DEBIAN_FRONTEND=noninteractive
apt-get update -y
if ! DEBIAN_FRONTEND=noninteractive apt-get install -y upx-ucl; then
apt-get install -y libucl1 &&
wget -q http://ftp.us.debian.org/debian/pool/main/u/upx-ucl/$DEB &&
dpkg -i $DEB;
fi
python3 -m venv venv && . venv/bin/activate
pip3 install --upgrade pip wheel setuptools
pip3 install -r requirements.txt
Expand All @@ -83,7 +77,7 @@ jobs:
path: ./build-debian/*
if-no-files-found: error

# disabled, EOL
# XXX: disabled, EOL
# centos7-container-build-job:
# name: Build for CentOS 7
# runs-on: ubuntu-latest
Expand All @@ -98,8 +92,6 @@ jobs:
# - name: Run yum, venv, pip, build and upload artifacts
# run: |
# yum install -y gcc python3-devel python3-pip python3-virtualenv
# yum install -y https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/u/ucl-1.03-24.el7.x86_64.rpm
# yum install -y https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/u/upx-3.96-9.el7.x86_64.rpm
# python3 -m venv venv && . venv/bin/activate
# pip3 install --upgrade pip wheel setuptools
# pip3 install -r requirements.txt
Expand Down Expand Up @@ -134,7 +126,6 @@ jobs:
run: |
dnf install -y gcc python3-devel python3-pip
dnf install -y epel-release
dnf install -y upx ucl
python3 -m venv venv && . venv/bin/activate
pip3 install --upgrade pip wheel setuptools
pip3 install -r requirements.txt
Expand All @@ -154,12 +145,13 @@ jobs:
- uses: actions/checkout@v4
- name: Run ap, venv, pip, build and upload artifacts
run: |
apk add python3 python3-dev py3-pip py3-virtualenv gcc musl-dev upx
apk add python3 python3-dev py3-pip py3-virtualenv gcc musl-dev
python3 -m venv venv && . venv/bin/activate
pip3 install --upgrade pip wheel setuptools
pip3 install -r requirements.txt
pip3 install pyinstaller sysv-ipc geoip2 flask
./build.sh && mkdir ./build-alpine && mv -f *.tar.gz *.sha512sum ./build-alpine
WEBSPY=1 ./build.sh && mkdir ./build-alpine && mv -f *.tar.gz *.sha512sum ./build-alpine
- uses: actions/upload-artifact@v4
with:
name: build-alpine-artifacts
Expand All @@ -176,23 +168,9 @@ jobs:
uses: actions/download-artifact@v4
with:
path: build-artifacts

# - name: Create gh release using 'hub'
# run: |
# gh release create $(find -type f -printf '--attach %p ') slv-pyspy-v$(date +%Y%m%d) --file - <<'#####'
# pyspy
#
# Shows users logged into glftpd in terminal or as web page. Like 'gl_spy' and 'webspy' from foo-tools.
#
# Download binaries for your specific OS
# #####
# working-directory: ./build-artifacts
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# XXX: (replaced) hub release create slv-pyspy-v$(date +%Y%m%d) $(find -type f -printf '%p ') --notes-file - <<'#####'
- name: Create release using 'gh'
run: |
gh release create slv-pyspy-v$(date +%Y%m%d) $(find -type f -printf '%p ') --notes-file - <<'#####'
Shows users logged into glftpd in terminal or as web page. Like 'gl_spy' and 'webspy' from foo-tools.
Download binaries for your specific OS
Expand Down
45 changes: 23 additions & 22 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
# Required: Python 3.7.3+, sysv-ipc, pyinstaller
# python3 -m venv venv && . venv/bin/activate && \
# pip3 install wheel setuptools sysv_ipc pyinstaller
# Recommended: upx
# apt install upx-ucl or yum install upx

PYREQVER="3.7"
PYSRC="spy.py"
Expand All @@ -16,19 +14,21 @@ PACK=1
REQS="$(cut -d= -f1 requirements.txt 2>/dev/null)"
ARGS="--hidden-import sysv_ipc"
OPTS="_WITH_GEOIP _WITH_HTTPD _WITH_FLASK _WITH_BUNDLE"
PACKFILES="../spy.conf spy ../webspy"

if [ "${WEBSPY:-0}" -eq 1 ]; then
PKG_SUFFIX="-web"
ARGS=" $ARGS --add-data webspy:./webspy "
# use webspy dir from bundule
PACKFILES="../spy.conf spy"
PACKSUFFIX="-web"
# shellcheck disable=SC2086
if echo $OPTS | grep -q "_WITH_BUNDLE"; then
sed -i "s/^\(_WITH_BUNDLE\) *= *.*$/\1 = True/" "$PYSRC"
fi
echo "build: including webspy dir in pyinstaller bundle..."
fi

if [ ! -s requirements.txt ] || [ -z "$REQS" ]; then
echo "WARNING: missing requirements"
echo "build: WARNING missing requirements"
fi

for a in "$@"; do
Expand Down Expand Up @@ -60,21 +60,22 @@ if echo $OPTS | grep -q "_WITH_FLASK"; then
sed -i "s/^\(FLASK_OPTIONS\['debug']\) *= *.*$/\1 = False/" "$PYSRC"
fi

echo "Creating one single executable file..."
echo "build: creating one single executable file..."

if [ -n "$VIRTUAL_ENV" ]; then
echo "Running in venv: ${VIRTUAL_ENV}..."
echo "build: running in venv: ${VIRTUAL_ENV}..."
else
echo "Not running in venv..."
echo "build: not running in venv..."
fi

if [ ! -e "$PYSRC" ]; then
echo "ERROR: '$PYSRC' not found"
echo "build: ERROR '$PYSRC' not found"
exit 1
fi

printf "build: "
command -V python3 || {
echo "ERROR: python3 not found"
echo "build: ERROR python3 not found"
exit 1
}
#command -V bc || { echo "ERROR: bc not found"; exit 1; }
Expand All @@ -86,7 +87,7 @@ PYVER_OK=0
# PYVER_OK=1
# fi
#else
PYVER_MAY="$(echo "$PYVER" | sed 's/\([0-9]\)\.[0-9]/\1/')"
PYVER_MAY="$(echo "$PYVER" | sed 's/\([0-9]\)\.[0-9]\+/\1/')"
PYVER_MIN="$(echo "$PYVER" | sed 's/[0-9]\.\([0-9]\+\)/\1/')"
PYREQVER_MAY="$(echo $PYREQVER | sed 's/\([0-9]\)\.[0-9]/\1/')"
PYREQVER_MIN="$(echo $PYREQVER | sed 's/[0-9]\.\([0-9]\+\)/\1/')"
Expand All @@ -97,46 +98,46 @@ PYVER_OK=0
fi
#fi
if [ "$PYVER_OK" -eq 1 ]; then
echo "python version is OK (need Python ${PYREQVER}+ got v${PYVER})"
echo "build: python version is OK (need Python ${PYREQVER}+ got v${PYVER})"
else
echo "WARNING: Python ${PYREQVER}+ not found"
echo "build: WARNING Python ${PYREQVER}+ not found"
fi

ECNT=0
for i in $REQS; do
PKG="$( echo "$i" | tr '_' '-' )"
printf "%b\n" 'try:\n import '"${i}"'\nexcept:\n exit(1)' | python3 || {
echo "Module '${i}' not found, try 'apt install python3-${PKG}' or 'pip install ${PKG}'"
echo "build: module '${i}' not found, on debian try 'apt install python3-${PKG}' or 'pip install ${PKG}'"
ECNT=$((ECNT + 1))
}
done
if [ "$ECNT" -gt 0 ]; then
echo "ERROR: $ECNT module(s) missing"
echo "build: ERROR $ECNT module(s) missing"
exit 1
fi

if [ "$PYINSTALLER" -eq 1 ]; then
command -v pyinstaller >/dev/null 2>&1 || {
echo "ERROR: pyinstaller not found, try 'apt install python3-pyinstaller' or 'pip install pyinstaller'"
echo "build: ERROR pyinstaller not found, on debian try 'apt install python3-pyinstaller' or 'pip install pyinstaller'"
exit 1
}
# shellcheck disable=SC2086
pyinstaller spy.py $ARGS --clean --noconfirm --onefile &&
if [ -e "dist/spy" ]; then
printf "\nresult: OK "
printf "\nbuild: result OK "
ls -la dist/spy
echo
if [ "$PACK" -eq 1 ]; then
# shellcheck disable=SC1091
. /etc/os-release
PACKNAME="pyspy-${ID:-linux}${VERSION_ID}-python${PYVER:-3}-x86_x64${PKG_SUFFIX}"
printf "Creating %s.tar.gz...\n" "$PACKNAME"
tar -C ./dist -cvf "${PACKNAME}.tar.gz" ../spy.conf spy ../webspy >/dev/null &&
sha512sum "${PACKNAME}.tar.gz" >"${PACKNAME}.sha512sum" && echo "shasum: OK" || echo "ERROR: shasum"
PACKNAME="pyspy-${ID:-linux}${VERSION_ID}-python${PYVER:-3}-x86_x64${PACKSUFFIX}"
printf "build: Creating %s.tar.gz...\n" "$PACKNAME"
tar -C ./dist -cvf "${PACKNAME}.tar.gz" $PACKFILES >/dev/null &&
sha512sum "${PACKNAME}.tar.gz" >"${PACKNAME}.sha512sum" && echo "build: shasum OK" || echo "build: ERROR shasum"
fi
else
echo
echo "ERROR: something went wrong :("
echo "build: ERROR something went wrong :("
exit 1
fi
fi
37 changes: 16 additions & 21 deletions docker-build-distro.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,37 @@ UBUNTU="
pip3 install pyinstaller sysv-ipc geoip2 flask
./build.sh && mkdir -p ./build-ubuntu && mv -f *.tar.gz *.sha512sum ./build-ubuntu
"
DEB=upx-ucl_4.2.2-3_amd64.deb #upx-ucl_3.96-2_amd64.deb
DEBIAN="
export DEBIAN_FRONTEND=noninteractive
apt-get update -y
apt-get install -y wget python3 python3-venv python3-pip
if ! apt-get install -y upx-ucl; then
apt-get install -y libucl1 &&
wget -q http://ftp.us.debian.org/debian/pool/main/u/upx-ucl/$DEB &&
dpkg -i $DEB;
fi
python3 -m venv venv && . venv/bin/activate
pip3 install --upgrade pip wheel setuptools
pip3 install --force -r requirements.txt
pip3 install --force pyinstaller sysv-ipc geoip2 flask
./build.sh && mkdir -p ./build-debian && mv -f *.tar.gz *.sha512sum ./build-debian
WEBSPY=1 ./build.sh && mkdir -p ./build-debian && mv -f *.tar.gz *.sha512sum ./build-debian
"
#CENTOS="
# yum install -y gcc python3-devel python3-pip python3-virtualenv
# yum install -y https://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/u/ucl-1.03-24.el7.x86_64.rpm
# yum install -y https://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/u/upx-3.96-9.el7.x86_64.rpm
# python3 -m venv venv && . venv/bin/activate
# pip3 install --upgrade pip wheel setuptools
# pip3 install -r requirements.txt
# pip3 install pyinstaller sysv-ipc geoip2
# ./build.sh && mkdir -p ./build-centos && mv -f *.tar.gz *.sha512sum ./build-centos
#"
_CENTOS_EOL="
yum install -y gcc python3-devel python3-pip python3-virtualenv
python3 -m venv venv && . venv/bin/activate
pip3 install --upgrade pip wheel setuptools
pip3 install -r requirements.txt
pip3 install pyinstaller sysv-ipc geoip2
./build.sh && mkdir -p ./build-centos && mv -f *.tar.gz *.sha512sum ./build-centos
"
ALPINE="
apk add python3 python3-dev py3-pip py3-virtualenv gcc musl-dev upx
apk add python3 python3-dev py3-pip py3-virtualenv gcc musl-dev
python3 -m venv venv && . venv/bin/activate
pip3 install --upgrade pip wheel setuptools
pip3 install -r requirements.txt
pip3 install pyinstaller sysv-ipc geoip2 flask
./build.sh && mkdir -p ./build-alpine && mv -f *.tar.gz *.sha512sum ./build-alpine
WEBSPY=1 ./build.sh && mkdir -p ./build-alpine && mv -f *.tar.gz *.sha512sum ./build-alpine
"
RHEL="
dnf install -y gcc python3-devel python3-pip
dnf install -y epel-release
dnf install -y upx ucl
python3 -m venv venv && . venv/bin/activate
pip3 install --upgrade pip wheel setuptools
pip3 install -r requirements.txt
Expand All @@ -59,8 +51,11 @@ RHEL="
func_docker_run() {
image=$1
shift
#docker run -it --workdir /build -v "$PWD:/build" "$image" bash
docker run --rm --workdir /build -v "$PWD:/build" "$image" sh -c "$*"
if [ -n "$DEBUG" ] && [ "$DEBUG" -eq 1 ]; then
docker run -it --workdir /build -v "$PWD:/build" "$image" sh
else
docker run --rm --workdir /build -v "$PWD:/build" "$image" sh -c "$*"
fi
}

TAG="${2:-latest}"
Expand All @@ -69,7 +64,7 @@ TAG="${2:-latest}"
case $1 in
ubuntu) func_docker_run "ubuntu:$TAG" "$UBUNTU" ;;
debian) func_docker_run "debian:$TAG" "$DEBIAN" ;;
#centos7) func_docker_run centos:7 "$CENTOS" ;;
#centos7) func_docker_run centos:7 "$_CENTOS_EOL" ;;
centos-stream) func_docker_run "quay.io/centos/centos:$TAG" "$RHEL" ;;
alma) func_docker_run "almalinux:$TAG" "$RHEL" ;;
rocky) func_docker_run "rockylinux:$TAG" "$RHEL" ;;
Expand Down

0 comments on commit 28fd929

Please sign in to comment.