-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmake_docker.sh
executable file
·66 lines (58 loc) · 2.21 KB
/
make_docker.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
#!/bin/sh
# ! make_docker.sh has to be sh, not bash as the docker image that runs it does not
# include bash
#
# Copyright (C) 2021 Ultimaker B.V.
set -eu
# When releasing a new docker image, update the version below to match the one uploaded to cloudsmith
DOCKER_IMAGE_RELEASED="v1"
DOCKER_IMAGE_CACHE="ghcr.io/ultimaker/um-kernel"
set_docker_image_name_version()
{
DOCKER_IMAGE_NAME="${DOCKER_IMAGE_NAME:-${DOCKER_IMAGE_CACHE}}"
DOCKER_IMAGE_VERSION="${DOCKER_IMAGE_VERSION:-${DOCKER_IMAGE_RELEASED}}"
}
build_docker()
{
set_docker_image_name_version
echo "Building image ${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_VERSION}"
docker build --cache-from "${DOCKER_IMAGE_CACHE}" \
--build-arg BUILDKIT_INLINE_CACHE=1 \
-f docker_env/Dockerfile -t "${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_VERSION}" .
if ! docker run --rm --privileged "${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_VERSION}" "./buildenv_check.sh"; then
echo "Something is wrong with the build environment, please check your Dockerfile."
docker image rm "${DOCKER_IMAGE_NAME}"
exit 1
fi
}
# This section actually runs the parameters in the docker image
DOCKER_WORK_DIR="${WORKDIR:-/build}"
PREFIX="/usr"
run_in_docker()
{
set_docker_image_name_version
echo "Running '${*}' in docker."
# In order to run local kernel config tools, like menuconfig, we need to attach a tty to the docker,
# but that will fail in CI. So we first check if we have a tty and then add the "-t" argument. The
# standart input attach ("-i") is safe to keep there, even in CI.
terminal_arg="-i";
if tty; then
terminal_arg="-it"
fi;
docker run \
--rm \
--privileged \
"${terminal_arg}" \
-u "$(id -u):$(id -g)" \
-v "$(pwd):${DOCKER_WORK_DIR}" \
-v /etc/localtime:/etc/localtime:ro \
-v /etc/timezone:/etc/timezone:ro \
-e "PREFIX=${PREFIX}" \
-e "RELEASE_VERSION=${RELEASE_VERSION:-999.999.999}" \
-e "ONLY_CHECK_STAGED=${ONLY_CHECK_STAGED:-}" \
-e "CALLER_UID=$(id -u)" \
-e "CALLER_GID=$(id -g)" \
-w "${DOCKER_WORK_DIR}" \
"${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_VERSION}" \
"${@:-}"
}