2018-11-15 04:09:57 +01:00
|
|
|
#!/bin/bash
|
2019-11-28 12:57:49 +01:00
|
|
|
set -e
|
2016-04-15 11:23:40 +02:00
|
|
|
|
2019-07-10 08:14:49 +02:00
|
|
|
# If compiling source code this dir is harbor's make dir.
|
2020-02-18 10:33:43 +01:00
|
|
|
# If installing harbor via package, this dir is harbor's root dir.
|
2019-04-30 10:16:06 +02:00
|
|
|
if [[ -n "$HARBOR_BUNDLE_DIR" ]]; then
|
|
|
|
harbor_prepare_path=$HARBOR_BUNDLE_DIR
|
|
|
|
else
|
|
|
|
harbor_prepare_path="$( cd "$(dirname "$0")" ; pwd -P )"
|
|
|
|
fi
|
2019-04-02 14:08:26 +02:00
|
|
|
echo "prepare base dir is set to ${harbor_prepare_path}"
|
2019-11-28 12:57:49 +01:00
|
|
|
|
|
|
|
# Clean up input dir
|
|
|
|
rm -rf ${harbor_prepare_path}/input
|
|
|
|
# Create a input dirs
|
|
|
|
mkdir -p ${harbor_prepare_path}/input
|
|
|
|
input_dir=${harbor_prepare_path}/input
|
|
|
|
|
|
|
|
# Copy harbor.yml to input dir
|
|
|
|
if [[ ! "$1" =~ ^\-\- ]] && [ -f "$1" ]
|
|
|
|
then
|
|
|
|
cp $1 $input_dir/harbor.yml
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
if [ -f "${harbor_prepare_path}/harbor.yml" ];then
|
|
|
|
cp ${harbor_prepare_path}/harbor.yml $input_dir/harbor.yml
|
|
|
|
else
|
|
|
|
echo "no config file: ${harbor_prepare_path}/harbor.yml"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
data_path=$(grep '^[^#]*data_volume:' $input_dir/harbor.yml | awk '{print $NF}')
|
|
|
|
|
2019-04-02 14:08:26 +02:00
|
|
|
# If previous secretkeys exist, move it to new location
|
|
|
|
previous_secretkey_path=/data/secretkey
|
|
|
|
previous_defaultalias_path=/data/defaultalias
|
|
|
|
|
|
|
|
if [ -f $previous_secretkey_path ]; then
|
|
|
|
mkdir -p $data_path/secret/keys
|
|
|
|
mv $previous_secretkey_path $data_path/secret/keys
|
|
|
|
fi
|
|
|
|
if [ -f $previous_defaultalias_path ]; then
|
|
|
|
mkdir -p $data_path/secret/keys
|
|
|
|
mv $previous_defaultalias_path $data_path/secret/keys
|
|
|
|
fi
|
|
|
|
|
2019-03-12 12:09:01 +01:00
|
|
|
|
2019-03-18 08:07:19 +01:00
|
|
|
# Create secret dir
|
|
|
|
secret_dir=${data_path}/secret
|
|
|
|
config_dir=$harbor_prepare_path/common/config
|
|
|
|
|
|
|
|
# Run prepare script
|
2020-08-13 08:55:42 +02:00
|
|
|
docker run --rm -v $input_dir:/input \
|
|
|
|
-v $data_path:/data \
|
|
|
|
-v $harbor_prepare_path:/compose_location \
|
|
|
|
-v $config_dir:/config \
|
|
|
|
-v /:/hostfs \
|
|
|
|
--privileged \
|
2020-02-14 14:11:52 +01:00
|
|
|
goharbor/prepare:dev prepare $@
|
2019-03-12 12:09:01 +01:00
|
|
|
|
2019-04-02 14:08:26 +02:00
|
|
|
echo "Clean up the input dir"
|
2019-03-12 12:09:01 +01:00
|
|
|
# Clean up input dir
|
2019-04-02 14:08:26 +02:00
|
|
|
rm -rf ${harbor_prepare_path}/input
|