From dc3579ff296a28d884cc718159505d4e933ee987 Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Fri, 9 Feb 2024 12:22:12 -0700 Subject: [PATCH 1/9] bit of makefile cleanup --- src/pybennu/Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pybennu/Makefile b/src/pybennu/Makefile index 6ec5aa1..e711d86 100644 --- a/src/pybennu/Makefile +++ b/src/pybennu/Makefile @@ -63,7 +63,7 @@ endef ## # Targets ## -.PHONY: dist test docs +.PHONY: packagetools pytools root clean clean-build clean-pyc deb dist sdist install install-dev uninstall wheelhouse bull help: @echo "clean - Remove python and build file artifacts." @@ -113,7 +113,6 @@ deb: packagetools @echo 'printf "\n\tINSTALLING ZMQ WITH DRAFT SUPPORT...\n\n"' >> $(POST) @echo 'wget --no-check-certificate https://raw.githubusercontent.com/zeromq/pyzmq/main/examples/draft/install.sh' >> $(POST) @echo 'sed -i -e "s/wget/wget --no-check-certificate/g" install.sh' >> $(POST) - @echo 'sed -i -e "s/make -j/make -j $(nproc)/g" install.sh' >> $(POST) @echo 'sed -i -e "s/pip install/pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org -I/g" install.sh' >> $(POST) @echo 'chmod +x install.sh' >> $(POST) @echo './install.sh' >> $(POST) From 8a88a4423c390979489cc77706cf6d8f978436c7 Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Fri, 9 Feb 2024 12:41:36 -0700 Subject: [PATCH 2/9] pybennu: create postinst as it's own file This is much cleaner and easier to read and maintain than being inline in the Makefile. --- src/pybennu/Makefile | 18 +----------------- src/pybennu/postinst | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 17 deletions(-) create mode 100755 src/pybennu/postinst diff --git a/src/pybennu/Makefile b/src/pybennu/Makefile index e711d86..cbf728b 100644 --- a/src/pybennu/Makefile +++ b/src/pybennu/Makefile @@ -27,7 +27,7 @@ endif BUILD_DIR = $(CURDIR)/build DIST_DIR = $(CURDIR)/dist -POST = $(CURDIR)/dist/postinst +POST = $(CURDIR)/postinst ## # Packaging @@ -108,22 +108,6 @@ clean-pyc: deb: packagetools @mkdir -p dist/ - @echo 'printf "\n--- RUNNING PYBENNU AFTER INSTALL SCRIPT ---\n\n"' > $(POST) - @echo 'mv /root/libzmq* /usr/lib/x86_64-linux-gnu' >> $(POST) - @echo 'printf "\n\tINSTALLING ZMQ WITH DRAFT SUPPORT...\n\n"' >> $(POST) - @echo 'wget --no-check-certificate https://raw.githubusercontent.com/zeromq/pyzmq/main/examples/draft/install.sh' >> $(POST) - @echo 'sed -i -e "s/wget/wget --no-check-certificate/g" install.sh' >> $(POST) - @echo 'sed -i -e "s/pip install/pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org -I/g" install.sh' >> $(POST) - @echo 'chmod +x install.sh' >> $(POST) - @echo './install.sh' >> $(POST) - @echo 'printf "\n\tINSTALLING HELICS/PYHELICS...\n\n"' >> $(POST) - @echo 'wget --no-check-certificate -O pyhelics.tgz https://github.com/GMLC-TDC/pyhelics/releases/download/v2.7.1/helics-2.7.1.tar.gz' >> $(POST) - @echo 'mkdir -p /tmp/pyhelics && tar -C /tmp/pyhelics -xzf pyhelics.tgz && rm pyhelics.tgz' >> $(POST) - @echo 'cd /tmp/pyhelics/helics-2.7.1 && sed -i "s/helics-apps/helics-apps~=2.7.1/" /tmp/pyhelics/helics-2.7.1/setup.py' >> $(POST) - @echo 'pip3 install --trusted-host pypi.org --trusted-host files.pythonhosted.org /tmp/pyhelics/helics-2.7.1/' >> $(POST) - @echo 'printf "\n\tINSTALLING PYBENNU PIP DEPENDENCIES...\n\n"' >> $(POST) - @echo 'pip3 install --trusted-host pypi.org --trusted-host files.pythonhosted.org bitarray elasticsearch>=5.3.0 helics~=2.7.1 matplotlib>=1.5.3 networkx>=1.11 numpy>=1.11.2 opendssdirect.py~=0.6.1 py-expression-eval~=0.3.14 PYPOWER>=5.0.1 pyserial>=3.4 pyyaml>=3.12 requests>=2.20 scipy>=0.18.1 sysv_ipc' >> $(POST) - @echo 'printf "\nDONE!!\n\n"' >> $(POST) @$(FPM) \ --verbose \ -f \ diff --git a/src/pybennu/postinst b/src/pybennu/postinst new file mode 100755 index 0000000..fd85fbb --- /dev/null +++ b/src/pybennu/postinst @@ -0,0 +1,26 @@ +set -ex + +printf "\n--- RUNNING PYBENNU AFTER INSTALL SCRIPT ---\n\n" +mv /root/libzmq* /usr/lib/x86_64-linux-gnu + +printf "\n\tINSTALLING ZMQ WITH DRAFT SUPPORT...\n\n" +wget --no-check-certificate https://raw.githubusercontent.com/zeromq/pyzmq/main/examples/draft/install.sh +sed -i -e "s/wget/wget --no-check-certificate/g" install.sh +sed -i -e "s/pip install/pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org -I/g" install.sh +chmod +x install.sh +./install.sh +rm ./install.sh + +printf "\n\tINSTALLING HELICS/PYHELICS...\n\n" +wget --no-check-certificate -O pyhelics.tgz https://github.com/GMLC-TDC/pyhelics/releases/download/v2.7.1/helics-2.7.1.tar.gz +mkdir -p /tmp/pyhelics +tar -C /tmp/pyhelics -xzf pyhelics.tgz +rm pyhelics.tgz +cd /tmp/pyhelics/helics-2.7.1 +sed -i "s/helics-apps/helics-apps~=2.7.1/" /tmp/pyhelics/helics-2.7.1/setup.py +pip3 install --trusted-host pypi.org --trusted-host files.pythonhosted.org /tmp/pyhelics/helics-2.7.1/ + +printf "\n\tINSTALLING PYBENNU PIP DEPENDENCIES...\n\n" +pip3 install --trusted-host pypi.org --trusted-host files.pythonhosted.org bitarray 'elasticsearch>=5.3.0' 'helics~=2.7.1' 'matplotlib>=1.5.3' 'networkx>=1.11' 'numpy>=1.11.2' 'opendssdirect.py~=0.6.1' 'py-expression-eval~=0.3.14' 'PYPOWER>=5.0.1' 'pyserial>=3.4' 'pyyaml>=3.12' 'requests>=2.20' 'scipy>=0.18.1' sysv_ipc + +printf "\nDONE!!\n\n" \ No newline at end of file From 94edd9459226fa8393e34d52aab13764a0bd1b55 Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Fri, 9 Feb 2024 12:42:26 -0700 Subject: [PATCH 3/9] use the variable --- src/pybennu/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pybennu/Makefile b/src/pybennu/Makefile index cbf728b..b96e06b 100644 --- a/src/pybennu/Makefile +++ b/src/pybennu/Makefile @@ -107,7 +107,7 @@ clean-pyc: @find . -name ".cache" -exec rm -rfv {} + deb: packagetools - @mkdir -p dist/ + @mkdir -p $(DIST_DIR) @$(FPM) \ --verbose \ -f \ From 4a8107e76caa8f3f5d38f61ab056cdd439fd991a Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Fri, 9 Feb 2024 13:58:24 -0700 Subject: [PATCH 4/9] add debs to gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 6da9743..798b8f7 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,8 @@ .vscode .idea +bennu.deb +pybennu.deb build *.autosave #*.pyc From 5b7477fcadeed174fc91f18fe183c81aed5f4ad4 Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Fri, 9 Feb 2024 13:58:36 -0700 Subject: [PATCH 5/9] add script to build bennu deb --- build_bennu_deb.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100755 build_bennu_deb.sh diff --git a/build_bennu_deb.sh b/build_bennu_deb.sh new file mode 100755 index 0000000..8871a93 --- /dev/null +++ b/build_bennu_deb.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +set -ex + +mkdir -p ./build +cd ./build +cmake ../ +make -j "$(nproc)" +sudo make package +cp ./*.deb ../bennu.deb +cd ../ From d5dba205e9a2cbe13f416da1e17e40a9650a8328 Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Fri, 9 Feb 2024 14:59:58 -0700 Subject: [PATCH 6/9] add timestamp to package versions --- CMakeLists.txt | 8 ++++++-- cmake/CpackConfig.cmake | 2 +- src/pybennu/Makefile | 6 +++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 208e9ab..9e14340 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,12 +8,16 @@ execute_process( OUTPUT_STRIP_TRAILING_WHITESPACE ) +# unix timestamp +string(TIMESTAMP BUILD_TIMESTAMP "%s") + # CMake requires semantic versions with integer components # Set it to something static so stuff works -set(bennu_VERSION "6.0.0") +# Example: 6.0.1707507861 +set(bennu_VERSION "6.0.${BUILD_TIMESTAMP}") # Add commit hash to the version for use by the Deb package builder -# Example: 6.0.0.f7055755 +# Example: 6.0.1707507861.94edd945 set(bennu_VERSION_WITH_COMMIT "${bennu_VERSION}.${bennu_SHORT_HASH}") project(bennu diff --git a/cmake/CpackConfig.cmake b/cmake/CpackConfig.cmake index a6bf2e3..2461ae7 100644 --- a/cmake/CpackConfig.cmake +++ b/cmake/CpackConfig.cmake @@ -17,7 +17,7 @@ set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Sandia National Laboratories PACKAGE_LICENSE = GPLv3 From 84661991ce3f4a3fd824edad0334d03fe880ed3a Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Fri, 9 Feb 2024 15:00:16 -0700 Subject: [PATCH 7/9] metadata tweaks --- src/pybennu/Makefile | 4 ++-- src/pybennu/setup.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pybennu/Makefile b/src/pybennu/Makefile index 15db62e..be97642 100644 --- a/src/pybennu/Makefile +++ b/src/pybennu/Makefile @@ -37,7 +37,7 @@ define PACKAGE_DESCRIPTION Modeling and simulation application for SCADA/ICS. endef PACKAGE_SECTION = python -PACKAGE_PRIORITY = extra +PACKAGE_PRIORITY = optional PACKAGE_COMPRESSION = bzip2 # 6.0.1707507794.8a88a442 PACKAGE_FULL_VERSION := 6.0.$(shell date +%s).$(shell git rev-parse --short HEAD) @@ -46,7 +46,7 @@ PACKAGE_FILENAME = $(PACKAGE_NAME)_$(PACKAGE_FULL_VERSION)_amd64.deb PACKAGE_VENDOR = SNL PACKAGE_MAINTAINER = Sandia National Laboratories PACKAGE_LICENSE = GPLv3 -PACKAGE_URL = https://github.com/sandialabs/sceptre-bennu.git +PACKAGE_URL = https://github.com/sandialabs/sceptre-bennu PACKAGE_ARCHITECTURE = amd64 ## diff --git a/src/pybennu/setup.py b/src/pybennu/setup.py index 2974464..274e1c1 100644 --- a/src/pybennu/setup.py +++ b/src/pybennu/setup.py @@ -155,7 +155,7 @@ def run(self): # https://github.com/pypa/setuptools_scm version = '6.0.0', description = 'bennu python providers and utilities', - url = 'https://github.com/sandialabs/sceptre-bennu.git', + url = 'https://github.com/sandialabs/sceptre-bennu', author = 'Sandia National Laboratories', author_email = 'emulytics@sandia.gov', license = 'GPLv3', From 2cb74420cf695addab80c98352ece539b8624fba Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Fri, 9 Feb 2024 16:53:01 -0700 Subject: [PATCH 8/9] guard statements --- src/pybennu/postinst | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/pybennu/postinst b/src/pybennu/postinst index fd85fbb..ac7ba65 100755 --- a/src/pybennu/postinst +++ b/src/pybennu/postinst @@ -1,8 +1,16 @@ set -ex printf "\n--- RUNNING PYBENNU AFTER INSTALL SCRIPT ---\n\n" -mv /root/libzmq* /usr/lib/x86_64-linux-gnu +if [[ ! -f /usr/lib/x86_64-linux-gnu/libzmq.a ]]; then + mv /root/libzmq.a /usr/lib/x86_64-linux-gnu/ +fi +if [[ ! -f /usr/lib/x86_64-linux-gnu/libzmq.so.5.1.5 ]]; then + mv /root/libzmq.so.5.1.5 /usr/lib/x86_64-linux-gnu/ +fi +# mv /root/libzmq* /usr/lib/x86_64-linux-gnu +# TODO: we should statically include our own version of install.sh +# instead of downloading it every build and running sed on it printf "\n\tINSTALLING ZMQ WITH DRAFT SUPPORT...\n\n" wget --no-check-certificate https://raw.githubusercontent.com/zeromq/pyzmq/main/examples/draft/install.sh sed -i -e "s/wget/wget --no-check-certificate/g" install.sh From e82db0db129cfdd6f3cbf9566fef63cf9b1c6c40 Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Fri, 9 Feb 2024 16:53:33 -0700 Subject: [PATCH 9/9] fix zmq install --- src/pybennu/postinst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pybennu/postinst b/src/pybennu/postinst index ac7ba65..dee84a8 100755 --- a/src/pybennu/postinst +++ b/src/pybennu/postinst @@ -14,7 +14,7 @@ fi printf "\n\tINSTALLING ZMQ WITH DRAFT SUPPORT...\n\n" wget --no-check-certificate https://raw.githubusercontent.com/zeromq/pyzmq/main/examples/draft/install.sh sed -i -e "s/wget/wget --no-check-certificate/g" install.sh -sed -i -e "s/pip install/pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org -I/g" install.sh +sed -i -e "s/pip install/pip3 install --trusted-host pypi.org --trusted-host files.pythonhosted.org -I/g" install.sh chmod +x install.sh ./install.sh rm ./install.sh