forked from aperloff/cms-cvmfs-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.cms-cvmfs-docker
163 lines (153 loc) · 5.89 KB
/
.cms-cvmfs-docker
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/bash
cvmfs_docker() {
local debug="false"
local display="host.docker.internal:0"
local dryrun="false"
local gitconfig="false"
local image="aperloff/cms-cvmfs-docker:latest"
local mounts=""
local name=""
local persistence="--rm"
local port=""
local local=""
local remote="/root/local_mount/"
local registry="docker.io/"
local ssh="false"
local vnc=""
local usage="$FUNCNAME [-h] [-m \"space separated mounts\"] [-l <local path to mount>] [-r <remote path to mount>]
-- opens a temporary docker container for mounting CVMFS
simply specify the mount points or "" for all and then specify an additional folder to mount into the container
where:
-d print the command being used to invoke the docker container, but don't run the container (default: ${dryrun})
-D set the display (default: ${display})
-g mount the global gitconfig file from the host (default: ${gitconfig})
-h show this help text
-i [image] specify the Docker image to be used (default: ${image})
-l [LOCAL] local path to mount in container (default: ${local})
-m [MOUNTS] sets the mount points; space separate multiple points inside quotes (default: ${mounts})
-n [NAME] make the container persistent (default: ${name})
-p [PORT] open a port using the specified port number (default: ${port})
-r [REMOTE] remote path to mount in the container (default: ${remote})
-R [registry] the Docker registry of the image (default: ${registry})
-s mount the .ssh folder (default: ${ssh})
-v expose the ports needed to use a VNC viewer (default: ${vnc})
-V print extra debugging information (default: ${debug})
example: cvmfs_docker -m \"cms.cern.ch oasis.opensciencegrid.org\" -l `pwd` -r /root/workdir"
local OPTIND OPTARG
while getopts 'dDghi:m:n:l:p:r:R:svV' option; do
case "$option" in
d) dryrun="true"
;;
D) display=$OPTARG
;;
g) gitconfig="true"
;;
h) echo "$usage"
return 0
;;
i) image=$OPTARG
;;
l) local=$OPTARG
;;
n) name=$OPTARG
persistence=""
;;
m) mounts=$OPTARG
;;
p) port=$OPTARG
port="-p ${port}:${port}"
;;
r) remote=$OPTARG
;;
R) registry=$OPTARG
;;
s) ssh="true"
;;
v) vnc="-p 5901:5901 -p 6080:6080"
;;
V) debug="true"
;;
:) printf "missing argument for -%s\n" "$OPTARG" >&2
echo "$usage" >&2
return -1
;;
\?) printf "illegal option: -%s\n" "$OPTARG" >&2
echo "$usage" >&2
return -2
;;
esac
done
shift $((OPTIND - 1))
# Only do the xhost checking if the system has xhost
if [[ $(command -v xhost) ]] && [[ ! "${dryrun}" == "true" ]]; then
# Capture the output of the xhost command and look for the lines:
# "access control enabled, only authorized clients can connect"
# "INET:localhost
# If the first is different, then the xhost access should be reset by doing:
# xhost -
# Then check again. If either the second line is missing, or the first was there, but the second one was missing, then do:
# xhost +127.0.0.1
# Then check again. If it's not right this time, then exit and throw an error
xhost_enabled="access control enabled, only authorized clients can connect"
xhost_localhost="INET:localhost"
xhost_check="$(xhost)"
if [[ $xhost_check == *"${xhost_localhost}"* ]]; then
echo "Note::access control already enabled, including an opening for localhost"
else
xhost -
xhost_check="$(xhost)"
if [[ $xhost_check != *"${xhost_enabled}"* ]]; then
xhost +127.0.0.1
xhost_check="$(xhost)"
if [[ $xhost_check != *"${xhost_localhost}"* ]]; then
echo "ERROR:Unable to set the xhost settings properly"
return -3
fi
fi
fi
fi
# Format the local mount point
if [[ "$local" != "" ]]; then
local local_mount="-v ${local}:${remote}"
else
echo "NOTE: No local mount set."
fi
# Format the image used
if [[ -z ${image} ]]; then
if [[ "${registry: -1}" == "/" ]]; then
registry="${registry: : -1}"
fi
if [[ "${registry}" == *"docker.io"* ]]; then
image=${registry}/${image}
elif [[ "${registry}" == *"gitlab-registry.cern.ch"* ]]; then
image=${registry}/aperloff/${image}
fi
fi
cmd="docker run ${persistence} -it -P ${vnc} ${port} --device /dev/fuse --cap-add SYS_ADMIN -e CVMFS_MOUNTS=\"${mounts}\" -e DISPLAY=${display} -e MY_UID=$(id -u) -e MY_GID=$(id -g) -v ~/.globus:/home/cmsusr/.globus"
if [[ "$ssh" == "true" ]]; then
# ssh agent forwarding from:
# https://medium.com/@nazrulworld/ssh-agent-forward-into-docker-container-on-macos-ff847ec660e2
# https://docs.docker.com/docker-for-mac/osxfs/#ssh-agent-forwarding
cmd="${cmd} -v ~/.ssh:/home/cmsusr/.ssh --mount type=bind,src=${SSH_AUTH_SOCK},target=${SSH_AUTH_SOCK} -e SSH_AUTH_SOCK=\"${SSH_AUTH_SOCK}\""
fi
if [[ "${gitconfig}" == "true" ]]; then
cmd="${cmd} --mount type=bind,source=`readlink ${HOME}/.gitconfig`,target=/home/cmsusr/.gitconfig"
fi
if [[ -n $local_mount ]]; then
cmd="${cmd} ${local_mount}"
fi
if [[ -n $name ]]; then
cmd="${cmd} --name ${name}"
fi
cmd="${cmd} ${image}"
if [[ "$debug" == "true" ]]; then
set -x
fi
if [[ "${dryrun}" == "true" ]]; then
echo "${cmd}"
else
eval ${cmd}
fi
set +x
return 0
}