forked from IBM/cloud-native-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-registry.sh
executable file
·51 lines (40 loc) · 1.45 KB
/
create-registry.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
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
root_folder=$(cd $(dirname $0); cd ..; pwd)
function _out() {
echo "$(date +'%F %H:%M:%S') $@"
}
function _err() {
echo "$@" >&4
echo "$(date +'%F %H:%M:%S') $@"
}
readonly CFG_FILE=${root_folder}/local.env
# Check if config file exists, in this case it will have been modified
if [ ! -f $CFG_FILE ]; then
_out Config file local.env is missing!
_out -- Copy template.local.env to local.env and edit according to our instructions!
exit 1
fi
source $CFG_FILE
# SETUP logging (redirect stdout and stderr to a log file)
readonly LOG_FILE=${root_folder}/iks-scripts/create-registry.log
touch $LOG_FILE
function create_registry() {
_out Creating a Namespace in IBM Cloud Container Registry
_out Logging into IBM Cloud
ibmcloud config --check-version=false >> $LOG_FILE 2>&1
ibmcloud api --unset >> $LOG_FILE 2>&1
ibmcloud api https://cloud.ibm.com >> $LOG_FILE 2>&1
ibmcloud login --apikey $IBMCLOUD_API_KEY -r $IBM_CLOUD_REGION >> $LOG_FILE 2>&1
_out Creating Namespace $REGISTRY_NAMESPACE
ibmcloud cr login >> $LOG_FILE 2>&1
registry=$(ibmcloud cr info | awk '/Container Registry / {print $3}')
echo "REGISTRY=$registry" >> $CFG_FILE
ibmcloud cr namespace-add $REGISTRY_NAMESPACE >> $LOG_FILE 2>&1
# check if something went wrong
if [ $? == 0 ]; then
_out Namespace in IBM Cloud Container Registry created
else
_out SOMETHING WENT WRONG! Check the iks-scripts/create-registry.log
fi
}
create_registry