Last active
July 2, 2020 16:31
-
-
Save EssGeeEich/7b20c4944aaf7f76ef58bdd184e99170 to your computer and use it in GitHub Desktop.
An easy and SELinux compliant pod builder.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ModuleVolumes $ModDir:/data/ | |
| ModuleROVolumes | |
| ModuleEnvironments DATABASE_URL=mysql://bitwarden:random_password_here@127.0.0.1/bitwarden ENABLE_DB_WAL=false | |
| ModuleImage bitwardenrs/server-mysql:latest |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ModuleVolumes $ModDir:/config/ | |
| ModuleROVolumes | |
| ModuleEnvironments MYSQL_USER=bitwarden MYSQL_PASSWORD=random_password_here MYSQL_DATABASE=bitwarden | |
| ModuleImage linuxserver/mariadb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| PodPorts 127.0.0.1:80:80 | |
| PodModules MariaDB BitwardenRS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| RUNUSER="podman" | |
| TIMEZONE="Europe/Rome" | |
| RootDir="/srv/pod" | |
| BuildSubDir="Build" | |
| PodsSubDir="Pods" | |
| TempSubDir="Temp" | |
| # Autorun pod after build? | |
| AUTORUN=1 | |
| # Manage systemd services? | |
| SYSTEMD=1 | |
| SYSTEMD_REMOVESVC=1 | |
| SYSTEMD_INSTALLSVC=1 | |
| while test ${#} -gt 0 | |
| do | |
| Pod="$1" | |
| PodArgs="" | |
| BuildDir="$RootDir/$BuildSubDir" | |
| BaseDir="$RootDir/$PodsSubDir" | |
| BaseTmpDir="$RootDir/$TempSubDir" | |
| PodDir="$BaseDir/$Pod" | |
| TmpDir="$BaseTmpDir/$Pod" | |
| ModuleArgs="-dt --pod $Pod -e PUID=$USERID -e PGID=$GROUPID -e TZ=$TIMEZONE" | |
| USERID="$(id -u $RUNUSER)" | |
| GROUPID="$(id -g $RUNUSER)" | |
| mkdir -p "$PodDir" | |
| chown -R "${USERID}:${GROUPID}" "$PodDir" | |
| chmod -R 2770 "$PodDir" | |
| while read -r a b || [[ -n "$a" ]]; do | |
| printf -v "$a" "$(eval echo $b)" | |
| done < "$BuildDir/$Pod/Pod" | |
| if [ $SYSTEMD -gt 0 ] | |
| then | |
| systemctl disable "pod-$Pod" | |
| systemctl stop "pod-$Pod" | |
| if [ $SYSTEMD_REMOVESVC -gt 0 ] | |
| then | |
| rm -f "/etc/systemd/system/pod-${Pod}.service" | |
| fi | |
| fi | |
| podman pod stop "$Pod" | |
| podman pod rm -f "$Pod" | |
| PodPortFlags="" | |
| for PodPort in $PodPorts | |
| do | |
| PodPortFlags="$PodPortFlags -p $PodPort" | |
| done | |
| podman pod create --name "$Pod" $PodPortFlags $PodArgs | |
| for Module in $PodModules | |
| do | |
| PodmanModule="${Pod}_${Module}" | |
| if [ $SYSTEMD -gt 0 ] | |
| then | |
| systemctl disable "container-$PodmanModule" | |
| systemctl stop "container-$PodmanModule" | |
| rm -f "/etc/systemd/system/container-$PodmanModule.service" | |
| fi | |
| ModDir="$PodDir/$Module" | |
| mkdir -p "$ModDir" | |
| chown -R "${USERID}:${GROUPID}" "$ModDir" | |
| chmod -R 2770 "$ModDir" | |
| while read -r a b || [[ -n "$a" ]]; do | |
| printf -v "$a" "$(eval echo $b)" | |
| done < "$BuildDir/$Pod/$Module" | |
| ModuleVolumeFlags="" | |
| for ModuleVolume in $ModuleVolumes | |
| do | |
| ModuleVolumeFlags="$ModuleVolumeFlags -v $ModuleVolume:z" | |
| done | |
| ModuleROVolumeFlags="" | |
| for ModuleROVolume in $ModuleROVolumes | |
| do | |
| ModuleROVolumeFlags="$ModuleROVolumeFlags -v $ModuleROVolume:z,ro" | |
| done | |
| ModuleEnvironmentFlags="" | |
| for ModuleEnvironment in $ModuleEnvironments | |
| do | |
| ModuleEnvironmentFlags="$ModuleEnvironmentFlags -e $ModuleEnvironment" | |
| done | |
| podman run $ModuleArgs --name "$PodmanModule" $ModuleEnvironmentFlags $ModuleVolumeFlags $ModuleImage | |
| done | |
| if [ $SYSTEMD -gt 0 ] | |
| then | |
| mkdir -p "$TmpDir" | |
| rm -r "$TmpDir" | |
| mkdir -p "$TmpDir" | |
| pushd "$TmpDir" | |
| podman generate systemd --files --name "$Pod" | |
| if [ $SYSTEMD_INSTALLSVC -gt 0 ] | |
| then | |
| mv -Z *.service "/etc/systemd/system/" | |
| fi | |
| popd | |
| if [ $AUTORUN -gt 0 ] | |
| then | |
| systemctl enable "pod-$Pod" | |
| fi | |
| else | |
| if [ $AUTORUN -gt 0 ] | |
| then | |
| podman start "$Pod" | |
| fi | |
| fi | |
| while read -r a b || [[ -n "$a" ]]; do | |
| printf -v "$a" "$(eval echo $b)" | |
| done < "$BuildDir/$Pod/PodOff" | |
| shift | |
| done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ### Prerequisites ### | |
| # Install podman (Example for Fedora/RHEL below) | |
| dnf install podman | |
| # Configure SELinux to allow running podman | |
| setsebool container_manage_cgroup 1 | |
| # Create the podman user: | |
| adduser -r -s /sbin/nologin podman | |
| # Create the directory tree: | |
| mkdir -p /srv/pod | |
| chown -R podman:podman /srv/pod | |
| chmod -R 2770 /srv/pod | |
| mkdir -p /srv/pod/Build/BitwardenRS | |
| # Get the script and the sample Podfiles | |
| wget -P /srv/pod https://gist.github.com/EssGeeEich/7b20c4944aaf7f76ef58bdd184e99170/raw/podmake.sh | |
| wget -P /srv/pod/Build/BitwardenRS https://gist.github.com/EssGeeEich/7b20c4944aaf7f76ef58bdd184e99170/raw/Pod | |
| wget -P /srv/pod/Build/BitwardenRS https://gist.github.com/EssGeeEich/7b20c4944aaf7f76ef58bdd184e99170/raw/MariaDB | |
| wget -P /srv/pod/Build/BitwardenRS https://gist.github.com/EssGeeEich/7b20c4944aaf7f76ef58bdd184e99170/raw/BitwardenRS | |
| # Run as root to install BitwardenRS with MariaDB | |
| /srv/pod/podmake BitwardenRS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment