Skip to content

Commit 4add7ee

Browse files
authored
Fix empty docker-compose in basebox (#81)
## Description Ensures docker-compose is correctly downloaded. Also adds some better debuggability to setup.sh and the vagrant provision script. A bunch of misc clean ups following the boy scout rule (leave things better than you found them) ## Why is this needed Fixes: #59 ## How Has This Been Tested? `vagrant up provisioner` now works ## How are existing users impacted? What migration steps/scripts do we need? Fixes a bug where the vagrant sandbox wasn't working. ## Checklist: I have: - [ ] updated the documentation and/or roadmap (if required) - [ ] added unit or e2e tests - [ ] provided instructions on how to upgrade
2 parents 28a2363 + 7e2296d commit 4add7ee

File tree

4 files changed

+95
-79
lines changed

4 files changed

+95
-79
lines changed

deploy/vagrant/basebox/ubuntu1804/provision.sh

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ setup_docker() (
99
ca-certificates \
1010
curl \
1111
gnupg-agent \
12-
software-properties-common
12+
software-properties-common \
13+
;
1314

1415
curl -fsSL https://download.docker.com/linux/ubuntu/gpg |
1516
sudo apt-key add -
@@ -22,16 +23,24 @@ setup_docker() (
2223
sudo add-apt-repository "$repo"
2324

2425
sudo apt-get update
25-
sudo apt-get install -y docker-ce docker-ce-cli containerd.io
26+
sudo apt-get install -y \
27+
containerd.io \
28+
docker-ce \
29+
docker-ce-cli \
30+
;
2631
)
2732

33+
# from https://docs.docker.com/compose/install/
2834
setup_docker_compose() (
29-
# from https://docs.docker.com/compose/install/
30-
sudo curl -L \
31-
"https://github.com/docker/compose/releases/download/1.26.0/docker-compose-$(uname -s)-$(uname -m)" \
32-
-o /usr/local/bin/docker-compose
33-
34-
sudo chmod +x /usr/local/bin/docker-compose
35+
local name url
36+
name=docker-compose-$(uname -s)-$(uname -m)
37+
url=https://github.com/docker/compose/releases/download/1.26.0/$name
38+
curl -fsSLO "$url"
39+
curl -fsSLO "$url.sha256"
40+
sha256sum -c <"$name.sha256"
41+
rm -f "$name.sha256"
42+
chmod +x "$name"
43+
sudo mv "$name" /usr/local/bin/docker-compose
3544
)
3645

3746
main() (
@@ -45,3 +54,4 @@ main() (
4554
)
4655

4756
main
57+
sync # do not remove!

deploy/vagrant/scripts/tinkerbell.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ setup_nat() (
3434
main() (
3535
export DEBIAN_FRONTEND=noninteractive
3636

37-
if [ ! -f ./.env ]; then
37+
if ! [[ -f ./.env ]]; then
3838
./generate-env.sh eth1 >.env
3939
fi
4040

4141
# shellcheck disable=SC1091
42-
. ./.env
42+
source ./.env
4343

4444
make_certs_writable
4545

@@ -51,6 +51,9 @@ main() (
5151

5252
secure_certs
5353
configure_vagrant_user
54+
55+
set +x # don't want the stderr output from xtrace messing with the post-setup-message
56+
[[ -f /tmp/post-setup-message ]] && cat /tmp/post-setup-message
5457
)
5558

5659
main

generate-env.sh

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ ERR="${RED:-}ERROR:${RESET:-}"
1414
source ./current_versions.sh
1515

1616
err() (
17-
if [ -z "${1:-}" ]; then
17+
if [[ -z ${1:-} ]]; then
1818
cat >&2
1919
else
2020
echo "$ERR " "$@" >&2
@@ -53,48 +53,49 @@ generate_env() (
5353
tink_password=$(generate_password)
5454
local registry_password
5555
registry_password=$(generate_password)
56-
cat <<EOF
57-
# Tinkerbell Stack version
58-
59-
export OSIE_DOWNLOAD_LINK=${OSIE_DOWNLOAD_LINK}
60-
export TINKERBELL_TINK_SERVER_IMAGE=${TINKERBELL_TINK_SERVER_IMAGE}
61-
export TINKERBELL_TINK_CLI_IMAGE=${TINKERBELL_TINK_CLI_IMAGE}
62-
export TINKERBELL_TINK_BOOTS_IMAGE=${TINKERBELL_TINK_BOOTS_IMAGE}
63-
export TINKERBELL_TINK_HEGEL_IMAGE=${TINKERBELL_TINK_HEGEL_IMAGE}
64-
export TINKERBELL_TINK_WORKER_IMAGE=${TINKERBELL_TINK_WORKER_IMAGE}
65-
66-
# Network interface for Tinkerbell's network
67-
export TINKERBELL_NETWORK_INTERFACE="$tink_interface"
68-
69-
# Decide on a subnet for provisioning. Tinkerbell should "own" this
70-
# network space. Its subnet should be just large enough to be able
71-
# to provision your hardware.
72-
export TINKERBELL_CIDR=29
73-
74-
# Host IP is used by provisioner to expose different services such as
75-
# tink, boots, etc.
76-
#
77-
# The host IP should the first IP in the range, and the Nginx IP
78-
# should be the second address.
79-
export TINKERBELL_HOST_IP=192.168.1.1
80-
81-
# Tink server username and password
82-
export TINKERBELL_TINK_USERNAME=admin
83-
export TINKERBELL_TINK_PASSWORD="$tink_password"
84-
85-
# Docker Registry's username and password
86-
export TINKERBELL_REGISTRY_USERNAME=admin
87-
export TINKERBELL_REGISTRY_PASSWORD="$registry_password"
88-
89-
# Legacy options, to be deleted:
90-
export FACILITY=onprem
91-
export ROLLBAR_TOKEN=ignored
92-
export ROLLBAR_DISABLE=1
93-
EOF
56+
57+
cat <<-EOF
58+
# Tinkerbell Stack version
59+
60+
export OSIE_DOWNLOAD_LINK=${OSIE_DOWNLOAD_LINK}
61+
export TINKERBELL_TINK_SERVER_IMAGE=${TINKERBELL_TINK_SERVER_IMAGE}
62+
export TINKERBELL_TINK_CLI_IMAGE=${TINKERBELL_TINK_CLI_IMAGE}
63+
export TINKERBELL_TINK_BOOTS_IMAGE=${TINKERBELL_TINK_BOOTS_IMAGE}
64+
export TINKERBELL_TINK_HEGEL_IMAGE=${TINKERBELL_TINK_HEGEL_IMAGE}
65+
export TINKERBELL_TINK_WORKER_IMAGE=${TINKERBELL_TINK_WORKER_IMAGE}
66+
67+
# Network interface for Tinkerbell's network
68+
export TINKERBELL_NETWORK_INTERFACE="$tink_interface"
69+
70+
# Decide on a subnet for provisioning. Tinkerbell should "own" this
71+
# network space. Its subnet should be just large enough to be able
72+
# to provision your hardware.
73+
export TINKERBELL_CIDR=29
74+
75+
# Host IP is used by provisioner to expose different services such as
76+
# tink, boots, etc.
77+
#
78+
# The host IP should the first IP in the range, and the Nginx IP
79+
# should be the second address.
80+
export TINKERBELL_HOST_IP=192.168.1.1
81+
82+
# Tink server username and password
83+
export TINKERBELL_TINK_USERNAME=admin
84+
export TINKERBELL_TINK_PASSWORD="$tink_password"
85+
86+
# Docker Registry's username and password
87+
export TINKERBELL_REGISTRY_USERNAME=admin
88+
export TINKERBELL_REGISTRY_PASSWORD="$registry_password"
89+
90+
# Legacy options, to be deleted:
91+
export FACILITY=onprem
92+
export ROLLBAR_TOKEN=ignored
93+
export ROLLBAR_DISABLE=1
94+
EOF
9495
)
9596

9697
main() (
97-
if [ -z "${1:-}" ]; then
98+
if [[ -z ${1:-} ]]; then
9899
err "Usage: $0 network-interface-name > .env"
99100
exit 1
100101
fi

setup.sh

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
# stops the execution if a command or pipeline has an error
4-
set -eu
4+
set -euxo pipefail
55

66
# Tinkerbell stack Linux setup script
77
#
@@ -38,7 +38,7 @@ NEXT="${GREEN:-}NEXT:${RESET:-}"
3838
get_distribution() (
3939
local lsb_dist=""
4040
# Every system that we officially support has /etc/os-release
41-
if [ -r /etc/os-release ]; then
41+
if [[ -r /etc/os-release ]]; then
4242
# shellcheck disable=SC1091
4343
lsb_dist="$(. /etc/os-release && echo "$ID")"
4444
fi
@@ -50,7 +50,7 @@ get_distribution() (
5050
get_distro_version() (
5151
local lsb_version="0"
5252
# Every system that we officially support has /etc/os-release
53-
if [ -r /etc/os-release ]; then
53+
if [[ -r /etc/os-release ]]; then
5454
# shellcheck disable=SC1091
5555
lsb_version="$(. /etc/os-release && echo "$VERSION_ID")"
5656
fi
@@ -112,10 +112,10 @@ setup_networking() (
112112
fi
113113

114114
NAT_INTERFACE=""
115-
if [ -r .nat_interface ]; then
115+
if [[ -r .nat_interface ]]; then
116116
NAT_INTERFACE=$(cat .nat_interface)
117117
fi
118-
if [ -n "$NAT_INTERFACE" ] && ip addr show "$NAT_INTERFACE" &>/dev/null; then
118+
if [[ -n $NAT_INTERFACE ]] && ip addr show "$NAT_INTERFACE" &>/dev/null; then
119119
# TODO(nshalman) the terraform code would just run these commands as-is once
120120
# but it would be nice to make these more persistent based on OS
121121
iptables -A FORWARD -i "$TINKERBELL_NETWORK_INTERFACE" -o "$NAT_INTERFACE" -j ACCEPT
@@ -135,10 +135,10 @@ setup_networking_manually() (
135135

136136
setup_network_forwarding() (
137137
# enable IP forwarding for docker
138-
if [ "$(sysctl -n net.ipv4.ip_forward)" != "1" ]; then
139-
if [ -d /etc/sysctl.d ]; then
138+
if (($(sysctl -n net.ipv4.ip_forward) != 1)); then
139+
if [[ -d /etc/sysctl.d ]]; then
140140
echo "net.ipv4.ip_forward=1" >/etc/sysctl.d/99-tinkerbell.conf
141-
elif [ -f /etc/sysctl.conf ]; then
141+
elif [[ -f /etc/sysctl.conf ]]; then
142142
echo "net.ipv4.ip_forward=1" >>/etc/sysctl.conf
143143
fi
144144

@@ -171,7 +171,7 @@ setup_networking_netplan() (
171171
)
172172

173173
setup_networking_ubuntu_legacy() (
174-
if [ ! -f /etc/network/interfaces ]; then
174+
if ! [[ -f /etc/network/interfaces ]]; then
175175
echo "$ERR file /etc/network/interfaces not found"
176176
exit 1
177177
fi
@@ -224,7 +224,7 @@ EOF
224224

225225
local cfgfile="/etc/sysconfig/network-scripts/ifcfg-$TINKERBELL_NETWORK_INTERFACE"
226226

227-
if [ -f "$cfgfile" ]; then
227+
if [[ -f $cfgfile ]]; then
228228
echo "$ERR network config already exists: $cfgfile"
229229
echo "$BLANK Please update it to match this configuration:"
230230
echo "$content"
@@ -245,12 +245,12 @@ setup_osie() (
245245

246246
local osie_current=$STATEDIR/webroot/misc/osie/current
247247
local tink_workflow=$STATEDIR/webroot/workflow/
248-
if [ ! -d "$osie_current" ] || [ ! -d "$tink_workflow" ]; then
248+
if [[ ! -d $osie_current ]] || [[ ! -d $tink_workflow ]]; then
249249
mkdir -p "$osie_current"
250250
mkdir -p "$tink_workflow"
251251
pushd "$SCRATCH"
252252

253-
if [ -z "${TB_OSIE_TAR:-}" ]; then
253+
if [[ -z ${TB_OSIE_TAR:-} ]]; then
254254
curl "${OSIE_DOWNLOAD_LINK}" -o ./osie.tar.gz
255255
tar -zxf osie.tar.gz
256256
else
@@ -305,7 +305,7 @@ check_container_status() (
305305
--filter "event=health_status" \
306306
--format '{{.Status}}')
307307

308-
if [ "$status" != "health_status: healthy" ]; then
308+
if [[ $status != "health_status: healthy" ]]; then
309309
echo "$ERR $container_name is not healthy. status: $status"
310310
exit 1
311311
fi
@@ -314,7 +314,7 @@ check_container_status() (
314314
generate_certificates() (
315315
mkdir -p "$STATEDIR/certs"
316316

317-
if [ ! -f "$STATEDIR/certs/ca.json" ]; then
317+
if ! [[ -f "$STATEDIR/certs/ca.json" ]]; then
318318
jq \
319319
'.
320320
| .names[0].L = $facility
@@ -325,7 +325,7 @@ generate_certificates() (
325325
>"$STATEDIR/certs/ca.json"
326326
fi
327327

328-
if [ ! -f "$STATEDIR/certs/server-csr.json" ]; then
328+
if ! [[ -f "$STATEDIR/certs/server-csr.json" ]]; then
329329
jq \
330330
'.
331331
| .hosts += [ $ip, "tinkerbell.\($facility).packet.net" ]
@@ -347,13 +347,13 @@ generate_certificates() (
347347
local certs_dir="/etc/docker/certs.d/$TINKERBELL_HOST_IP"
348348

349349
# copy public key to NGINX for workers
350-
if ! cmp --quiet "$STATEDIR"/certs/ca.pem "$STATEDIR/webroot/workflow/ca.pem"; then
351-
cp "$STATEDIR"/certs/ca.pem "$STATEDIR/webroot/workflow/ca.pem"
350+
if ! cmp --quiet "$STATEDIR/certs/ca.pem" "$STATEDIR/webroot/workflow/ca.pem"; then
351+
cp "$STATEDIR/certs/ca.pem" "$STATEDIR/webroot/workflow/ca.pem"
352352
fi
353353

354354
# update host to trust registry certificate
355355
if ! cmp --quiet "$STATEDIR/certs/ca.pem" "$certs_dir/tinkerbell.crt"; then
356-
if [ ! -d "$certs_dir/tinkerbell.crt" ]; then
356+
if ! [[ -d "$certs_dir/" ]]; then
357357
# The user will be told to create the directory
358358
# in the next block, if copying the certs there
359359
# fails.
@@ -363,7 +363,7 @@ generate_certificates() (
363363
echo "$ERR please copy $STATEDIR/certs/ca.pem to $certs_dir/tinkerbell.crt"
364364
echo "$BLANK and run $0 again:"
365365

366-
if [ ! -d "$certs_dir" ]; then
366+
if ! [[ -d $certs_dir ]]; then
367367
echo "sudo mkdir -p '$certs_dir'"
368368
fi
369369
echo "sudo cp '$STATEDIR/certs/ca.pem' '$certs_dir/tinkerbell.crt'"
@@ -406,7 +406,7 @@ bootstrap_docker_registry() (
406406

407407
setup_docker_registry() (
408408
local registry_images="$STATEDIR/registry"
409-
if [ ! -d "$registry_images" ]; then
409+
if ! [[ -d $registry_images ]]; then
410410
mkdir -p "$registry_images"
411411
fi
412412
start_registry
@@ -427,13 +427,15 @@ command_exists() (
427427
)
428428

429429
check_command() (
430-
if command_exists "$1"; then
431-
echo "$BLANK Found prerequisite: $1"
432-
return 0
433-
else
434-
echo "$ERR Prerequisite command not installed: $1"
430+
if ! command_exists "$1"; then
431+
echo "$ERR Prerequisite executable command not found: $1"
435432
return 1
436433
fi
434+
if ! [[ -s "$(which "$1")" ]]; then
435+
echo "$ERR Prerequisite command is an empty file: $1"
436+
fi
437+
echo "$BLANK Found prerequisite: $1"
438+
return 0
437439
)
438440

439441
check_prerequisites() (
@@ -469,15 +471,15 @@ check_prerequisites() (
469471
;;
470472
esac
471473

472-
if [ $failed -eq 1 ]; then
474+
if ((failed == 1)); then
473475
echo "$ERR Prerequisites not met. Please install the missing commands and re-run $0."
474476
exit 1
475477
fi
476478
)
477479

478480
whats_next() (
479481
echo "$NEXT 1. Enter /vagrant/deploy and run: source ../.env; docker-compose up -d"
480-
echo "$BLANK 2. Try executing your fist workflow."
482+
echo "$BLANK 2. Try executing your first workflow."
481483
echo "$BLANK Follow the steps described in https://tinkerbell.org/examples/hello-world/ to say 'Hello World!' with a workflow."
482484
)
483485

@@ -489,7 +491,7 @@ do_setup() (
489491
echo "$INFO starting tinkerbell stack setup"
490492
check_prerequisites "$lsb_dist" "$lsb_version"
491493

492-
if [ ! -f "$ENV_FILE" ]; then
494+
if ! [[ -f $ENV_FILE ]]; then
493495
echo "$ERR Run './generate-env.sh network-interface > \"$ENV_FILE\"' before continuing."
494496
exit 1
495497
fi
@@ -503,7 +505,7 @@ do_setup() (
503505
setup_docker_registry
504506

505507
echo "$INFO tinkerbell stack setup completed successfully on $lsb_dist server"
506-
whats_next
508+
whats_next | tee /tmp/post-setup-message
507509
)
508510

509511
# wrapped up in a function so that we have some protection against only getting

0 commit comments

Comments
 (0)