-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathrun
More file actions
executable file
·61 lines (54 loc) · 1.52 KB
/
run
File metadata and controls
executable file
·61 lines (54 loc) · 1.52 KB
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
#!/bin/bash
SELF_DIR="$(cd "$(dirname "${BASH_SOURCE}")" && pwd -P)"
TAG="isaac_automator"
# build image if it doesn't exist
if [[ $(docker images -q "$TAG" 2> /dev/null) == '' ]]; then
"${SELF_DIR}/build"
fi
# Forward some env vars if they are set.
# We dont want to forward aws/gcp/azure creds because we store them in state/ dir
# so our deployment is completely isolated from the host and self-sufficient.
ENV_ARGS=()
for var in ALIYUN_ACCESS_KEY ALIYUN_SECRET_KEY; do
if [[ -n "${!var}" ]]; then
ENV_ARGS+=(-e "${var}=${!var}")
fi
done
# clean up stale URL file
OPEN_URL_FILE="${SELF_DIR}/.open-url"
rm -f "${OPEN_URL_FILE}"
# background watcher: poll for .open-url and open it on the host immediately
(
while true; do
if [[ -f "${OPEN_URL_FILE}" ]]; then
URL=$(cat "${OPEN_URL_FILE}")
rm -f "${OPEN_URL_FILE}"
if [[ -n "${URL}" ]]; then
if [[ "$OSTYPE" == "darwin"* ]]; then
open "${URL}"
else
xdg-open "${URL}" > /dev/null 2>&1 &
fi
fi
fi
sleep 1
done
) &
WATCHER_PID=$!
if [[ "$OSTYPE" == "darwin"* ]]; then
# we're on mac - enable emulation
docker run --platform linux/x86_64 -it --rm --network host \
-v "${SELF_DIR}":/app \
"${ENV_ARGS[@]}" \
"$TAG" "${*:-bash}"
else
# we're not on mac
docker run -it --rm --network host \
-v "${SELF_DIR}":/app \
"${ENV_ARGS[@]}" \
"$TAG" "${*:-bash}"
fi
# stop the background watcher
kill "${WATCHER_PID}" 2>/dev/null
wait "${WATCHER_PID}" 2>/dev/null
rm -f "${OPEN_URL_FILE}"