forked from quartiq/artiq-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dartiq
executable file
·210 lines (181 loc) · 6.06 KB
/
dartiq
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/bin/bash
if [ "$1" == "--help" ]; then
echo "dartiq [options] [command]
Run ARTIQ in Docker container.
When no command is supplied an interactive shell with ARTIQ environment enabled is started.
Otherwise supplied command is started in ARTIQ environment.
Options:
--image <IMAGE TAG>
use image specified by IMAGE TAG
--user <USER>
in the container act as a USER, defaults to current user
--home <PATH>
when running as non-root user mount specified directory as home directory
--workspace <DIRECTORY>
direcotry to be mounted as /workspace and be a default home directory when running
in non-root mode, defaults to current directory
--gateware-toolchain
path to gatware toolchain, in case of Xilinx Vivado it should point to the directory
where Vivado directory is located
--artiq <DIRECTORY>
directory from which is to be used as ARTIQ sources
--misoc <DIRECTORY>
directory from which is to be used as MiSOC sources
--migen <DIRECTORY>
directory from which is to be used as Migen sources
--docker-options '<OPTIONS>'
adds string <OPTIONS> as additional parameters to docker call
--debug
enable debugging of docker command
Environmental variables used:
ARTIQ_DOCKER_TOOLS_PATH - equivalent of gateware-toolchain option
ARTIQ_DOCKER_HOME_PATH - equivalent of home option
ARTIQ_DOCKER_IMAGE - equivalent of image option
ARTIQ_DOCKER_ARTIQ_PATH - equivalent of artiq option
ARTIQ_DOCKER_MISOC_PATH - equivalent of misoc option
ARTIQ_DOCKER_MIGEN_PATH - equivalent of migen option
ARTIQ_DOCKER_OPTIONS - equivalent of docker-options option
NOTE 1: Options have higher priority then environmental variables.
NOTE 2: If no Artiq source is supplied version from the image is used.
"
exit 0
fi
# ---------------------------------------------------------------------------------------------------------------------
MIGEN_PATH="$ARTIQ_DOCKER_MIGEN_PATH"
MISOC_PATH="$ARTIQ_DOCKER_MISOC_PATH"
ARTIQ_PATH="$ARTIQ_DOCKER_ARTIQ_PATH"
TOOLS_PATH="$ARTIQ_DOCKER_TOOLS_PATH"
DARTIQ_HOME_PATH="$ARTIQ_DOCKER_HOME_PATH"
IMAGE="$ARTIQ_DOCKER_IMAGE"
DOCKER_OPTIONS="$ARTIQ_DOCKER_OPTIONS"
WORKSPACE="$(pwd)"
ENTRYPOINT_ARGS=""
ARGUMENTS_LEFT=()
ENV_VARS=""
DEVICES=""
MOUNTS="-v /run/udev:/run/udev:ro -v /dev/bus/usb:/dev/bus/usb -v /tmp/.X11-unix:/tmp/.X11-unix"
if [ -z "$IMAGE" ]; then
IMAGE="quartiq/artiq:latest"
fi
# ---------------------------------------------------------------------------------------------------------------------
# Parse arguments
while [ "$1" != "" ]; do
case $1 in
"--debug")
set -o xtrace
shift
;;
"--image")
shift
IMAGE="$1"
shift
;;
"--user")
shift
HOST_USER="$1"
shift
;;
"--workspace")
shift
WORKSPACE="$(readlink -f $1)"
# Check if workspace exists. If not create it. Otherwise it will be
# created by Docker and access rights will be messed.
if [ ! -d "$WORKSPACE" ]; then
mkdir -p "$WORKSPACE"
fi
shift
;;
"--gateware-toolchain")
shift
TOOLS_PATH="$1"
shift
;;
"--migen")
shift
MIGEN_PATH="$1"
shift
;;
"--misoc")
shift
MISOC_PATH="$1"
shift
;;
"--artiq")
shift
ARTIQ_PATH="$1"
shift
;;
"--home")
shift
DARTIQ_HOME_PATH="$1"
shift
;;
"--docker-options")
shift
DOCKER_OPTIONS="$1"
shift
;;
*)
ARGUMENTS_LEFT+=($1)
shift
;;
esac
done
# ---------------------------------------------------------------------------------------------------------------------
# Home directory
if [ -z "$DARTIQ_HOME_PATH" ]; then
DARTIQ_HOME_PATH="$WORKSPACE/.dartiq_home"
fi
# ---------------------------------------------------------------------------------------------------------------------
# Print parameters
echo "Home path: $DARTIQ_HOME_PATH"
echo "Workspace path: $WORKSPACE"
echo "Docker image: $IMAGE"
echo "Docker options: $DOCKER_OPTIONS"
# ---------------------------------------------------------------------------------------------------------------------
# Process mounts
if [ -n "$TOOLS_PATH" ]; then
echo "Gateware tools: $TOOLS_PATH"
MOUNTS="$MOUNTS -v $TOOLS_PATH:$TOOLS_PATH:ro"
ENV_VARS="$ENV_VARS -e GATEWARE_TOOLCHAIN_PATH=$TOOLS_PATH/Vivado"
fi
if [ -n "$MIGEN_PATH" ]; then
echo "Migen path: $MIGEN_PATH"
MOUNTS="$MOUNTS -v $MIGEN_PATH:/migen_ext:ro"
fi
if [ -n "$MISOC_PATH" ]; then
echo "MiSOC path: $MISOC_PATH"
MOUNTS="$MOUNTS -v $MISOC_PATH:/misoc_ext:ro"
fi
if [ -n "$ARTIQ_PATH" ]; then
echo "ARTIQ path: $ARTIQ_PATH"
MOUNTS="$MOUNTS -v $ARTIQ_PATH:/artiq_ext:ro"
fi
# ---------------------------------------------------------------------------------------------------------------------
# Add ttyUSB devices
for x in $(find /dev -name ttyUSB* 2>/dev/null)
do
DEVICES="$DEVICES --device=$x"
done
# ---------------------------------------------------------------------------------------------------------------------
# User creation arguments
ENTRYPOINT_ARGS="$ENTRYPOINT_ARGS --uid $(id -u $HOST_USER)"
ENTRYPOINT_ARGS="$ENTRYPOINT_ARGS --user $(id -u -n $HOST_USER)"
ENTRYPOINT_ARGS="$ENTRYPOINT_ARGS --gid $(id -g $HOST_USER)"
ENTRYPOINT_ARGS="$ENTRYPOINT_ARGS --group $(id -g -n $HOST_USER)"
# ---------------------------------------------------------------------------------------------------------------------
# Execute docker
# For debugging
#
docker run -it $DEVICES --privileged \
-e DISPLAY=$DISPLAY \
--net=host \
$MOUNTS \
$MOUNT_TOOLS \
-v $WORKSPACE:/workspace \
-v $DARTIQ_HOME_PATH:/home/user \
$ENV_VARS \
$DOCKER_OPTIONS \
$IMAGE \
$ENTRYPOINT_ARGS \
"${ARGUMENTS_LEFT[@]}"