This repository has been archived by the owner on Jun 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 74
/
RunDockerImage.sh
executable file
·72 lines (60 loc) · 3.16 KB
/
RunDockerImage.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
#!/bin/bash
###############################################################
# Licensed Materials - Property of IBM
# "Restricted Materials of IBM"
# (C) Copyright IBM Corp. 2019 ALL RIGHTS RESERVED
###############################################################
###############################################################
#
# Author: Eli M. Dow <emdow@us.ibm.com>
#
###############################################################
# Looks for an environment var named CLAI_DOCKER_IMAGE_NAME. If not
# defined, uses the default flag value 'claiplayground' for the docker image.
image_name=${CLAI_DOCKER_IMAGE_NAME-"claiplayground"}
# Looks for an environment var named CLAI_DOCKER_CONTAINER_NAME. If not
# defined, uses the default flag value 'CLAIBotPlayground' for the container.
container_name=${CLAI_DOCKER_CONTAINER_NAME-"CLAIBotPlayground"}
# Controls where CLAI would store internal states for persistence
DefaultBaseDir="${HOME}/.clai"
HostBaseDir="${CLAI_BASEDIR:-${DefaultBaseDir}}"
ContainerBaseDir="/root/.clai"
# docker-run settings that we will always want:
# Run docker in privileged / unrestricted mode (--privileged)
# Allocate a psuedo-terminal in the docker container (-t)
# Run docker with 2GB of memory (-m 2GB)
# Provide a handy human readable name for the container (--name ${container_name})
docker_run_command="docker run --privileged \
-t \
-m 2g \
--name ${container_name}"
if [ -z "$CLAI_DOCKER_JENKINSBUILD" ]; then
# Settings we will want only when running from a command shell:
# Run docker in a detached daemon mode (-d)
# Forward the ports to the localhost so we can SSH (-P)
# Mount a host directory to the container directory (-v ${HostBaseDir}:${ContainerBaseDir})
docker_run_command="${docker_run_command} \
-d \
-P \
-v ${HostBaseDir}:${ContainerBaseDir}"
else
# Settings we will want only when running from Jenkins:
# Mount a host directory to the container directory (-v ${HostBaseDir}:/root)
# Use pytest as the entrypoint (--entrypoint pytest)
docker_run_command="${docker_run_command} \
-v ${HostBaseDir}:/root \
--entrypoint pytest"
fi
docker_run_command="${docker_run_command} ${image_name}"
# If we are redirecting output to a file, add that to the command here
if [ -n "$CLAI_DOCKER_OUTPUT" ]; then
docker_run_command="${docker_run_command} > ${CLAI_DOCKER_OUTPUT}"
fi
# Execute the docker-run command
if [ -z "$CLAI_DOCKER_JENKINSBUILD" ]; then
eval ${docker_run_command}
echo 'User for ssh is root and the default pass Bashpass'
else
echo ${docker_run_command}
eval ${docker_run_command}
fi