From 132cf5b58c1e145f43a7a21a5b471a18bc3efe8f Mon Sep 17 00:00:00 2001 From: Mo8it Date: Mon, 29 Aug 2022 22:35:42 +0200 Subject: [PATCH] Add day_4 --- day_4/compile_tmate.sh | 17 +++++++++++++ day_4/compile_tmate_container.sh | 21 ++++++++++++++++ day_4/nextcloud.sh | 43 ++++++++++++++++++++++++++++++++ day_4/nginx.sh | 28 +++++++++++++++++++++ 4 files changed, 109 insertions(+) create mode 100755 day_4/compile_tmate.sh create mode 100755 day_4/compile_tmate_container.sh create mode 100755 day_4/nextcloud.sh create mode 100755 day_4/nginx.sh diff --git a/day_4/compile_tmate.sh b/day_4/compile_tmate.sh new file mode 100755 index 0000000..421ffb5 --- /dev/null +++ b/day_4/compile_tmate.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +# Sync repositories +apt update +# Install required packages +apt install -y git-core build-essential pkg-config libtool libevent-dev libncurses-dev zlib1g-dev automake libssh-dev libmsgpack-dev + +# Follow instructions from the Tmate website to compile +git clone https://github.com/tmate-io/tmate.git +cd tmate +./autogen.sh +./configure +make +make install + +# Move output binary to "output volume" +mv tmate /volumes/bin diff --git a/day_4/compile_tmate_container.sh b/day_4/compile_tmate_container.sh new file mode 100755 index 0000000..a69ff71 --- /dev/null +++ b/day_4/compile_tmate_container.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +# Check if script exists that will run in the container +if [ ! -f scripts/compile_tmate.sh ] +then + echo "Script scripts/compile_tmate.sh not found!" + exit 1 +fi + +# Make sure that the script is executable +chmod u+x scripts/compile_tmate.sh + +# Make sure that the "output directory" exists +mkdir -p bin + +# Run container +podman run -it --rm --tz local -v ./scripts:/volumes/scripts:Z,ro -v ./bin:/volumes/bin:Z ubuntu:latest /volumes/scripts/compile_tmate.sh + +echo "DONE!" + +echo "The output binary can be found at bin/tmate" diff --git a/day_4/nextcloud.sh b/day_4/nextcloud.sh new file mode 100755 index 0000000..9471d7a --- /dev/null +++ b/day_4/nextcloud.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +# In this solution, 0 is used instead of N + +# Create directories for volumes +mkdir -p ~/nextcloud0 +mkdir -p ~/nextcloud0-db + +# Create database container +podman create \ + --name nextcloud0-db \ + --network traefik \ + -v ~/nextcloud0-db:/var/lib/postgresql/data:Z \ + -e POSTGRES_DB=nextcloud \ + -e POSTGRES_USER=nextcloud \ + -e POSTGRES_PASSWORD=test \ + --tz local \ + --label "io.containers.autoupdate=registry" \ + docker.io/library/postgres:alpine + +# Create Nextcloud container +podman create \ + --name nextcloud0 \ + --network traefik \ + -v ~/nextcloud0:/var/www/html:Z \ + -e POSTGRES_DB=nextcloud \ + -e POSTGRES_USER=nextcloud \ + -e POSTGRES_PASSWORD=test \ + -e POSTGRES_HOST=nextcloud0-db \ + --tz local \ + --label "io.containers.autoupdate=registry" \ + docker.io/library/nextcloud:24-apache + + +# Change current directory to not have to move the systemd service files afterwards +cd ~/.config/systemd/user +# Generate systemd service files +podman generate systemd --new --files --name nextcloud0-db +podman generate systemd --new --files --name nextcloud0 + +# Enable and start the containers +systemctl --user enable --now container-nextcloud0-db +systemctl --user enable --now container-nextcloud0 diff --git a/day_4/nginx.sh b/day_4/nginx.sh new file mode 100755 index 0000000..4612247 --- /dev/null +++ b/day_4/nginx.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +# In this solution, 0 is used instead of N + +# Check if required directory exists +if [ ! -d ~/nginx0 ] +then + echo "~/nginx0 missing!" + exit 1 +fi + +# Create container +podman create \ + --name nginx0 \ + --network traefik \ + -v ~/nginx0/website:/volumes/website:Z,ro \ + -v ~/nginx0/conf:/etc/nginx/conf.d:Z,ro \ + --tz local \ + --label "io.containers.autoupdate=registry" \ + docker.io/library/nginx:alpine + +# Change current directory to not have to move the systemd service file afterwards +cd ~/.config/systemd/user +# Generate the systemd service file +podman generate systemd --new --files --name nginx0 + +# Enable and start the container +systemctl --user enable --now container-nginx0