-
Notifications
You must be signed in to change notification settings - Fork 0
/
dev.sh
executable file
·54 lines (46 loc) · 1.48 KB
/
dev.sh
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
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
SCRIPT_PATH="$(cd "$(dirname "$0")" &>/dev/null; pwd -P)"
declare -r SCRIPT_PATH
declare -r IMAGE_REGISTRY="${IMAGE_PREFIX:-localhost/snapserv/container}"
declare -r IMAGE_ARCH="${IMAGE_ARCH:-linux/arm64}"
main() {
# Change to script directory
cd "${SCRIPT_PATH}"
# Build container images
export REGISTRY="${IMAGE_REGISTRY}"
docker buildx bake --load --set="*.platform=${IMAGE_ARCH}"
docker image ls | grep "${IMAGE_REGISTRY}/"
# If an argument was specified, run the image
if [[ $# -gt 0 ]]; then
# Use first argument as image name
local -r image="$1"; shift
# Split arguments based on double-dash
local arg
local -a docker_args=()
local -a image_args=()
# Split arguments into docker and image arguments
for arg in "$@"; do
if [[ "${arg}" == "--" ]]; then
image_args=("${@:1}")
break
else
docker_args+=("${arg}")
fi
done
# Use docker to run the image
docker run \
--rm \
--platform "${IMAGE_ARCH}" \
--read-only \
--tmpfs /run:exec \
--tmpfs /tmp \
-e "S6_KILL_GRACETIME=0" \
-e "S6_READ_ONLY_ROOT=1" \
"${docker_args[@]+"${docker_args[@]}"}" \
"${IMAGE_REGISTRY}/${image}:latest" \
"${image_args[@]+"${image_args[@]}"}"
fi
}
main "$@"