From cbe3dd4e0df8f912cf39b7ade0391b1fd9666357 Mon Sep 17 00:00:00 2001 From: Sgoti Date: Thu, 29 May 2025 11:25:06 -0400 Subject: [PATCH 1/4] Add Container file and build script (button_hpr_container.sh) to repo. The build script can also run new containers after building images. Build properties such as "${conternerBuildProperties[containerFile]}" must be assigned before building/running new containers. Build script is "work in progress". On branch dev Changes to be committed: new file: Containerfile new file: button_hpr_container.sh --- utils/Containerfile | 62 ++++++++++++++++ utils/button_hpr_container.sh | 136 ++++++++++++++++++++++++++++++++++ 2 files changed, 198 insertions(+) create mode 100644 utils/Containerfile create mode 100755 utils/button_hpr_container.sh diff --git a/utils/Containerfile b/utils/Containerfile new file mode 100644 index 0000000..072c20c --- /dev/null +++ b/utils/Containerfile @@ -0,0 +1,62 @@ +FROM perl:5.40.1 As base + +LABEL author="sgoti" \ + email="lyunpaw@gmail.com" \ + project="Hacker Public Radio" \ + forge="https://repo.anhonesthost.net/HPR" + +ARG unprivilegedUser="janitor" + +RUN apt update && apt upgrade --yes; + +RUN apt install --no-install-recommends sqlite3 git --yes \ + && rm --recursive --force /var/lib/apt/lists/*; + +RUN mkdir --verbose --parent /opt/hpr /tmp/hpr; + +RUN groupadd --system ${unprivilegedUser} \ + && useradd --system --no-log-init --gid ${unprivilegedUser} ${unprivilegedUser}; + +RUN chown --recursive ${unprivilegedUser}:${unprivilegedUser} /opt/hpr \ + && chown --recursive ${unprivilegedUser}:${unprivilegedUser} /tmp/hpr; + +#Bill of particulars. + +##Meta::CPAN (Comprehensive Perl Archive Network) +RUN cpanm Config::General \ + DBD::SQLite \ + DBI \ + Data::Dumper \ + Date::Calc \ + Date::Parse \ + DateTime \ + DateTime::Duration \ + DateTime::Format::Duration \ + DateTime::TimeZone \ + HTML::Entities \ + JSON \ + Template \ + Template::Filters; + +##Included perl core modules (standard library). +##Carp +##Cwd +##Getopt::Long +##Pod::Usage +##File::Copy + +USER ${unprivilegedUser} + +WORKDIR /opt/hpr + +RUN git clone https://repo.anhonesthost.net/HPR/hpr-tools.git \ + && git clone https://repo.anhonesthost.net/HPR/hpr_hub.git \ + && git clone https://repo.anhonesthost.net/HPR/hpr_generator.git \ + && git clone https://repo.anhonesthost.net/HPR/hpr_documentation.git; + +WORKDIR /opt/hpr/hpr-tools/Community_News/ +RUN ln --symbolic /opt/hpr/hpr_generator/utils/mysql2sqlite /opt/hpr/hpr-tools/Community_News/mysql2sqlite; +RUN ./collect_HPR_database; + +CMD bash; + diff --git a/utils/button_hpr_container.sh b/utils/button_hpr_container.sh new file mode 100755 index 0000000..4db0232 --- /dev/null +++ b/utils/button_hpr_container.sh @@ -0,0 +1,136 @@ +#!/usr/bin/env bash +#License: GPL v3 +#see . + +#Name: button_podman_make_shownotes.sh +#Purpose: build/run HPR Container. +#Version: beta 0.01 +#Author: SGOTI (Some Guy On The Internet) +#Email: Lyunpaw@gmail.com +#Date: 2025-04-19 + +#declaration: +declare bindir="/usr/bin/" +declare podman="${bindir}podman" +declare echo="builtin echo -e" +declare unprivilegedUser="janitor" +declare date="${bindir}date" +declare flags +declare OPTIND +declare -A containerBulidProperties + +declare currentMonth +declare nextMonth +declare currentYear + +#start: +currentMonth=$(${date} +%m) +currentYear=$(${date} +%Y) + +if [[ ${currentmonth} -gt 0 ]] && [[ ${currentmonth} -le 11 ]]; then + nextMonth="(($(${date} +%m)+01))" #Incomplete: Can return single-digit integer; must be a double-digit integer. +else + nextMonth="01" +fi + +containerBulidProperties=( +"containerFile" "/path/to/Containerfile" +"hostMountDir01" "path/to/project/directory" +"hostMountDir02" "/tmp/" +"containerMountDir01" "/opt/hpr/" +"containerMountDir02" "/tmp/hpr/" +"containerImageTag" "testing:0.1" +"pullNewImage" "podman pull docker.io/library/perl" +"recordingDate" "$(${date} -d "${currentYear}/${currentMonth}/01")" +"recordingTimeStart" "15:00" #TZ: UTC +"recordingTimeEnd" "17:00" #TZ: UTC +) + +function runHPRContainer () { + local makeEmail #Incomplete: + makeEmail="./make_email -month=${containerBulidProperties[recordingDate]} -start=15:00 -end=17:00 -out=/tmp/hpr/%semail.txt" + local makeShownotes #Incomplete: + makeShownotes="/opt/hpr/src/hpr-tools/Community_News/make_shownotes -from=${containerBulidProperties[recordingDate]} -full=/tmp/hpr/%sfull_shownotes.html -mail -comments" + + ${podman} run \ + --mount type=bind,src=${containerBulidProperties[hostMountDir02]},dst=${containerBulidProperties[containerMountDir02]},rw=true \ + --label="Project"="HPR" \ + --label="Forge"="https://repo.anhonesthost.net/HPR/" \ + --interactive \ + --tty \ + --rm=true \ + --privileged=false \ + --pull="never" \ + --cgroups=enabled \ + --cgroupns=private \ + --uts=private \ + --pid=private \ + --memory="32m" \ + --memory-reservation="16m" \ + --hostname="hpr" \ + --name="hpr_project" \ + --user="${unprivilegedUser}" \ + ${containerBulidProperties[containerImageTag]} bash; + unset currentMonth + unset currentYear + return; +} + +function buildNewContainerImage () { + local containerNameAndVersionNumber="hpr_image:5.40.1" + if [[ -f "${containerBulidProperties[containerFile]}" ]]; then + ${echo} "Building new container image...\nThis may take several minutes.\ + \nThis is a non interactive build process, so you can return when \ + it's completed."; + ${podman} build --file="${containerBulidProperties[containerFile]}" --tag="${containerBulidProperties[containerImageTag]}"; + else + ${echo} 'Dont forget to assign the ${containerBulidProperties[containerFile]} ;). The Containerfile is needed to build the container image.' + fi + return; +} + +function help () { + ${echo} "$0 [-hbpq]\n\t[-h] help\n\t[-b] build new container\n\t[-p] pull new perl image\n\t[-q] quit"; + return; +} + +while getopts 'hbpq' flags; do + case "${flags}" in + h) help; exit 0; + ;; + + i) ${echo} "Work in progress... :D"; break; + ;; + + b) buildNewContainerImage; + ;; + + p) ${containerBulidProperties[pullNewImage]}; exit 0; + ;; + + e) ${echo} "Work in progress... :D"; break; + ;; + + s) ${echo} "Work in progress... :D"; break; + ;; + + q) + ${echo} "Quitting script."; break; + ;; + + *) + ${echo} "Good Heavens! Wrong input."; help; exit 1 + ;; + esac +done +shift $((OPTIND-1)) + +if [[ -z ${1} ]]; then help; runHPRContainer; fi; + +unset echo +unset flags +unset podman +unset OPTIND +unset containerBulidProperties +exit 0 + From 2ca4d32282aad52dfb0fe66fc46e5aced3f2e167 Mon Sep 17 00:00:00 2001 From: Sgoti Date: Thu, 29 May 2025 13:04:14 -0400 Subject: [PATCH 2/4] Changed image tag from 'testing' to current perl version '5.40.1' removed a few unused variables then shift the 'local' scoped unsets to global --- utils/button_hpr_container.sh | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/utils/button_hpr_container.sh b/utils/button_hpr_container.sh index 4db0232..adfcbdd 100755 --- a/utils/button_hpr_container.sh +++ b/utils/button_hpr_container.sh @@ -2,7 +2,7 @@ #License: GPL v3 #see . -#Name: button_podman_make_shownotes.sh +#Name: button_hpr_container.sh #Purpose: build/run HPR Container. #Version: beta 0.01 #Author: SGOTI (Some Guy On The Internet) @@ -35,11 +35,11 @@ fi containerBulidProperties=( "containerFile" "/path/to/Containerfile" -"hostMountDir01" "path/to/project/directory" +"hostMountDir01" "/path/to/project/directory" "hostMountDir02" "/tmp/" "containerMountDir01" "/opt/hpr/" "containerMountDir02" "/tmp/hpr/" -"containerImageTag" "testing:0.1" +"containerImageTag" "hpr_project:5.40.1" "pullNewImage" "podman pull docker.io/library/perl" "recordingDate" "$(${date} -d "${currentYear}/${currentMonth}/01")" "recordingTimeStart" "15:00" #TZ: UTC @@ -71,13 +71,10 @@ function runHPRContainer () { --name="hpr_project" \ --user="${unprivilegedUser}" \ ${containerBulidProperties[containerImageTag]} bash; - unset currentMonth - unset currentYear return; } function buildNewContainerImage () { - local containerNameAndVersionNumber="hpr_image:5.40.1" if [[ -f "${containerBulidProperties[containerFile]}" ]]; then ${echo} "Building new container image...\nThis may take several minutes.\ \nThis is a non interactive build process, so you can return when \ @@ -131,6 +128,8 @@ unset echo unset flags unset podman unset OPTIND +unset currentMonth +unset currentYear unset containerBulidProperties exit 0 From bbf5c26dabf54b134366feecd037620609bab2f2 Mon Sep 17 00:00:00 2001 From: Sgoti Date: Fri, 30 May 2025 17:40:11 -0400 Subject: [PATCH 3/4] Moved 'Containerfile' and build script to hpr-tools/ Ken asked that files be placed into 'hpr-tools/'. The build script is named 'button_hpr_container.sh' currently; this will change too. Maybe 'hpr_email_shownotes.sh'. Taking suggestions (as of 2025/05/30-2025/12/31). --- utils/button_hpr_container.sh | 135 ---------------------------------- 1 file changed, 135 deletions(-) delete mode 100755 utils/button_hpr_container.sh diff --git a/utils/button_hpr_container.sh b/utils/button_hpr_container.sh deleted file mode 100755 index adfcbdd..0000000 --- a/utils/button_hpr_container.sh +++ /dev/null @@ -1,135 +0,0 @@ -#!/usr/bin/env bash -#License: GPL v3 -#see . - -#Name: button_hpr_container.sh -#Purpose: build/run HPR Container. -#Version: beta 0.01 -#Author: SGOTI (Some Guy On The Internet) -#Email: Lyunpaw@gmail.com -#Date: 2025-04-19 - -#declaration: -declare bindir="/usr/bin/" -declare podman="${bindir}podman" -declare echo="builtin echo -e" -declare unprivilegedUser="janitor" -declare date="${bindir}date" -declare flags -declare OPTIND -declare -A containerBulidProperties - -declare currentMonth -declare nextMonth -declare currentYear - -#start: -currentMonth=$(${date} +%m) -currentYear=$(${date} +%Y) - -if [[ ${currentmonth} -gt 0 ]] && [[ ${currentmonth} -le 11 ]]; then - nextMonth="(($(${date} +%m)+01))" #Incomplete: Can return single-digit integer; must be a double-digit integer. -else - nextMonth="01" -fi - -containerBulidProperties=( -"containerFile" "/path/to/Containerfile" -"hostMountDir01" "/path/to/project/directory" -"hostMountDir02" "/tmp/" -"containerMountDir01" "/opt/hpr/" -"containerMountDir02" "/tmp/hpr/" -"containerImageTag" "hpr_project:5.40.1" -"pullNewImage" "podman pull docker.io/library/perl" -"recordingDate" "$(${date} -d "${currentYear}/${currentMonth}/01")" -"recordingTimeStart" "15:00" #TZ: UTC -"recordingTimeEnd" "17:00" #TZ: UTC -) - -function runHPRContainer () { - local makeEmail #Incomplete: - makeEmail="./make_email -month=${containerBulidProperties[recordingDate]} -start=15:00 -end=17:00 -out=/tmp/hpr/%semail.txt" - local makeShownotes #Incomplete: - makeShownotes="/opt/hpr/src/hpr-tools/Community_News/make_shownotes -from=${containerBulidProperties[recordingDate]} -full=/tmp/hpr/%sfull_shownotes.html -mail -comments" - - ${podman} run \ - --mount type=bind,src=${containerBulidProperties[hostMountDir02]},dst=${containerBulidProperties[containerMountDir02]},rw=true \ - --label="Project"="HPR" \ - --label="Forge"="https://repo.anhonesthost.net/HPR/" \ - --interactive \ - --tty \ - --rm=true \ - --privileged=false \ - --pull="never" \ - --cgroups=enabled \ - --cgroupns=private \ - --uts=private \ - --pid=private \ - --memory="32m" \ - --memory-reservation="16m" \ - --hostname="hpr" \ - --name="hpr_project" \ - --user="${unprivilegedUser}" \ - ${containerBulidProperties[containerImageTag]} bash; - return; -} - -function buildNewContainerImage () { - if [[ -f "${containerBulidProperties[containerFile]}" ]]; then - ${echo} "Building new container image...\nThis may take several minutes.\ - \nThis is a non interactive build process, so you can return when \ - it's completed."; - ${podman} build --file="${containerBulidProperties[containerFile]}" --tag="${containerBulidProperties[containerImageTag]}"; - else - ${echo} 'Dont forget to assign the ${containerBulidProperties[containerFile]} ;). The Containerfile is needed to build the container image.' - fi - return; -} - -function help () { - ${echo} "$0 [-hbpq]\n\t[-h] help\n\t[-b] build new container\n\t[-p] pull new perl image\n\t[-q] quit"; - return; -} - -while getopts 'hbpq' flags; do - case "${flags}" in - h) help; exit 0; - ;; - - i) ${echo} "Work in progress... :D"; break; - ;; - - b) buildNewContainerImage; - ;; - - p) ${containerBulidProperties[pullNewImage]}; exit 0; - ;; - - e) ${echo} "Work in progress... :D"; break; - ;; - - s) ${echo} "Work in progress... :D"; break; - ;; - - q) - ${echo} "Quitting script."; break; - ;; - - *) - ${echo} "Good Heavens! Wrong input."; help; exit 1 - ;; - esac -done -shift $((OPTIND-1)) - -if [[ -z ${1} ]]; then help; runHPRContainer; fi; - -unset echo -unset flags -unset podman -unset OPTIND -unset currentMonth -unset currentYear -unset containerBulidProperties -exit 0 - From c9e1446f1f0d870abfebd78d908639fc2e23d4e0 Mon Sep 17 00:00:00 2001 From: Sgoti Date: Fri, 30 May 2025 17:46:02 -0400 Subject: [PATCH 4/4] Tiny human distraction. I cp the files over but the 'git rm' failed and I didn't noticed. Just a clean up job. --- utils/Containerfile | 62 --------------------------------------------- 1 file changed, 62 deletions(-) delete mode 100644 utils/Containerfile diff --git a/utils/Containerfile b/utils/Containerfile deleted file mode 100644 index 072c20c..0000000 --- a/utils/Containerfile +++ /dev/null @@ -1,62 +0,0 @@ -FROM perl:5.40.1 As base - -LABEL author="sgoti" \ - email="lyunpaw@gmail.com" \ - project="Hacker Public Radio" \ - forge="https://repo.anhonesthost.net/HPR" - -ARG unprivilegedUser="janitor" - -RUN apt update && apt upgrade --yes; - -RUN apt install --no-install-recommends sqlite3 git --yes \ - && rm --recursive --force /var/lib/apt/lists/*; - -RUN mkdir --verbose --parent /opt/hpr /tmp/hpr; - -RUN groupadd --system ${unprivilegedUser} \ - && useradd --system --no-log-init --gid ${unprivilegedUser} ${unprivilegedUser}; - -RUN chown --recursive ${unprivilegedUser}:${unprivilegedUser} /opt/hpr \ - && chown --recursive ${unprivilegedUser}:${unprivilegedUser} /tmp/hpr; - -#Bill of particulars. - -##Meta::CPAN (Comprehensive Perl Archive Network) -RUN cpanm Config::General \ - DBD::SQLite \ - DBI \ - Data::Dumper \ - Date::Calc \ - Date::Parse \ - DateTime \ - DateTime::Duration \ - DateTime::Format::Duration \ - DateTime::TimeZone \ - HTML::Entities \ - JSON \ - Template \ - Template::Filters; - -##Included perl core modules (standard library). -##Carp -##Cwd -##Getopt::Long -##Pod::Usage -##File::Copy - -USER ${unprivilegedUser} - -WORKDIR /opt/hpr - -RUN git clone https://repo.anhonesthost.net/HPR/hpr-tools.git \ - && git clone https://repo.anhonesthost.net/HPR/hpr_hub.git \ - && git clone https://repo.anhonesthost.net/HPR/hpr_generator.git \ - && git clone https://repo.anhonesthost.net/HPR/hpr_documentation.git; - -WORKDIR /opt/hpr/hpr-tools/Community_News/ -RUN ln --symbolic /opt/hpr/hpr_generator/utils/mysql2sqlite /opt/hpr/hpr-tools/Community_News/mysql2sqlite; -RUN ./collect_HPR_database; - -CMD bash; -