-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdev.sh
More file actions
executable file
·73 lines (61 loc) · 1.5 KB
/
dev.sh
File metadata and controls
executable file
·73 lines (61 loc) · 1.5 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
#!/usr/bin/env sh
set -e
dev_image=${DEV_IMAGE:-"ns-user-manager-dev:20.10.0"}
container_name=ns-user-manager-dev
build_image() {
podman build \
--force-rm \
--layers \
--target "$1" \
--tag "$2" \
.
}
if [ "$1" = "build" ]; then
build_image "dev" "$dev_image"
exit 0
fi
if [ "$1" = "preview" ]; then
build_image "build" "$dev_image:build"
podman run \
--rm \
--interactive \
--tty \
--network host \
"$dev_image:build" \
npm run preview
exit 0
fi
if ! podman image exists "$dev_image"; then
build_image "dev" "$dev_image"
fi
# params given will be appended at the end of the command
commands_given="$*"
shift "$#"
# setup podman command
set -- "$@" podman
if podman container exists $container_name; then
# base command to execute in container
set -- "$@" exec
# if terminal is interactive, add interactive and tty flags
if [ -t 0 ]; then
set -- "$@" --interactive --tty
fi
# add container name
set -- "$@" $container_name
else
# base command to create container
set -- "$@" run --name $container_name --replace --rm --volume "$(pwd)":/app:Z --network host
# if terminal is interactive, add interactive and tty flags
if [ -t 0 ]; then
set -- "$@" --interactive --tty
fi
# add image name
set -- "$@" "$dev_image"
fi
# if commands_given are not zero, append them
if [ -n "$commands_given" ]; then
for command in $commands_given; do
set -- "$@" "$command"
done
fi
"$@"