adding docker-compose file and add_user script

This commit is contained in:
Michael Scalzetti 2022-07-18 16:27:45 -04:00
commit fff94a967a
2 changed files with 54 additions and 0 deletions

21
docker-compose.yml Normal file
View File

@ -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

33
scripts/add_user.sh Executable file
View File

@ -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 <user>"
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"