-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathup
More file actions
executable file
·79 lines (69 loc) · 2.68 KB
/
up
File metadata and controls
executable file
·79 lines (69 loc) · 2.68 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
76
77
78
79
#!/bin/bash
set -e
CONTAINER_NAME="dev-ssh-1"
# On macOS, Docker runs in a VM (Colima/Docker Desktop).
# - BuildKit (for builds) uses SSH_AUTH_SOCK from macOS
# - Runtime volume mounts need a path inside the VM: /run/host-services/ssh-auth.sock
# These are different paths, so we use DOCKER_SSH_SOCK for runtime mounts.
if [[ "$(uname)" == "Darwin" ]]; then
# Validate SSH_AUTH_SOCK exists on macOS (for BuildKit during builds)
if [ -z "$SSH_AUTH_SOCK" ] || [ ! -S "$SSH_AUTH_SOCK" ]; then
echo "Error: SSH agent socket not found at: ${SSH_AUTH_SOCK:-<not set>}"
echo ""
echo "Ensure your SSH agent is running:"
echo " ssh-add -l"
exit 1
fi
# For runtime, Docker needs the VM's forwarded socket path
export DOCKER_SSH_SOCK="/run/host-services/ssh-auth.sock"
# Validate the socket exists inside the VM
if ! colima ssh -- test -S "$DOCKER_SSH_SOCK" 2>/dev/null; then
echo "Error: SSH agent socket not found in Colima VM at: $DOCKER_SSH_SOCK"
echo ""
echo "Start Colima with SSH agent forwarding:"
echo " colima stop && colima start --ssh-agent"
exit 1
fi
else
# On Linux, Docker runs natively and can access host paths directly.
# Both BuildKit and runtime use the same path.
# Check if container already exists - if so, use its expected socket
if docker container inspect "$CONTAINER_NAME" &>/dev/null; then
EXPECTED_SOCKET=$(docker inspect "$CONTAINER_NAME" --format '{{range .Mounts}}{{if eq .Destination "/ssh-agent"}}{{.Source}}{{end}}{{end}}')
if [ -n "$EXPECTED_SOCKET" ]; then
export DOCKER_SSH_SOCK="$EXPECTED_SOCKET"
if [ ! -S "$EXPECTED_SOCKET" ]; then
echo "Error: Tried to restart existing container but it expects SSH socket that does not exist at: $EXPECTED_SOCKET"
echo ""
SOCKET_DIR=$(dirname "$EXPECTED_SOCKET")
echo "To create an ssh-agent at the expected location, run:"
echo ""
echo " mkdir -p $SOCKET_DIR && ssh-agent -a $EXPECTED_SOCKET"
echo ""
echo "Then add keys with:"
echo " SSH_AUTH_SOCK=$EXPECTED_SOCKET ssh-add"
echo ""
exit 1
fi
fi
else
# No container exists - SSH_AUTH_SOCK must be set
if [ -z "$SSH_AUTH_SOCK" ]; then
echo "Error: SSH_AUTH_SOCK is not set."
echo ""
echo "Start an SSH agent:"
echo " eval \$(ssh-agent)"
exit 1
fi
if [ ! -S "$SSH_AUTH_SOCK" ]; then
echo "Error: SSH agent socket not found at: $SSH_AUTH_SOCK"
echo ""
echo "Start an SSH agent or set SSH_AUTH_SOCK to an existing agent socket."
echo ""
echo " eval \$(ssh-agent)"
exit 1
fi
export DOCKER_SSH_SOCK="$SSH_AUTH_SOCK"
fi
fi
docker compose up "$@"