-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsync
More file actions
executable file
·57 lines (52 loc) · 2.2 KB
/
Copy pathcsync
File metadata and controls
executable file
·57 lines (52 loc) · 2.2 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
#!/usr/bin/env bash
# Runs py_conf_sync.py inside Docker so nothing executes on the host.
# Usage: csync [--rebuild] <py_conf_sync args...>
# --rebuild Force a fresh local build before running
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
LOCAL_IMAGE="py-conf-sync:local"
PUBLISHED_IMAGE="ghcr.io/kellenmurphy/py-conf-sync:latest"
if [[ "${1:-}" == "--rebuild" ]]; then
shift
docker build --no-cache --network=host -t "$LOCAL_IMAGE" "$SCRIPT_DIR" >&2
IMAGE="$LOCAL_IMAGE"
elif docker image inspect "$LOCAL_IMAGE" >/dev/null 2>&1; then
IMAGE="$LOCAL_IMAGE"
elif docker pull "$PUBLISHED_IMAGE" >/dev/null 2>&1; then
IMAGE="$PUBLISHED_IMAGE"
else
echo "[py-conf-sync] No image found — building locally..." >&2
docker build --network=host -q -t "$LOCAL_IMAGE" "$SCRIPT_DIR" >&2
IMAGE="$LOCAL_IMAGE"
fi
# Mount ~/.csync.env into the container at the same path so _find_env_file() can locate it.
# If it's a FIFO (e.g. a 1Password-served environment), Docker's VM file sharing cannot
# pass it through — read it once on the host and inject the values as environment
# variables instead (py_conf_sync accepts credentials from the environment). The content
# is passed via process substitution on the exec line below: the fd only stays open
# through exec if the substitution is part of that command, not a prior array assignment.
home_env_args=()
env_file_content=""
if [[ -p "$HOME/.csync.env" ]]; then
env_file_content="$(cat "$HOME/.csync.env")"
elif [[ -f "$HOME/.csync.env" ]]; then
home_env_args+=(-v "$HOME/.csync.env:$HOME/.csync.env" -e "HOME=$HOME")
fi
# Auto-mount any absolute paths in the arguments (handles: scan /abs/path, --config /abs/file)
extra_mounts=()
for arg in "$@"; do
if [[ "$arg" == /* ]] && [[ -e "$arg" ]]; then
extra_mounts+=(-v "$arg:$arg")
fi
done
# An empty env-file is a harmless no-op, so the substitution is unconditional.
exec docker run --rm \
--network=host \
--user "$(id -u):$(id -g)" \
-v "$(pwd):/workspace" \
-w /workspace \
--env-file <(printf '%s\n' "$env_file_content") \
"${home_env_args[@]+"${home_env_args[@]}"}" \
"${extra_mounts[@]+"${extra_mounts[@]}"}" \
"$IMAGE" \
"$@"