forked from openshift/ocm-container
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathocm-container.sh
executable file
·109 lines (93 loc) · 2.62 KB
/
ocm-container.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/bash
usage() {
cat <<EOF
usage: $0 [ OPTIONS ] [ Initial Cluster Name ]
Options
-h --help Show this message and exit
-o --launch-opts Sets extra non-default container launch options
-t --tag Sets the image tag to use
-x --debug Set bash debug flag
Initial Cluster Name can be either the cluster name, cluster id, or external cluster ID.
EOF
}
ARGS=()
BUILD_TAG="latest"
while [ "$1" != "" ]; do
case $1 in
-h | --help ) usage
exit 1
;;
-o | --launch-opts ) shift
OCM_CONTAINER_LAUNCH_OPTS=$1
;;
-t | --tag ) shift
BUILD_TAG="$1"
;;
-x | --debug ) set -x
;;
-* ) echo "Unexpected parameter $1"
usage
exit 1
;;
* )
ARGS+=($1)
;;
esac
shift
done
if [ ${#ARGS[@]} -gt 1 ]
then
echo "Expected at most one argument. Got ${#ARGS[@]}"
usage
exit 1
fi
### Load config
CONFIG_DIR=${HOME}/.config/ocm-container
export OCM_CONTAINER_CONFIGFILE="$CONFIG_DIR/env.source"
if [ ! -f ${OCM_CONTAINER_CONFIGFILE} ]; then
echo "Cannot find config file at $OCM_CONTAINER_CONFIGFILE";
echo "Run the init.sh file to create one."
echo "exiting"
exit 1;
fi
source ${OCM_CONTAINER_CONFIGFILE}
### SSH Agent Mounting
operating_system=`uname`
SSH_AGENT_MOUNT="-v ${SSH_AUTH_SOCK}:/tmp/ssh.sock:ro"
if [[ "$operating_system" == "Darwin" ]]
then
SSH_AGENT_MOUNT="--mount type=bind,src=/run/host-services/ssh-auth.sock,target=/tmp/ssh.sock,readonly"
fi
### Kerberos Ticket Mounting
OCM_CONTAINER_KRB5CC_FILE=${KRB5CCNAME:-/tmp/krb5cc_$UID}
if [ -f $OCM_CONTAINER_KRB5CC_FILE ]
then
KRB5CCFILEMOUNT="-v ${OCM_CONTAINER_KRB5CC_FILE}:/tmp/krb5cc:ro"
fi
### Kerberos User Override
if [ -z $OCM_CONTAINER_KERBEROS_USER ]
then
OCM_CONTAINER_KERBEROS_USER=$(whoami)
fi
USER=$OCM_CONTAINER_KERBEROS_USER
### Automatic Login Detection
if [ -n "$ARGS" ]
then
INITIAL_CLUSTER_LOGIN="-e INITIAL_CLUSTER_LOGIN=$ARGS"
fi
### start container
${CONTAINER_SUBSYS} run -it --rm --privileged \
-e "OCM_URL" \
-e "USER" \
-e "SSH_AUTH_SOCK=/tmp/ssh.sock" \
-e "KRB5CCNAME=/tmp/krb5cc" \
-e "OFFLINE_ACCESS_TOKEN" \
${INITIAL_CLUSTER_LOGIN} \
-v ${CONFIG_DIR}:/root/.config/ocm-container:ro \
-v ${HOME}/.ssh:/root/.ssh:ro \
-v ${HOME}/.aws/credentials:/root/.aws/credentials:ro \
-v ${HOME}/.aws/config:/root/.aws/config:ro \
${SSH_AGENT_MOUNT} \
${KRB5CCFILEMOUNT} \
${OCM_CONTAINER_LAUNCH_OPTS} \
ocm-container:${BUILD_TAG}