Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,10 @@ support by virtue of support for Ubuntu. Actual Docker installation is handled b
installation script, but you can use the stacks installer directly on any *nix machine by
running [stacks/setup.sh](./stacks/setup.sh).

Login as root and execute:
To begin a standard installation:

```sh
source <(curl -H 'Cache-Control: no-cache, no-store' -o- https://raw.githubusercontent.com/uicpharm/docker-host/main/init.sh)
```

The script will download the project and walk you through executing the scripts.

If you cannot login as root and can only sudo, then download it to your home directory and
execute it from there:

```sh
curl -H 'Cache-Control: no-cache, no-store' -o- https://raw.githubusercontent.com/uicpharm/docker-host/main/init.sh > init.sh && \
chmod +x init.sh && \
sudo ./init.sh
```bash
bash <(curl -H 'Cache-Control: no-cache, no-store' -o- https://raw.githubusercontent.com/uicpharm/docker-host/main/init.sh)
```

## FAQs
Expand Down
1 change: 1 addition & 0 deletions custom-words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ nodocker
NOPASSWD
opencontainers
realpath
Retzky
rmul
rpms
runnerdir
Expand Down
182 changes: 120 additions & 62 deletions init.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
#!/bin/bash

# Params
version=1.0.0
bold=$(tput bold)
red=$(tput setaf 1)
yellow=$(tput setaf 3)
ul=$(tput smul)
rmul=$(tput rmul)
norm=$(tput sgr0)
branch=main
[[ $1 != -* && -n $1 ]] && branch=$1
dev=false
help_only=false
version_only=false
stacks_only=false
runner_only=false

# Asks a yes/no question and returns 0 for 'yes' and 1 for 'no'. If the user does not
# provide a response, it uses the default value.
Expand All @@ -25,70 +35,105 @@ function yorn() {
done
}

bold=$(tput bold)
ul=$(tput smul)
norm=$(tput sgr0)
echo "$bold
___ __ __ __ __
/ _ \ ___ ____ / /__ ___ ____ / // /___ ___ / /_
/ // // _ \/ __// '_// -_)/ __/ / _ // _ \ (_-</ __/
/____/ \___/\__//_/\_\ \__//_/ /_//_/ \___//___/\__/

Installer for container environments on UIC Pharmacy servers
$norm
Please select a base directory where we will install things. We will put a
directory called 'docker-host' ${bold}inside${norm} that directory. Use the base directory to
store other app configurations and data so it's conveniently all in one place.
"
PS3="Select the base directory or type your own: "
select BASEDIR in /data ~; do
BASEDIR="${BASEDIR:-$REPLY}"
question="Create the directory $ul$BASEDIR$norm, right?"
[[ -d $BASEDIR ]] && question="Install files in existing directory $ul$BASEDIR$norm, right?"
yorn "$question" y && break
function display_version() {
echo -n "Docker Host version $version build "
find "$dir" -type f \( -name '*.sh' -o -name '*.yml' \) -not -path '*/node_modules/*' | \
sort | xargs cat | sha256sum | cut -c1-8
}

# Title for the script
function display_title() {
local -r ver=$(display_version)
echo "$bold"
echo " ___ __ __ __ __ "
echo " / _ \ ___ ____ / /__ ___ ____ / // /___ ___ / /_"
echo " / // // _ \/ __// '_// -_)/ __/ / _ // _ \ (_-</ __/"
echo "/____/ \___/\__//_/\_\ \__//_/ /_//_/ \___//___/\__/ "
echo
echo "Containerization on UIC Pharmacy servers $yellow(${ver/Docker Host version /v})"
echo "$norm"
}

# Help
function display_help() {
display_title
cat <<EOF
Usage: $0 [OPTIONS]

Sets up an OS for container tooling and installs additional useful scripts for
container management according to UIC Pharmacy standards:

- ${bold}deploy$norm: Helps deploy a stack.
- ${bold}publish$norm: Takes a Dockerfile and publishes multi-arch images.
- ${bold}podman-install-service$norm: Installs a Podman pod as a service.

Options:
-h, --help Show this help message and exit.
-d, --dev Install in developer mode, just create a symlink.
-b, --branch Branch to use for installation files.
--stacks-only Only run the stack installation.
--runner-only Only run the GitHub Actions runner installation.
-V, --version Print version and exit.
EOF
}

# Collect optional arguments.
# spellchecker: disable-next-line
while getopts hb:dV-: OPT; do
# Ref: https://stackoverflow.com/a/28466267/519360
if [ "$OPT" = "-" ]; then
OPT="${OPTARG%%=*}" # extract long option name
OPTARG="${OPTARG#"$OPT"}" # extract long option argument (may be empty)
OPTARG="${OPTARG#=}" # if long option argument, remove assigning `=`
fi
case "$OPT" in
h | help) help_only=true ;;
b | branch) branch=$OPTARG ;;
d | dev) dev=true ;;
stacks-only) stacks_only=true ;;
runner-only) runner_only=true ;;
V | version) version_only=true ;;
\?) echo "${red}Invalid option: -$OPT$norm" >&2 ;;
*) echo "${red}Some of these options are invalid:$norm $*" >&2; exit 2 ;;
esac
done
shift $((OPTIND - 1))

# Prerequisite commands
for cmd in curl cut find gzip install mktemp sort tar tr; do
if ! which "$cmd" > /dev/null; then
echo "${bold}${red}This installer requires $ul$cmd$rmul to work.$norm" >&2
exit 1
fi
done

# Determine if git needs to be installed. On macOS, we check if developer tools are installed. On
# all other platforms, we just check if `git --version` is successful.
NEED_GIT=true
if [ "$(uname)" = "Darwin" ]; then
xcode-select --print-path &> /dev/null && NEED_GIT=false
# Load installer files into a temp directory
export dev
if $dev; then
dir=$(dirname "$(realpath "$0")")
echo "Will install from $dir in dev mode..."
else
git --version &> /dev/null && NEED_GIT=false
echo "Downloading installation files from $branch branch..."
dir=$(mktemp -d -t uicpharm-docker-host-XXXXXX)
url=https://github.com/uicpharm/docker-host/archive/refs/heads/$branch.tar.gz
curl -fsL "$url" | tar xz --strip-components=1 -C "$dir"
fi

if $NEED_GIT; then
if yorn 'We have to install git or we cannot proceed. Is that okay?' 'y'; then
# Install git with apt or yum
if [ -n "$(command -v dnf)" ]; then
dnf install -y git || exit 1
elif [ -n "$(command -v yum)" ]; then
yum install -y git || exit 1
elif [ -n "$(command -v xcode-select)" ]; then
xcode-select --install
# Wait until the interactive install is done
echo -n "Follow the GUI installer. Waiting for installation to finish"
until xcode-select --print-path &> /dev/null; do echo -n '.'; sleep 5; done
echo '\nGreat, developer tools are installed!'
elif [ -n "$(command -v apt)" ]; then
apt update -y && apt install -y git || exit 1
else
echo "Could not determine application repository. Supports apt, dnf, yum, and xcode-select."
exit 1
fi
else
echo 'Ok, we must abort then.'
exit
fi
# Help/version options only display their info and exit
if $help_only; then
display_help
exit
elif $version_only; then
display_version
exit
fi

# Clone the project if the dir doesn't exist
REPO_DIR="$BASEDIR/docker-host"
REPO_URL="https://github.com/uicpharm/docker-host.git"
mkdir -p "$BASEDIR" || exit 1
[ ! -d "$REPO_DIR" ] && git clone -b "$branch" "$REPO_URL" "$REPO_DIR"
[[ -d $REPO_DIR ]] && echo "The docker-host project is installed at $ul$REPO_DIR$norm."
cd "$REPO_DIR" || exit 1
display_title
# Warn that we will ask for sudo password.
if [[ $EUID -ne 0 ]]; then
echo "Part of the installation requires 'sudo'. You may be asked for a sudo password."
echo
fi

# Calculate the default flavor based on what we see on the system
default_flavor=''
Expand All @@ -103,7 +148,7 @@ elif [[ -f /etc/os-release ]]; then
fi

# Available flavor installers
flavors=$(find . -mindepth 1 -maxdepth 1 \( -type d -o -type l \) ! -name 'exp' ! -name 'node_modules' ! -name 's*' ! -name '.*' | cut -d'/' -f2 | sort)
flavors=$(find "$dir" -mindepth 1 -maxdepth 1 \( -type d -o -type l \) ! -name 'exp' ! -name 'node_modules' ! -name 's*' ! -name '.*' | awk -F'/' '{print $NF}' | sort)
[[ ! $flavors =~ $default_flavor ]] && default_flavor=''

if [[ -n $default_flavor ]] && yorn "It looks like you're running on $ul$default_flavor$norm, is that right?" y; then
Expand All @@ -118,7 +163,20 @@ fi

if [[ ! $flavors =~ $flavor ]]; then
echo "Aborting because $ul$flavor$norm is not a valid choice."
exit 1
fi

# All flavors should run as sudo, except macOS.
cmd=(env) && [[ $flavor != macos ]] && cmd=(sudo env)
cmd+=(DEV="$dev")
if $stacks_only; then
cd "$dir/shared" || exit 1
cmd+=(./stacks.sh)
elif $runner_only; then
cd "$dir/shared" || exit 1
cmd+=(./github-actions-runner.sh)
else
cd "$flavor" || exit 1
./setup.sh
cd "$dir/$flavor" || exit 1
cmd+=(./setup.sh)
fi
"${cmd[@]}"
17 changes: 11 additions & 6 deletions macos/docker.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash

scr_dir=$(realpath "${0%/*}")
[[ -z $DEV ]] && DEV=false

SCRIPT_TITLE="Install Docker Desktop"
if [[ " $* " == *" --title "* ]]; then echo "$SCRIPT_TITLE"; exit 0; fi
Expand All @@ -21,12 +22,16 @@ echo

# Add scripts to /usr/local/bin so it will be in the path
# (On macOS, we must use this one because /usr/bin is not permitted)
if [ -d '/usr/local/bin' ]; then
bin_dir='/usr/local/bin'
fi
if [ -n "$bin_dir" ]; then
echo "Installing scripts to $bin_dir may require a password."
bin_dir=/usr/local/bin
sudo install -d $bin_dir
if [[ -d $bin_dir ]]; then
echo "Installing scripts to $(tput smul)$bin_dir$(tput rmul) (may require a password):"
for scr_name in "$scr_dir"/../shared/bin/*.sh; do
sudo ln -f -s "$(realpath "$scr_name")" "$bin_dir/$(basename "$scr_name" .sh)"
cmd=(sudo install -b -v) && $DEV && cmd=(sudo ln -f -v -s)
cmd+=("$(realpath "$scr_name")")
cmd+=("$bin_dir/$(basename "$scr_name" .sh)")
"${cmd[@]}"
done
else
echo "$(tput setaf 1)Cannot install scripts to $(tput smul)$bin_dir$(tput rmul) because it wasn't found.$(tput sgr0)" >&2
fi
2 changes: 0 additions & 2 deletions rhel-9/bin/docker-compose.sh

This file was deleted.

20 changes: 15 additions & 5 deletions rhel-9/bin/podman-install-service.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
#!/bin/bash

version=1.0.0
bold=$(tput bold)
ul=$(tput smul)
red=$(tput setaf 1)
yellow=$(tput setaf 3)
norm=$(tput sgr0)

display_version() {
hash=$(cat "$0" | sha256sum | cut -c1-8)
echo "$(basename "$0") version $version build $hash"
}

display_help() {
cat <<EOF
$bold$(display_version)$norm
${red}UIC Retzky College of Pharmacy$norm

Usage: $(basename "$0") <container or pod name> [OPTIONS]

Creates a system service for a container or pod. The container or pod must be
Expand All @@ -18,22 +27,23 @@ option $bold--no-restart$norm, but then systemctl won't work until after an OS r
Options:
-h, --help Show this help message and exit.
-n, --no-restart Don't restart the container when creating the service.
-V, --version Print version and exit.
EOF
}

svc_name="$1"
[[ $* =~ -h || $* =~ --help ]] && display_help && exit
[[ $* =~ -h || $* =~ --help ]] && display_help && exit 1
[[ $* =~ -V || $* =~ --version ]] && display_version && exit 1
[[ $* =~ -n || $* =~ --no-restart ]] && systemctl_opts=() || systemctl_opts=(--now)

# Abort if service was not provided
if [[ -z "$svc_name" ]] || [[ $svc_name == -* ]]; then
echo -e "${red}You must provide a service name.$norm\n" >&2
display_help
echo -e "${red}You must provide a service name.$norm" >&2
exit 1
fi

# Only run if "docker" is answering as podman
if [[ $(docker --version) == podman* ]]; then
# Only run if we are using podman
if [[ $(podman --version 2>/dev/null) == podman* ]]; then
(
cd /etc/systemd/system || exit 1
echo "Setting up service as $(tput bold)$svc_name$(tput sgr0):"
Expand Down
24 changes: 14 additions & 10 deletions rhel-9/docker.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash

scr_dir=$(realpath "${0%/*}")
[[ -z $DEV ]] && DEV=false

SCRIPT_TITLE="Install Docker/Podman"
if [[ " $* " == *" --title "* ]]; then echo "$SCRIPT_TITLE"; exit 0; fi
Expand All @@ -11,18 +12,21 @@ sleep 2
dnf install -y python-dotenv container-tools podman-compose

# Add scripts to /usr/bin so it will be in the path
if [ -d '/usr/bin' ]; then
bin_dir='/usr/bin'
elif [ -d '/usr/local/bin' ]; then
bin_dir='/usr/local/bin'
if [[ -d /usr/bin ]]; then
bin_dir=/usr/bin
elif [[ -d /usr/local/bin ]]; then
bin_dir=/usr/local/bin
fi
if [ -n "$bin_dir" ]; then
for scr_name in "$scr_dir"/../shared/bin/*.sh; do
ln -f -s "$(realpath "$scr_name")" "$bin_dir/$(basename "$scr_name" .sh)"
done
for scr_name in "$scr_dir"/bin/*.sh; do
ln -f -s "$(realpath "$scr_name")" "$bin_dir/$(basename "$scr_name" .sh)"
if [[ -n $bin_dir ]]; then
echo "Installing scripts to $(tput smul)$bin_dir$(tput rmul) (may require a password):"
for scr_name in "$scr_dir"/../shared/bin/*.sh "$scr_dir"/bin/*.sh; do
cmd=(install -b -v) && $DEV && cmd=(ln -f -v -s)
cmd+=("$(realpath "$scr_name")")
cmd+=("$bin_dir/$(basename "$scr_name" .sh)")
"${cmd[@]}"
done
else
echo "$(tput setaf 1)Cannot install scripts to $(tput smul)$bin_dir$(tput rmul) because it wasn't found.$(tput sgr0)" >&2
fi

# Silence Docker emulation messages
Expand Down
Loading