This repository has been archived by the owner on Jun 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdev.sh
129 lines (114 loc) · 3.82 KB
/
dev.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/sh
# --------------------------------------------------------
#
# This script both builds and runs the local R-Shiny app
# using the docker file supplied.
#
# --------------------------------------------------------
if [[ "$1" == "--help" ]]
then
echo "
Builds and deploys the app locally in a Docker image.
If you are on a Unix-based OS (e.g., OSX or Linux) the
logs and bookmarks will be mounted locally to help
with debugging etc.
Options:
--help : displays this message
--no-cache : builds the Docker image from scratch,
ignoring the cache
(runs docker build with the --no-cache flag)
"
exit
elif [[ "$1" == "--no-cache" ]]
then
echo "Building with no cache"
no_cache="--no-cache"
else
no_cache=""
fi
# --------------------------------------------------------
#
# create the local dockerfile
#
# --------------------------------------------------------
if [[ $(diff packages.txt .packages.txt) ]] || [[ $(diff gh-packages.txt .gh-packages.txt) ]] || [[ $(diff system-libraries.txt .system-libraries.txt) ]] || [[ ! -f Dockerfile.local ]]
then
if [[ $(head -n 1 packages.txt | wc -w) -gt 0 ]]
then
rlib_str="$(head -n 1 packages.txt)"
else
rlib_str=""
fi
if [[ $(head -n 1 gh-packages.txt | wc -w) -gt 0 ]]
then
## '@', '.', and '/' need to be escaped:
r_gh_lib_str=$(sed 's/[\@\./]/\\&/g' <<<"$(head -n 1 gh-packages.txt)")
else
r_gh_lib_str=""
fi
if [[ $(head -n 1 system-libraries.txt | wc -w) -gt 0 ]]
then
syslib_str="$(head -n 1 system-libraries.txt)"
else
syslib_str=""
fi
sed -e "s/\${RLIBS}/$rlib_str/; s/\${RGHLIBS}/$r_gh_lib_str/; s/\${SYSLIBS}/$syslib_str/" Dockerfile > Dockerfile.local
fi
cp packages.txt .packages.txt
cp gh-packages.txt .gh-packages.txt
cp system-libraries.txt .system-libraries.txt
# --------------------------------------------------------
#
# Build
#
# --------------------------------------------------------
docker build $no_cache -t shiny -f Dockerfile.local .
# --------------------------------------------------------
#
# Run
#
# --------------------------------------------------------
if [[ $? > 0 ]]
then
echo "There was an error building the image"
exit 1
else
echo "Running Shiny App..."
os=$OSTYPE
if [[ "$os" == 'msys' ]] || [[ "$os" == 'cygwin' ]] || [[ "$os" == 'win32' ]]
then
# --------------------------------------------------------
#
# Run the image - unfortunately won't mount the logs and
# bookmarks locally
#
# --------------------------------------------------------
docker run -i -t --rm --name myshiny -p 3838:3838 shiny
else
# --------------------------------------------------------
#
# this runs the image and mounts everything interesting
# to your local repo so you can play and see the logs
# without having to go into the container (hopefully)
#
# --------------------------------------------------------
docker run --rm --name myshiny \
-p 3838:3838 \
-v `pwd`/_mount/bookmarks:/var/lib/shiny-server \
-v `pwd`/_mount/logs:/var/log/shiny-server \
-v `pwd`/_mount/output:/srv/shiny-server-output \
-v `pwd`/_mount/tmp:/tmp \
-v `pwd`/app:/srv/shiny-server \
shiny
# docker run --rm --name shiny \
# -p 3838:3838 \
# -v `pwd`/_mount/bookmarks:/var/lib/shiny-server \
# -v `pwd`/_mount/logs:/var/log/shiny-server \
# -v `pwd`/_mount/output:/srv/shiny-server-output \
# -v `pwd`/_mount/tmp:/tmp \
# -v `pwd`/app:/srv/shiny-server \
# -ti --rm myshiny bash
# docker run --rm --name shiny -p 3838:3838 -v `pwd`/_mount/bookmarks:/var/lib/shiny-server -v `pwd`/_mount/logs:/var/log/shiny-server -v `pwd`/_mount/output:/srv/shiny-server-output -v `pwd`/_mount/tmp:/tmp -v `pwd`/app:/srv/shiny-server -ti --rm myshiny bash
fi
exit 0
fi