Skip to content

Commit 3608075

Browse files
author
Brad Micklea
authored
Merge pull request eclipse-che#2018 from eclipse/che-mount
Add che-mount support for desktop IDEs
2 parents 6c9d385 + 5c18a08 commit 3608075

3 files changed

Lines changed: 222 additions & 26 deletions

File tree

che.sh

Lines changed: 91 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,27 @@ init_global_variables() {
2020

2121
CHE_LAUNCHER_CONTAINER_NAME="che-launcher"
2222
CHE_LAUNCHER_IMAGE_NAME="codenvy/che-launcher"
23+
CHE_SERVER_IMAGE_NAME="codenvy/che-server"
24+
25+
CHE_MOUNT_FOLDER=${CHE_MOUNT_FOLDER:+$(get_clean_path ${CHE_MOUNT_FOLDER})}
2326

2427
# User configurable variables
25-
DEFAULT_CHE_VERSION="nightly"
28+
DEFAULT_CHE_VERSION="latest"
2629
DEFAULT_CHE_CLI_ACTION="help"
2730

2831
CHE_VERSION=${CHE_VERSION:-${DEFAULT_CHE_VERSION}}
2932
CHE_CLI_ACTION=${CHE_CLI_ACTION:-${DEFAULT_CHE_CLI_ACTION}}
3033

3134
USAGE="
3235
Usage: che [COMMAND]
33-
start Starts Che server
34-
stop Stops Che server
35-
restart Restart Che server
36-
update Pull latest version of ${CHE_LAUNCHER_IMAGE_NAME}
37-
info Print some debugging information
38-
init Initialize directory with Che configuration
39-
up Create workspace from source in current directory
36+
start Starts Che server
37+
stop Stops Che server
38+
restart Restart Che server
39+
update Pull latest version of ${CHE_LAUNCHER_IMAGE_NAME}
40+
info Print some debugging information
41+
mount <local-path> <ws-ssh-port> Synchronize workspace to a local directory
42+
init Initialize directory with Che configuration
43+
up Create workspace from source in current directory
4044
"
4145
}
4246

@@ -65,6 +69,34 @@ error_exit() {
6569
exit 1
6670
}
6771

72+
get_full_path() {
73+
echo $(realpath $1)
74+
}
75+
76+
convert_windows_to_posix() {
77+
echo "/"$(echo "$1" | sed 's/\\/\//g' | sed 's/://')
78+
}
79+
80+
get_clean_path() {
81+
INPUT_PATH=$1
82+
# \some\path => /some/path
83+
OUTPUT_PATH=$(echo ${INPUT_PATH} | tr '\\' '/')
84+
# /somepath/ => /somepath
85+
OUTPUT_PATH=${OUTPUT_PATH%/}
86+
# /some//path => /some/path
87+
OUTPUT_PATH=$(echo ${OUTPUT_PATH} | tr -s '/')
88+
# "/some/path" => /some/path
89+
OUTPUT_PATH=${OUTPUT_PATH//\"}
90+
echo ${OUTPUT_PATH}
91+
}
92+
93+
get_mount_path() {
94+
FULL_PATH=$(get_full_path $1)
95+
POSIX_PATH=$(convert_windows_to_posix $FULL_PATH)
96+
echo $(get_clean_path $POSIX_PATH)
97+
}
98+
99+
68100
docker-exec() {
69101
if is_boot2docker || is_docker_for_windows; then
70102
MSYS_NO_PATHCONV=1 docker.exe "$@"
@@ -82,17 +114,19 @@ check_docker() {
82114
}
83115

84116
parse_command_line () {
85-
for command_line_option in "$@"; do
86-
case ${command_line_option} in
87-
start|stop|restart|update|info|init|up|help|-h|--help)
88-
CHE_CLI_ACTION=${command_line_option}
117+
if [ $# -eq 0 ]; then
118+
CHE_CLI_ACTION="help"
119+
else
120+
case $1 in
121+
start|stop|restart|update|info|init|up|mount|help|-h|--help)
122+
CHE_CLI_ACTION=$1
89123
;;
90124
*)
91125
# unknown option
92126
error_exit "You passed an unknown command line option."
93127
;;
94128
esac
95-
done
129+
fi
96130
}
97131

98132
is_boot2docker() {
@@ -169,15 +203,23 @@ get_list_of_variables() {
169203
VALUE='-e '${SINGLE_VARIABLE}' '
170204
RETURN="${RETURN}""${VALUE}"
171205
done
172-
echo "${RETURN}"
206+
echo $RETURN
173207
}
174208

175209
execute_che_launcher() {
176-
update_che_launcher
210+
211+
CURRENT_IMAGE=$(docker images -q "${CHE_LAUNCHER_IMAGE_NAME}":"${CHE_VERSION}")
212+
213+
if [ "${CURRENT_IMAGE}" != "" ]; then
214+
info "ECLIPSE CHE: FOUND IMAGE ${CHE_LAUNCHER_IMAGE_NAME}:${CHE_VERSION}"
215+
else
216+
update_che_image ${CHE_LAUNCHER_IMAGE_NAME}
217+
fi
218+
177219
info "ECLIPSE CHE: LAUNCHING LAUNCHER"
178220
docker-exec run -t --name "${CHE_LAUNCHER_CONTAINER_NAME}" \
179221
-v /var/run/docker.sock:/var/run/docker.sock \
180-
$(get_list_of_variables) \
222+
-e $(get_list_of_variables) \
181223
"${CHE_LAUNCHER_IMAGE_NAME}":"${CHE_VERSION}" "${CHE_CLI_ACTION}" \
182224
# > /dev/null 2>&1
183225
}
@@ -223,20 +265,39 @@ execute_command_with_progress() {
223265
printf "\n"
224266
}
225267

226-
update_che_launcher() {
268+
update_che_image() {
227269
if [ -z "${CHE_VERSION}" ]; then
228270
CHE_VERSION=${DEFAULT_CHE_VERSION}
229271
fi
230272

231-
CURRENT_IMAGE=$(docker images -q ${CHE_LAUNCHER_IMAGE_NAME}:${CHE_VERSION})
273+
info "ECLIPSE CHE: PULLING IMAGE $1:${CHE_VERSION}"
274+
execute_command_with_progress extended docker pull $1:${CHE_VERSION}
275+
info "ECLIPSE CHE: IMAGE $1:${CHE_VERSION} INSTALLED"
276+
}
232277

233-
if [ "${CURRENT_IMAGE}" != "" ]; then
234-
info "ECLIPSE CHE: ALREADY HAVE IMAGE ${CHE_LAUNCHER_IMAGE_NAME}:${CHE_VERSION}"
235-
else
236-
info "ECLIPSE CHE: PULLING IMAGE ${CHE_LAUNCHER_IMAGE_NAME}:${CHE_VERSION}"
237-
execute_command_with_progress extended docker pull ${CHE_LAUNCHER_IMAGE_NAME}:${CHE_VERSION}
238-
info "ECLIPSE CHE: IMAGE ${CHE_LAUNCHER_IMAGE_NAME}:${CHE_VERSION} INSTALLED"
278+
mount_local_directory() {
279+
if [ ! $# -eq 3 ]; then
280+
error "che mount: Wrong number of arguments provided."
281+
return
239282
fi
283+
284+
MOUNT_PATH=$(get_mount_path $2)
285+
286+
if [ ! -e "${MOUNT_PATH}" ]; then
287+
error "che mount: Path provided does not exist."
288+
return
289+
fi
290+
291+
if [ ! -d "${MOUNT_PATH}" ]; then
292+
error "che mount: Path provided is not a valid directory."
293+
return
294+
fi
295+
296+
docker-exec run --rm -it --cap-add SYS_ADMIN \
297+
--device /dev/fuse \
298+
--name che-mount \
299+
-v "${MOUNT_PATH}":/mnthost \
300+
codenvy/che-mount $(get_docker_host_ip) $3
240301
}
241302

242303
# See: https://sipb.mit.edu/doc/safe-shell/
@@ -256,10 +317,14 @@ case ${CHE_CLI_ACTION} in
256317
execute_che_file
257318
;;
258319
update)
259-
update_che_launcher
320+
update_che_image ${CHE_LAUNCHER_IMAGE_NAME}
321+
update_che_image ${CHE_SERVER_IMAGE_NAME}
322+
;;
323+
mount)
324+
mount_local_directory "$@"
260325
;;
261326
help)
262-
get_list_of_variables
327+
# get_list_of_variables
263328
usage
264329
;;
265330
esac

dockerfiles/che-mount/Dockerfile

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright (c) 2012-2016 Codenvy, S.A.
2+
# All rights reserved. This program and the accompanying materials
3+
# are made available under the terms of the Eclipse Public License v1.0
4+
# which accompanies this distribution, and is available at
5+
# http://www.eclipse.org/legal/epl-v10.html
6+
#
7+
# Contributors:
8+
# Tyler Jewell - Initial implementation
9+
#
10+
# BUILD:
11+
# docker build -t codenvy/che-mount .
12+
#
13+
# LAUNCH CONTAINER:
14+
# docker run --rm -it --cap-add SYS_ADMIN --device /dev/fuse
15+
# -v /var/run/docker.sock:/var/run/docker.sock
16+
# -v <host-dir>:/mnthost codenvy/che-mount <ip> <ws-port>
17+
#
18+
# RUN IN CONTAINER:
19+
# echo "secret" | $(echo "yes" | sshfs user@10.0.75.2:/projects /mntssh -p 32774)
20+
#
21+
# TO UNMOUNT IN CONTAINER
22+
# fusermount -u /mntssh
23+
#
24+
# INTERNAL SYNC SCRIPT
25+
# /bin/synch.sh <ip> <ws-port>
26+
27+
FROM centos
28+
29+
RUN rpm -Uvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-7.noarch.rpm && \
30+
yum -y install fuse-sshfs && \
31+
mkdir /mntssh && \
32+
mkdir /mnthost
33+
34+
RUN yum install -y yum install -y ocaml ocaml-camlp4-devel ctags ctags-etags make && \
35+
mkdir -p /opt/unison && \
36+
cd /opt/unison && \
37+
curl -O http://www.seas.upenn.edu/~bcpierce/unison//download/releases/stable/unison-2.48.4.tar.gz && \
38+
tar xzvf unison-2.48.4.tar.gz && \
39+
cd src && \
40+
make && \
41+
cp unison /usr/local/sbin/ && \
42+
cp unison /usr/bin/ && \
43+
cd /opt && \
44+
rm -rf src/
45+
46+
COPY sync.sh /bin
47+
48+
ENTRYPOINT ["/bin/sync.sh"]

dockerfiles/che-mount/sync.sh

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/bin/sh
2+
# Copyright (c) 2012-2016 Codenvy, S.A., Red Hat, Inc
3+
# All rights reserved. This program and the accompanying materials
4+
# are made available under the terms of the Eclipse Public License v1.0
5+
# which accompanies this distribution, and is available at
6+
# http://www.eclipse.org/legal/epl-v10.html
7+
#
8+
# Contributors:
9+
# Tyler Jewell - Initial implementation
10+
#
11+
init_logging() {
12+
BLUE='\033[1;34m'
13+
GREEN='\033[0;32m'
14+
RED='\033[0;31m'
15+
NC='\033[0m'
16+
}
17+
18+
init_global_variables() {
19+
20+
USAGE="
21+
Usage:
22+
docker run --rm -it --cap-add SYS_ADMIN --device /dev/fuse
23+
-v <local-mount>/:/mnthost codenvy/che-mount <ip> <port>
24+
<local-mount> Host directory to sync files, must end with a slash '/'
25+
<ip> IP address of Che server
26+
<port> Port of workspace SSH server - retrieve inside workspace
27+
"
28+
}
29+
30+
parse_command_line () {
31+
if [ $# -eq 0 ]; then
32+
usage
33+
exit
34+
fi
35+
}
36+
37+
usage () {
38+
printf "%s" "${USAGE}"
39+
}
40+
41+
info() {
42+
printf "${GREEN}INFO:${NC} %s\n" "${1}"
43+
}
44+
45+
debug() {
46+
printf "${BLUE}DEBUG:${NC} %s\n" "${1}"
47+
}
48+
49+
error() {
50+
printf "${RED}ERROR:${NC} %s\n" "${1}"
51+
}
52+
53+
error_exit() {
54+
echo "---------------------------------------"
55+
error "!!!"
56+
error "!!! ${1}"
57+
error "!!!"
58+
echo "---------------------------------------"
59+
exit 1
60+
}
61+
62+
# See: https://sipb.mit.edu/doc/safe-shell/
63+
set -e
64+
set -u
65+
66+
init_logging
67+
init_global_variables
68+
parse_command_line "$@"
69+
70+
# Cleanup old ssh mount just incase
71+
#OUTPUT=$(fusermount -u /mntssh) #> /dev/null 2>&1)
72+
#echo $OUTPUT
73+
74+
sshfs user@$1:/projects /mntssh -p $2
75+
unison /mntssh /mnthost -batch -fat -silent -auto -prefer=newer > /dev/null 2>&1
76+
77+
info "INFO: ECLIPSE CHE: Successfully mounted user@$1:/projects"
78+
79+
while :
80+
do
81+
unison /mntssh /mnthost -batch -fat -silent -auto -prefer=newer > /dev/null 2>&1
82+
sleep 1
83+
done

0 commit comments

Comments
 (0)