Skip to content

Commit

Permalink
ux: Change the way docker runs the container
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich Bayliss committed Mar 5, 2020
1 parent adf4f77 commit acde1be
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 25 deletions.
12 changes: 6 additions & 6 deletions balenaos-in-container.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The config.json path. This you can download from balena.io dashboard.
Mandatory argument.
Alias: -c
.PARAMETER detach
.PARAMETER detached
Run the container in the background and print container ID (just like "docker run -d")
Default: no.
Alias: -d
Expand Down Expand Up @@ -109,7 +109,7 @@ foreach ( $volume in $balena_boot_volume,$balena_state_volume, $balena_data_volu
$container_name="${docker_prefix}container-${docker_postfix}"
echo "INFO: Running balenaOS as container ${container_name} ..."

docker run $no_ttyVal --rm --privileged `
docker run -d -t --rm --privileged `
--stop-timeout=30 `
-e "container=docker" `
--name ${container_name} `
Expand All @@ -121,14 +121,14 @@ docker run $no_ttyVal --rm --privileged `
-v "${balena_state_volume}:/mnt/state" `
-v "${balena_data_volume}:/mnt/data" `
$extra_args `
${detachVal} `
${image} `
sh -c '/aufs2overlay;exec /sbin/init'


if ($LastExitCode -eq 0){
if ($detach -ne ""){
echo "INFO: balenaOS container running as ${container_name}"
echo "INFO: balenaOS container running as ${container_name}"
if ($detached -ne ""){
docker attach ${container_name}
}
}
elseif ($LastExitCode -eq 130 -or $LastExitCode -eq 137) {
Expand All @@ -138,7 +138,7 @@ else{
echo "ERROR: Running docker container."
}

if (!$detach -and $clean_volumes){
if ($clean_volumes){
echo "Cleaning volumes..."
docker volume rm "${balena_boot_volume}" "${balena_state_volume}" "${balena_data_volume}" 2>&1>$null
}
29 changes: 10 additions & 19 deletions balenaos-in-container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ docker_prefix="balena-"
docker_postfix="$RANDOM"
clean_volumes=no
docker_extra_args=""
detach=""
no_tty="-ti"
detached=""

function help {
cat << EOF
Expand All @@ -32,7 +31,7 @@ ARGUMENTS:
-c, --config <config>
The config.json path. This you can download from balena.io dashboard.
Mandatory argument.
-d, --detach
-d, --detached
Run the container in the background and print container ID (just like "docker run -d")
Default: no.
--extra-args <arguments>
Expand All @@ -41,9 +40,6 @@ ARGUMENTS:
If volumes are not planned to be reused, you can take advantage of this
argument to clean up the system. Cannot be used together with -d.
Default: no.
--no-tty
Don't allocate a pseudo-TTY and don't keep STDIN open (docker run without "-it").
Default: no.
EOF
}

Expand Down Expand Up @@ -91,8 +87,8 @@ while [[ $# -ge 1 ]]; do
fi
shift
;;
-d|--detach)
detach="--detach"
-d|--detached)
detached="true"
;;
--extra-args)
docker_extra_args="$2"
Expand Down Expand Up @@ -156,7 +152,7 @@ done
container_name="${docker_prefix}container-${docker_postfix}"
echo "INFO: Running balenaOS as container ${container_name} ..."
#shellcheck disable=SC2086
if docker run $no_tty --rm --privileged \
if docker run -d -t --rm --privileged \
-e "container=docker" \
--stop-timeout=30 \
--dns 127.0.0.2 \
Expand All @@ -169,23 +165,18 @@ if docker run $no_tty --rm --privileged \
-v "${balena_state_volume}:/mnt/state" \
-v "${balena_data_volume}:/mnt/data" \
$docker_extra_args \
$detach \
"$image" \
sh -c '/aufs2overlay;exec /sbin/init'; then
if [ "$detach" != "" ]; then
echo "INFO: balenaOS container running as ${container_name}"

echo "INFO: balenaOS container running as ${container_name}"
if [ "$detached" = "" ]; then
docker attach "${container_name}"
else
echo "ERROR: Running docker container."
fi
else
if [ "$detach" != "" ]; then
echo "ERROR: Running docker container."
else
echo "INFO: balenaOS container stopped."
fi
fi

if [ "$detach" = "" ] && [ "$clean_volumes" = "yes" ]; then
if [ "$clean_volumes" = "yes" ]; then
echo "Cleaning volumes..."
docker volume rm "${balena_boot_volume}" "${balena_state_volume}" "${balena_data_volume}" &> /dev/null
fi

0 comments on commit acde1be

Please sign in to comment.