-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathdocker-dev.sh
More file actions
executable file
·63 lines (56 loc) · 1.39 KB
/
docker-dev.sh
File metadata and controls
executable file
·63 lines (56 loc) · 1.39 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
#!/bin/bash
set -euo pipefail
# Function to check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Determine container engine
if [[ -n "${CONTAINER_ENGINE:-}" ]]; then
# Use value from env if set
ENGINE="$CONTAINER_ENGINE"
if ! command_exists "$ENGINE"; then
echo "ERROR: Specified CONTAINER_ENGINE '$ENGINE' is not installed." >&2
exit 1
fi
else
# Auto-detect: prefer podman
if command_exists "podman"; then
ENGINE="podman"
elif command_exists "docker"; then
ENGINE="docker"
else
echo "ERROR: Neither podman nor docker is available." >&2
exit 1
fi
fi
# Set user namespace argument only for podman
USERNS_ARG=""
if [[ "$ENGINE" == "podman" ]]; then
USERNS_ARG="--userns=keep-id"
fi
# Require at least one argument
if [[ $# -lt 1 ]]; then
echo "Usage: $0 [build|<command>]" >&2
exit 1
fi
CMD="$1"
shift
# Use -it only if TTY is available (e.g., not in CI)
if [ -t 1 ]; then
INTERACTIVE="-it"
else
INTERACTIVE=""
fi
if [[ "$CMD" == "build" ]]; then
echo "Building image with $ENGINE..."
"$ENGINE" build \
--build-arg UID=$(id -u) \
--build-arg GID=$(id -g) \
-t aaproxybr .
else
echo "Running container with $ENGINE: aaproxybr $CMD $*"
"$ENGINE" run $USERNS_ARG $INTERACTIVE --rm \
-v "$(pwd):/app":z \
aaproxybr \
"$CMD" "$@"
fi