Improve the docker container spin-up script

I'm preparing for reproducibility, if that's not clear
This commit is contained in:
Salt 2021-06-20 20:18:52 -05:00
parent e86003f245
commit 273f4b2a23

View File

@ -8,8 +8,8 @@
set -e set -e
if [ -n "$ANSIBLE_SSH_KEY" ]; then if [ -n "$ANSIBLE_SSH_KEY" ]; then
# Set up an unprivileged user with the same UID-GID as the user who owns the volume # Set up an unprivileged user with the same UID-GID as the user who owns the volume
targetUID="$(stat -c %u /etc/ansible)" targetUID="$(stat -c %u /etc/ansible.orig)"
targetGID="$(stat -c %g /etc/ansible)" targetGID="$(stat -c %g /etc/ansible.orig)"
printf "\e[37mCreating a user with $targetUID:$targetGID...\e[0m\n" printf "\e[37mCreating a user with $targetUID:$targetGID...\e[0m\n"
groupadd ansible -g "$targetGID" groupadd ansible -g "$targetGID"
useradd ansible \ useradd ansible \
@ -37,10 +37,18 @@ if [ -n "$ANSIBLE_SSH_KEY" ]; then
printf '\e[37mUpdating repositories...\e[0m\n' printf '\e[37mUpdating repositories...\e[0m\n'
apt-get update > /dev/null 2>&1 apt-get update > /dev/null 2>&1
printf '\e[37mInstalling packages from APT...\e[0m\n' printf '\e[37mInstalling packages from APT...\e[0m\n'
apt-get install -y openssh-client python3-docker python3-pip sudo vim > /dev/null 2>&1 apt-get install -y openssh-client python-is-python3 python3-docker python3-pip rsync sudo vim > /dev/null 2>&1
printf '\e[37mInstalling packages from PIP (this may take a minute)...\e[0m\n' printf '\e[37mInstalling packages from PIP (this may take a minute)...\e[0m\n'
pip install -q ansible ansible-lint pip install -q ansible ansible-lint
# Setup our playbook environment roles
printf '\e[37mCreating local copy of playbook files...\e[0m\n'
mkdir /etc/ansible
chown ansible. /etc/ansible
sudo -u ansible rsync -aHS /etc/ansible.orig /etc/ansible --exclude .git
printf '\e[37mInstalling roles...\e[0m\n'
sudo -u ansible ansible-galaxy install -r roles/requirements.yml -p roles
# Drop to the ansible user # Drop to the ansible user
printf '\e[32mAnsible is ready to run\e[0m\n' printf '\e[32mAnsible is ready to run\e[0m\n'
printf ' * \e[33mThe repo is located at /etc/ansible\e[0m\n' printf ' * \e[33mThe repo is located at /etc/ansible\e[0m\n'
@ -54,6 +62,6 @@ fi
ANSIBLE_SSH_KEY="$(cat ~/.ssh/desu)" ANSIBLE_SSH_KEY="$(cat ~/.ssh/desu)"
docker run -it \ docker run -it \
-e "ANSIBLE_SSH_KEY=$ANSIBLE_SSH_KEY" \ -e "ANSIBLE_SSH_KEY=$ANSIBLE_SSH_KEY" \
-v "$PWD:/etc/ansible" \ -v "$PWD:/etc/ansible.orig:ro" \
ubuntu:focal \ ubuntu:focal \
bash -c 'cd /etc/ansible && ./contrib/docker.sh && exec bash' bash -c 'cd /etc/ansible && ./contrib/docker.sh && exec bash'