-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdockerize.sh
executable file
·78 lines (69 loc) · 2.64 KB
/
dockerize.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env bash
#
# Run make commands inside a container
# E.g. tools/dockerize.sh stage0 DEVICE_OPTIMIZATION=arm64
#
# Get make command
MAKE_PARAMS="help"
if [ $# -ge 1 ]; then
# all arguments as a single string
MAKE_PARAMS="$*"
# all arguments preserving their structure
INPUT_ARGS="$@"
fi
# Device optimizations (see: README.md)
DEVICE_OPTIMIZATION=${DEVICE_OPTIMIZATION:-arm64}
# Get directory tree and setup paths
TOOLS_DIR=$(cd "$(dirname "$0")" && pwd)
BASE_DIR=$(cd "${TOOLS_DIR}"/../ && pwd)
# Detect the host system and fix the necessary requirements if needed
HOST_OS=$(uname -s)
case "${HOST_OS}" in
"Darwin")
# macOS uses uses a case-insensitive filesystem which can cause issues when bind
# mounting directories into containers, for example with 'mknod' commands
# We should use a directory from the container not being mounted
STAGE0_PKGMK_WORK_DIR="/var/lib/pkg/work"
STAGE1_PKGMK_WORK_DIR="/var/lib/pkg/work"
;;
esac
# Set workspace dir inside the container
WORKSPACE_DIR="/crux-arm-release"
# Docker builder image and platform
DOCKER_IMAGE=${DOCKER_IMAGE:-docker.io/sepen/crux:3.7-arm64-builder}
DOCKER_PLATFORM=${DOCKER_PLATFORM:-linux/arm64}
# Run the docker command and bind some directories
# Avoid the whole directory tree of this project to ${WORKSPACE_DIR} since
# this will end up with "too many open files" when managing large docker volumes
case "$1" in
"debug"|"shell")
docker run --init --privileged --rm -it \
--platform "${DOCKER_PLATFORM}" \
-v "${BASE_DIR}/Makefile":${WORKSPACE_DIR}/Makefile \
-v "${BASE_DIR}/devices":${WORKSPACE_DIR}/devices \
-v "${BASE_DIR}/ports":${WORKSPACE_DIR}/ports \
-v "${BASE_DIR}/sources":${WORKSPACE_DIR}/sources \
-v "${BASE_DIR}/stage0":${WORKSPACE_DIR}/stage0 \
-v "${BASE_DIR}/stage1":${WORKSPACE_DIR}/stage1 \
"${DOCKER_IMAGE}" bash
;;
*)
docker run --init --privileged --rm \
--platform "${DOCKER_PLATFORM}" \
-v "${BASE_DIR}/Makefile":${WORKSPACE_DIR}/Makefile \
-v "${BASE_DIR}/devices":${WORKSPACE_DIR}/devices \
-v "${BASE_DIR}/ports":${WORKSPACE_DIR}/ports \
-v "${BASE_DIR}/sources":${WORKSPACE_DIR}/sources \
-v "${BASE_DIR}/stage0":${WORKSPACE_DIR}/stage0 \
-v "${BASE_DIR}/stage1":${WORKSPACE_DIR}/stage1 \
"${DOCKER_IMAGE}" bash -x -c "
# Disable sudo password prompt
echo '%wheel ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/wheel
cd ${WORKSPACE_DIR} && \
mkdir -p ${STAGE0_PKGMK_WORK_DIR} ${STAGE1_PKGMK_WORK_DIR}
make V=1 ${MAKE_PARAMS} \
STAGE0_PKGMK_WORK_DIR=${STAGE0_PKGMK_WORK_DIR} \
STAGE1_PKGMK_WORK_DIR=${STAGE1_PKGMK_WORK_DIR}
"
;;
esac