From fff94a967add8f050e9d730acfe9673d95c320f7 Mon Sep 17 00:00:00 2001 From: Michael Scalzetti Date: Mon, 18 Jul 2022 16:27:45 -0400 Subject: [PATCH] adding docker-compose file and add_user script --- docker-compose.yml | 21 +++++++++++++++++++++ scripts/add_user.sh | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 docker-compose.yml create mode 100755 scripts/add_user.sh diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..97dc23e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,21 @@ +version: '3' + +services: + registry: + container_name: "docker-registry" + image: registry:2 + + volumes: + - ./data/reg_data:/var/lib/registry/ + - ./data/reg_auth:/auth + + environment: + - "REGISTRY_AUTH=htpasswd" + - "REGISTRY_AUTH_HTPASSWD_REALM=Registry" + - "REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpassword" + + ports: + - 5000:5000 + + restart: always + diff --git a/scripts/add_user.sh b/scripts/add_user.sh new file mode 100755 index 0000000..d55f3de --- /dev/null +++ b/scripts/add_user.sh @@ -0,0 +1,33 @@ +#! /bin/bash +USERNAME=$1 +SCRIPT_USER=$USER +USER_HOME=$HOME + +# Make sure a user is supplied +if [[ -z "$USER" ]]; then + echo "Username is required" + echo "./add_user.sh " + exit +fi + +# Get password inputs +read -sp "Enter the account password: " PASS +echo "" +read -sp "Enter the password again: " PASS2 +echo "" + +# Make sure passwords match +if [ "$PASS" != "$PASS2" ]; then + echo "Passwords do not match" + exit +fi + +# Make sure the auth folder exists +mkdir -p ~/deployment/data/reg_auth + +# Add the new user and password to the registry (using docker to avoid dependencies) +# Then if docker doesn't crash, print a msg to stdout for the end user +sudo docker run --rm \ + --entrypoint htpasswd \ + httpd:2 -Bbn $USERNAME $PASS >> $USER_HOME/deployment/data/reg_auth/htpassword && \ +echo "Made user $USERNAME"