This repository has been archived by the owner on May 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
create_env.sh
executable file
·92 lines (81 loc) · 2.28 KB
/
create_env.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
display_help() {
echo "Usage: $0 PROJ_NAME DOCKER_IMAGE [options...] " >&2
echo ""
echo " PROJ_NAME"
echo " Specifies the name of the project"
echo " This will create a directory with the specified name in the project folder"
echo ""
echo " DOCKER_IMAGE"
echo " Specifies the name of the docker image the project should use."
echo ""
echo "Options:"
echo " --container-name [CONTAINER NAME]"
echo " Specifies the name of the project's docker container."
echo " By default the container name will be the same as the environment name."
echo ""
echo " --project-dir [PATH/TO/PROJ]"
echo " Specifies the directory where the projects are created."
echo " By default the default project folder is \$HOME\lkae_proj."
}
#required options
PROJ_NAME=$1
DOCKER_IMAGE=$2
shift 2
CONTAINER_NAME=$PROJ_NAME
PROJECT_DIR=$HOME/lkae_proj
while true; do
if [ $# -eq 0 ];then
echo $#
break
fi
case "$1" in
-h | --help)
display_help
exit 0
;;
--container-name)
CONTAINER_NAME=$2
shift 2
;;
--project-dir)
PROJECT_DIR=$2
shift 2
;;
-*)
echo "Error: Unknown option: $1" >&2
exit 1
;;
*) # No more options
break
;;
esac
done
#devcontianer.json basic template
JSON="{\n
\"name\": \"$CONTAINER_NAME\",\n
\"image\": \"$DOCKER_IMAGE\",\n
\n
\"settings\": {\n
\"terminal.integrated.automationShell.linux\": \"/bin/bash\"\n
},\n
\n
\"extensions\":[\n
],\n
\n
\n
\"workspaceMount\": \"source=\${localWorkspaceFolder},target=/workspace,type=bind,consistency=delegated\",\n
\"workspaceFolder\": \"/workspace\",\n
\n
\"containerEnv\": {\n
\"WORKSPACE\": \"/workspace\"\n
},\n
\n
\"runArgs\": [\"--privileged\", \"--device=/dev/kvm:/dev/kvm\"]\n
}"
#create the directory structure
mkdir -p $PROJECT_DIR/$PROJ_NAME/.devcontainer
#populate the container config
echo -e $JSON > $PROJECT_DIR/$PROJ_NAME/.devcontainer/devcontainer.json
#launch VS Code
cd $PROJECT_DIR/$PROJ_NAME && code .