-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathup.sh
executable file
·41 lines (33 loc) · 1.17 KB
/
up.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#! /usr/bin/env bash
set -e
function help() {
echo "Usage: up.sh [user@ip-address] [domain]"
echo "Example: up.sh [email protected]"
echo "The machine must have git, docker and docker compose installed."
}
if [ -z "$1" ] || [ -z "$2" ]; then
help
exit 1
fi
ssh_target=$1
domain=$2
echo "Source the environment variables..."
source .env
echo "Cloning the repository on the remote machine..."
ssh -t "$ssh_target" 'if [ -d ~/.docker-registry ]; then echo ".docker-registry dir exists"; else git clone https://github.com/vtno/docker-registry.git ~/.docker-registry; fi'
echo "Copying the registry credentials to the remote machine..."
scp .env "$ssh_target:~/.docker-registry/"
echo "Starting the registry..."
ssh -t "$ssh_target" 'cd ~/.docker-registry && docker compose up -d'
echo "Health check..."
# loop until the registry is up for 10 seconds with 1 second pause
for i in {1..10}; do
if curl -u "$USERNAME":"$PLAIN_PASSWORD" -s -o /dev/null -w "%{http_code}" "https://$domain" | grep -q 200; then
echo "Registry is up!"
exit 0
fi
sleep 1
done
echo "Registry is not up. Please check the logs."
ssh -t "$ssh_target" 'cd ~/.docker-registry && docker compose logs'
exit 1