commit fff94a967add8f050e9d730acfe9673d95c320f7 Author: Michael Scalzetti Date: Mon Jul 18 16:27:45 2022 -0400 adding docker-compose file and add_user script 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"