forked from intel/xFasterTransformer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_dev_docker.sh
More file actions
74 lines (61 loc) · 2.47 KB
/
Copy pathrun_dev_docker.sh
File metadata and controls
74 lines (61 loc) · 2.47 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
74
#!/bin/bash
cd "$( dirname "${BASH_SOURCE[0]}" )" || exit
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
WORKSPACE="${SCRIPT_DIR}"
USER_NAME=$(id -u -n)
DOCKER_IMG_NAME="intel/xfastertransformer:dev-ubuntu22.04"
TAG="xfastertransformer"
CONTAINER_NAME=${TAG}_$((`date '+%s'`*1000+`date '+%N'`/1000000))
# Check if the current user is root
if [ "$(id -u)" -ne 0 ]; then
# Docker image name
DOCKER_IMG_NAME="${TAG}:${USER_NAME}"
# Handling illegal characters in the docker image names.
DOCKER_IMG_NAME=$(echo "${DOCKER_IMG_NAME}" | sed -e 's/=/_/g' -e 's/,/-/g')
# Convert to all lower-case, as per requirement of Docker image names
DOCKER_IMG_NAME=$(echo "${DOCKER_IMG_NAME}" | tr '[:upper:]' '[:lower:]')
# Check if the Docker image exists
if [ -n "$(docker images -q "${DOCKER_IMG_NAME}")" ]; then
echo "Docker image ${DOCKER_IMG_NAME} exists."
else
echo "Docker image ${DOCKER_IMG_NAME} does not exist."
echo "Build dev image with current USER ID..."
# Dockerfile to be used in docker build
DOCKERFILE_PATH="${SCRIPT_DIR}/dockerfiles/Dockerfile.dev"
DOCKER_CONTEXT_PATH="${SCRIPT_DIR}"
DOCKER_USER="--build-arg USER_NAME=$(id -u -n) --build-arg USER_UID=$(id -u) \
--build-arg USER_GROUP=$(id -g -n) --build-arg USER_GID=$(id -g)"
if [[ ! -f "${DOCKERFILE_PATH}" ]]; then
die "Invalid Dockerfile path: \"${DOCKERFILE_PATH}\""
fi
# Build the docker container.
echo "Building container (${DOCKER_IMG_NAME})..."
docker build ${DOCKER_USER} \
-t "${DOCKER_IMG_NAME}" \
-f "${DOCKERFILE_PATH}" "${DOCKER_CONTEXT_PATH}"
# Check docker build status
if [[ $? != "0" ]]; then
echo "ERROR: docker build failed. Dockerfile is at ${DOCKERFILE_PATH}"
fi
fi
fi
# Print arguments.
echo "WORKSPACE: ${WORKSPACE}"
echo " (docker container name will be ${CONTAINER_NAME})"
echo ""
# By default the container will be removed once it finish running (--rm)
# and share the PID namespace (--pid=host) so the process inside does not have
# pid 1 and SIGKILL is propagated to the process inside.
docker run -it \
--rm \
--privileged=true \
--pid=host \
-P \
--shm-size=16g \
--name "${CONTAINER_NAME}" \
-v /data/:/data/ \
-v "${WORKSPACE}":"${WORKSPACE}" \
-w "${WORKSPACE}" \
-e "http_proxy=$http_proxy" \
-e "https_proxy=$https_proxy" \
"${DOCKER_IMG_NAME}"