harbor/tools/ova/script/common.sh

110 lines
2.6 KiB
Bash
Raw Normal View History

2016-10-25 12:09:54 +02:00
#!/bin/bash
#Shut down Harbor
function down {
base_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
docker-compose -f $base_dir/../harbor/docker-compose*.yml down
}
#Start Harbor
function up {
base_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
$base_dir/start_harbor.sh
}
#Configure Harbor
function configure {
base_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
$base_dir/config.sh
}
2016-12-02 06:41:38 +01:00
function getRegistryVersion {
registry_version=""
base_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
registry_version=$(sed -n -e 's|.*library/registry:||p' $base_dir/../harbor/docker-compose.yml)
if [ -z registry_version ]
then
registry_version="latest"
fi
}
2016-10-25 12:09:54 +02:00
#Garbage collectoin
function gc {
echo "======================= $(date)====================="
2016-12-02 06:41:38 +01:00
getRegistryVersion
2016-10-25 12:09:54 +02:00
docker run --name gc --rm --volume /data/registry:/storage \
--volume $base_dir/../harbor/common/config/registry/:/etc/registry/ \
2016-12-02 06:41:38 +01:00
registry:$registry_version garbage-collect /etc/registry/config.yml
2016-10-25 12:09:54 +02:00
echo "===================================================="
}
#Add rules to iptables
function addIptableRules {
2016-11-25 06:59:22 +01:00
iptables -A INPUT -p tcp --dport 5480 -j ACCEPT -w || true
#iptables -A INPUT -p tcp --dport 5488 -j ACCEPT
#iptables -A INPUT -p tcp --dport 5489 -j ACCEPT
2016-10-25 12:09:54 +02:00
}
#Install docker-compose
function installDockerCompose {
base_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
$base_dir/../deps/docker-compose-1.7.1/install.sh
}
#Load images
function load {
basedir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
docker load -i $basedir/../harbor/harbor*.tgz
}
#Configure SSH
function configSSH {
value=$(ovfenv -k permit_root_login)
if [ "$value" = "true" ]
then
v=yes
else
v=no
fi
echo "ssh: permit root login - $v"
sed -i -r s%"^PermitRootLogin .*"%"PermitRootLogin $v"% /etc/ssh/sshd_config
if [ ! -f /etc/ssh/ssh_host_rsa_key ] \
|| [ ! -f /etc/ssh/ssh_host_ecdsa_key ] \
|| [ ! -f /etc/ssh/ssh_host_ed25519_key ]
then
ssh-keygen -A
fi
systemctl restart sshd
}
#Configure attr in harbor.cfg
function configureHarborCfg {
cfg_key=$1
cfg_value=$2
basedir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cfg_file=$basedir/../harbor/harbor.cfg
if [ -n "$cfg_key" ]
then
sed -i -r s%"#?$cfg_key\s*=\s*.*"%"$cfg_key = $cfg_value"% $cfg_file
fi
2016-11-29 04:29:50 +01:00
}
2016-11-29 07:12:02 +01:00
function pushPhoton {
set +e
2016-12-02 06:41:38 +01:00
getRegistryVersion
2016-11-29 07:12:02 +01:00
docker run -d --name photon_pusher -v /data/registry:/var/lib/registry -p 5000:5000 registry:$registry_version
docker tag photon:1.0 127.0.0.1:5000/library/photon:1.0
sleep 5
docker push 127.0.0.1:5000/library/photon:1.0
docker rm -f photon_pusher
set -e
2016-10-25 12:09:54 +02:00
}