-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
75 lines (65 loc) · 2.03 KB
/
Copy pathentrypoint.sh
File metadata and controls
75 lines (65 loc) · 2.03 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
set -e
if [ -z "$GOOGLE_APPLICATION_CREDENTIALS" ]; then
echo "Error: GOOGLE_APPLICATION_CREDENTIALS environment variable is required"
exit 1
fi
# Default values
MOUNT_POINT=${MOUNT_POINT:-/mnt/gcs}
FUSE_UID=${GCSFUSE_UID:-1000}
FUSE_GID=${GCSFUSE_GID:-1000}
FILE_MODE=${FILE_MODE:-777}
DIR_MODE=${DIR_MODE:-777}
build_gcsfuse_cmd() {
local bucket_name="$1"
local mount_point="$2"
local cmd=("gcsfuse")
cmd+=(--uid "$FUSE_UID")
cmd+=(--gid "$FUSE_GID")
cmd+=(--file-mode "$FILE_MODE")
cmd+=(--dir-mode "$DIR_MODE")
if [ "$ALLOW_OTHER" = "true" ]; then
cmd+=("-o" "allow_other")
fi
if [ "$IMPLICIT_DIRS" = "true" ]; then
cmd+=("--implicit-dirs")
fi
cmd+=("$bucket_name" "$mount_point")
printf '%s\n' "${cmd[*]}"
"${cmd[@]}"
}
# Handle fuse.conf modification
if [ "$ALLOW_OTHER" = "true" ]; then
if ! grep -q "user_allow_other" /etc/fuse.conf; then
echo "user_allow_other" >> /etc/fuse.conf
fi
fi
if [ -n "${MOUNTS:-}" ]; then
echo "Using multi-mount mode"
IFS=';' read -ra MOUNT_SPECS <<< "$MOUNTS"
for spec in "${MOUNT_SPECS[@]}"; do
if [ -z "$spec" ]; then
continue
fi
bucket_name="${spec%%=*}"
mount_point="${spec#*=}"
if [ -z "$bucket_name" ] || [ -z "$mount_point" ] || [ "$bucket_name" = "$mount_point" ]; then
echo "Error: invalid MOUNTS entry '$spec'. Expected bucket=/mount/path"
exit 1
fi
mkdir -p "$mount_point"
echo "Mounting GCS bucket '${bucket_name}' to '${mount_point}'"
build_gcsfuse_cmd "$bucket_name" "$mount_point"
done
else
if [ -z "${BUCKET_NAME:-}" ]; then
echo "Error: BUCKET_NAME environment variable is required when MOUNTS is not set"
exit 1
fi
mkdir -p "$MOUNT_POINT"
echo "Mounting GCS bucket '${BUCKET_NAME}' to '${MOUNT_POINT}'"
build_gcsfuse_cmd "$BUCKET_NAME" "$MOUNT_POINT"
fi
echo "GCS bucket mount(s) completed successfully!"
# Keep container running
tail -f /dev/null