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