@@ -12,89 +12,93 @@ source sdk_lib/sdk_container_common.sh
12
12
arch=" all"
13
13
name=" "
14
14
15
- os_version=" $( get_git_version) "
16
- sdk_version=" $( get_sdk_version_from_versionfile) "
15
+ os_version=$( get_git_version)
16
+ sdk_version=$( get_sdk_version_from_versionfile)
17
17
custom_image=" "
18
- tty=" "
18
+ tty=()
19
19
remove=" "
20
20
cleanup=" "
21
+ mounts=()
21
22
22
23
usage () {
23
24
echo " Usage:"
24
- echo " $0 [-t] [-v <version>] [-V sdk version] [-a arch ] [-n <name> ] [-x <script>] [-C custom-container] [--rm] [container-command]"
25
+ echo " $0 [-t] [-v <version>] [-V <SDK version> ] [-a <amd64|arm64|all> ] [-n <name> ] [-x <script>] [-C < custom-container> ] [--rm] [-U] [-m <src>:<dest>] [< container-command> ]"
25
26
echo " Start an SDK container of a given SDK release version."
26
27
echo " This will create the container if it does not exist, otherwise start the existing container."
27
28
echo " If the container is already running then it will exec into the container."
28
29
echo
29
- echo " container-command - command to be run in the container instead of"
30
+ echo " < container-command> - Command to be run in the container instead of"
30
31
echo " an interactive shell."
31
- echo " -t Attach docker to a TTY (docker -t)"
32
+ echo " -t Attach docker to a TTY (docker -t). "
32
33
echo " -v <version> - Sourcetree (OS image) version to use."
33
34
echo " Defaults to '$os_version ' (current git commit)."
34
35
echo " FLATCAR_VERSION[_ID] in '$sdk_container_common_versionfile '"
35
36
echo " will be updated accordingly."
36
- echo " -V <SDK ver > - SDK version to use. Defaults to '${sdk_version} '"
37
+ echo " -V <SDK version > - SDK version to use. Defaults to '${sdk_version} '"
37
38
echo " (FLATCAR_SDK_VERSION from '$sdk_container_common_versionfile ')."
38
39
echo " -a <amd64|arm64|all> - Target architecture (board support) of the SDK."
39
40
echo " 'all' (the default) contains support for both amd64 and arm64."
40
41
echo " -n <name> - Custom name to use for the container."
41
- echo " --rm Remove container afterwards"
42
+ echo " --rm Remove container afterwards. "
42
43
echo " -x <script> - For each resource generated during build (container etc.)"
43
44
echo " add a cleanup line to <script> which, when run, will free"
44
45
echo " the resource. Useful for CI."
45
- echo " -C - Use an entirely custom container image instead of the SDK's"
46
- echo " $sdk_container_common_registry /flatcar-sdk-[ARCH]:[SDK VERSION]"
46
+ echo " -C <custom-container> - Use an entirely custom container image instead of the SDK's"
47
+ echo " $sdk_container_common_registry /flatcar-sdk-[ARCH]:[SDK VERSION]. "
47
48
echo " Useful for CI."
48
49
echo " -U Do not update the versionfile. Instead, use the version from the versionfile as-is."
50
+ echo " -m <src>:<dest> - Mount local file or directory inside the container."
51
+ echo " Can be specified multiple times."
49
52
echo " -h Print this help."
50
53
echo
51
54
}
52
55
# --
53
56
54
57
update_versionfile=x
55
- while [ 0 -lt $# ] ; do
58
+ while [[ $# -gt 0 ] ] ; do
56
59
case " $1 " in
57
60
-h) usage; exit 0;;
58
61
--help) usage; exit 0;;
59
- -t) tty=" -t " ; shift ;;
60
- -v) os_version=" $2 " ; shift ; shift ;;
61
- -V) sdk_version=" $2 " ; shift ; shift ;;
62
- -a) arch=" $2 " ; shift ; shift ;;
63
- -n) name=" $2 " ; shift ; shift ;;
64
- --rm) remove=true ; shift ;;
65
- -x) cleanup=" $2 " ; shift ; shift ;;
66
- -C) custom_image=" $2 " ; shift ; shift ;;
67
- -U) sdk_version=" $( get_sdk_version_from_versionfile) "
68
- os_version=" $( get_version_from_versionfile) "
62
+ -t) tty=( -t ) ; shift ;;
63
+ -v) os_version=$2 ; shift ; shift ;;
64
+ -V) sdk_version=$2 ; shift ; shift ;;
65
+ -a) arch=$2 ; shift ; shift ;;
66
+ -n) name=$2 ; shift ; shift ;;
67
+ --rm) remove=x ; shift ;;
68
+ -x) cleanup=$2 ; shift ; shift ;;
69
+ -C) custom_image=$2 ; shift ; shift ;;
70
+ -U) sdk_version=$( get_sdk_version_from_versionfile)
71
+ os_version=$( get_version_from_versionfile)
69
72
update_versionfile=
70
73
shift ;;
74
+ -m) mounts+=( -v " $2 " ); shift ; shift ;;
71
75
* ) break ;;
72
76
esac
73
77
done
74
78
75
- if [ -n " $ custom_image" ] ; then
76
- container_image_name=" ${custom_image} "
79
+ if [[ -n ${ custom_image} ] ] ; then
80
+ container_image_name=${custom_image}
77
81
else
78
- docker_sdk_vernum=" $( vernum_to_docker_image_version " ${sdk_version} " ) "
79
- container_image_name=" $sdk_container_common_registry /flatcar-sdk-${arch} :${docker_sdk_vernum} "
82
+ docker_sdk_vernum=$( vernum_to_docker_image_version " ${sdk_version} " )
83
+ container_image_name=" ${ sdk_container_common_registry} /flatcar-sdk-${arch} :${docker_sdk_vernum} "
80
84
fi
81
85
82
86
if [[ -n ${update_versionfile} ]] ; then
83
87
create_versionfile " $sdk_version " " $os_version "
84
88
fi
85
89
86
- if [ -z " $ name" ] ; then
87
- docker_sdk_vernum=" $( vernum_to_docker_image_version " ${sdk_version} " ) "
88
- docker_os_vernum=" $( vernum_to_docker_image_version " ${os_version} " ) "
90
+ if [[ -z ${ name} ] ] ; then
91
+ docker_sdk_vernum=$( vernum_to_docker_image_version " ${sdk_version} " )
92
+ docker_os_vernum=$( vernum_to_docker_image_version " ${os_version} " )
89
93
name=" flatcar-sdk-${arch} -${docker_sdk_vernum} _os-${docker_os_vernum} "
90
94
fi
91
95
92
96
filter=" ^/"
93
97
if " ${is_podman} " ; then
94
- filter=" "
98
+ filter=" "
95
99
fi
96
- stat=" $( $docker ps --all --no-trunc --filter name=" ${filter} $name \$ " --format ' {{.Status}}' \
97
- | cut -f1 -d' ' ) "
100
+ stat=$( call_docker ps --all --no-trunc --filter name=" ${filter}${ name} \$ " --format ' {{.Status}}' \
101
+ | cut -f1 -d' ' )
98
102
99
103
# pass SDK related environment variables and gcloud auth
100
104
# into container
@@ -104,59 +108,67 @@ setup_gsutil
104
108
mkdir -p " __build__/images"
105
109
mkdir -p " sdk_container/.cache/sdks"
106
110
107
- hostname=" ${name: 0: 63} "
108
- hostname=" ${hostname// ./ _} "
111
+ hostname=${name: 0: 63}
112
+ hostname=${hostname// ./ _}
109
113
110
- if [ -n " $ cleanup" ] ; then
111
- echo " $docker container rm -f ' ${name} ' " >> " $ cleanup"
114
+ if [[ -n ${ cleanup} ] ] ; then
115
+ echo " ${docker_a[@] @ Q} container rm -f ${name@ Q} " >> " ${ cleanup} "
112
116
fi
113
117
114
- if [ -z " $ stat" ] ; then
118
+ if [[ -z ${ stat} ] ] ; then
115
119
yell " Creating a new container '$name '"
116
120
117
- gpg_volumes=$( gnupg_ssh_gcloud_mount_opts)
121
+ gpg_volumes=()
122
+ gnupg_ssh_gcloud_mount_opts gpg_volumes
118
123
119
- if [ -z " $ custom_image" ]; then
120
- (
124
+ if [[ -z ${ custom_image} ] ]; then
125
+ (
121
126
source ci-automation/ci_automation_common.sh
122
127
docker_image_from_registry_or_buildcache " flatcar-sdk-${arch} " " ${docker_sdk_vernum} "
123
- )
128
+ )
124
129
else
125
130
# We could split the container_image_name in parts to call docker_image_from_registry_or_buildcache
126
131
# bur for now just try to ensure that we use the latest image if using a container registry,
127
132
# for the tar-ball-imported images we rely on the ci-automation scripts to call
128
133
# docker_image_from_registry_or_buildcache explicitly.
129
- $docker pull " ${container_image_name} " || true
134
+ call_docker pull " ${container_image_name} " || true
130
135
fi
131
136
132
- $docker create $tty -i \
133
- -v /dev:/dev \
134
- -v " $( pwd) /sdk_container:/mnt/host/source/" \
135
- -v " $( pwd) /__build__/images:/mnt/host/source/src/build" \
136
- -v " $( pwd) :/mnt/host/source/src/scripts" \
137
- $gpg_volumes \
138
- --privileged \
139
- --network host \
140
- -e SDK_USER_ID=" $( id -u) " \
141
- -e SDK_GROUP_ID=" $( id -g) " \
142
- --name=" $name " \
143
- --hostname=" $hostname " \
144
- --entrypoint /bin/bash \
145
- " ${container_image_name} " -l
137
+ docker_flags=(
138
+ " ${tty[@]} "
139
+ -i
140
+ -v /dev:/dev
141
+ -v " ${PWD} /sdk_container:/mnt/host/source/"
142
+ -v " ${PWD} /__build__/images:/mnt/host/source/src/build"
143
+ -v " ${PWD} :/mnt/host/source/src/scripts"
144
+ " ${gpg_volumes[@]} "
145
+ " ${mounts[@]} "
146
+ --privileged
147
+ --network host
148
+ -e SDK_USER_ID=" $( id -u) "
149
+ -e SDK_GROUP_ID=" $( id -g) "
150
+ --name=" ${name} "
151
+ --hostname=" ${hostname} "
152
+ --entrypoint /bin/bash
153
+ " ${container_image_name} "
154
+ -l
155
+ )
156
+
157
+ call_docker create " ${docker_flags[@]} "
146
158
fi
147
159
148
- if [ " $ stat" != " Up" ] ; then
160
+ if [[ ${ stat} != " Up" ] ] ; then
149
161
yell " Starting stopped container '$name '"
150
- if [ " ${remove} " = " true " ]; then
151
- remove_command=" $docker rm -f $name "
162
+ if [[ -n ${remove} ] ]; then
163
+ remove_command=" call_docker rm -f ${ name@ Q} "
152
164
else
153
165
remove_command=" :"
154
166
fi
155
- trap " $docker stop -t 0 $name ; ${remove_command} " EXIT
156
- $docker start " $name "
167
+ trap " call_docker stop -t 0 ${ name@ Q} ; ${remove_command} " EXIT
168
+ call_docker start " ${ name} "
157
169
fi
158
170
159
171
# Workaround: The SDK expects to be able to write to /etc/hosts
160
- $docker exec " $name " sh -c ' cp /etc/hosts /etc/hosts2; umount /etc/hosts ; mv /etc/hosts2 /etc/hosts'
172
+ call_docker exec " ${ name} " sh -c ' cp /etc/hosts /etc/hosts2; umount /etc/hosts ; mv /etc/hosts2 /etc/hosts'
161
173
162
- $docker exec $ tty -i " $name " /mnt/host/source/src/scripts/sdk_lib/sdk_entry.sh " $@ "
174
+ call_docker exec " ${ tty[@]} " -i " ${ name} " /mnt/host/source/src/scripts/sdk_lib/sdk_entry.sh " $@ "
0 commit comments