Skip to content

Commit 4e544e1

Browse files
Move all glue scripts to bash:
By using `/usr/bin/env sh` I needed to ignore some shell checks. By moving to bash, those shell checks can be re-enabled. Signed-off-by: Jacob Weinstock <[email protected]>
1 parent 0ff1d63 commit 4e544e1

File tree

8 files changed

+54
-16
lines changed

8 files changed

+54
-16
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ The following docs will help you get started.
4444
docker exec -i compose_tink-cli_1 tink workflow create -t <TEMPLATE ID> -r '{"device_1":"08:00:27:00:00:01"}')
4545
```
4646

47-
4. Restart the machine to provision (if using the vagrant sandbox test machine this is done by running vagrant destroy -f machine1 && vagrant up machine1
47+
4. Restart the machine to provision (if using the vagrant sandbox test machine this is done by running `vagrant destroy -f machine1 && vagrant up machine1`)

deploy/compose/docker-compose.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ services:
2727

2828
# OSIE work
2929
osie-work:
30-
image: alpine
30+
image: bash:4.4
3131
entrypoint: /scripts/lastmile.sh
3232
command:
3333
[
@@ -76,7 +76,7 @@ services:
7676
# Create hardware, template, and workflow records in tink-server
7777
create-tink-records:
7878
image: ${TINK_CLI_IMAGE}
79-
entrypoint: /manifests/apply_manifests.sh
79+
entrypoint: /manifests/exec_in_bash.sh
8080
command:
8181
[
8282
"$TINKERBELL_HARDWARE_MANIFEST",
@@ -87,6 +87,7 @@ services:
8787
"$TINKERBELL_CLIENT_MAC",
8888
]
8989
environment:
90+
GLUE_SCRIPT_NAME: "/manifests/apply_manifests.sh"
9091
TINKERBELL_GRPC_AUTHORITY: tink-server:42113
9192
TINKERBELL_CERT_URL: http://tink-server:42114/cert
9293
volumes:

deploy/compose/manifests/apply_manifests.sh

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
#!/usr/bin/env sh
2-
# shellcheck disable=SC2039,SC2155,SC2086
1+
#!/usr/bin/env bash
2+
# This script is used to push (hardware) and create (template, workflow) Tink Server data/objects
3+
# This script assumes that the `tink` binary is in the PATH and
4+
# TINKERBELL_CERT_URL and TINKERBELL_GRPC_AUTHORITY environment variables are set
5+
# See https://docs.tinkerbell.org/services/tink-cli/ for more details
36

47
set -xo pipefail
58

@@ -40,11 +43,13 @@ template() {
4043
workflow() {
4144
local workflow_dir="$1"
4245
local mac_address="$2"
43-
local mac=$(echo "${mac_address}" | tr '[:upper:]' '[:lower:]')
44-
local template_id=$(tink template get --no-headers 2>/dev/null | grep -v "+" | cut -d" " -f2 | xargs)
45-
tink workflow create --template "${template_id}" --hardware "{\"device_1\":\"${mac}\"}" | tee "${workflow_dir}"/workflow_id.txt
46+
local mac
47+
mac=$(echo "${mac_address}" | tr '[:upper:]' '[:lower:]')
48+
local template_id
49+
template_id=$(tink template get --no-headers 2>/dev/null | grep -v "+" | cut -d" " -f2 | xargs)
50+
tink workflow create --template "${template_id}" --hardware "{\"device_1\":\"${mac}\"}" | tee "${workflow_dir}/workflow_id.txt"
4651
# write just the workflow id to a file. `|| true` is a failsafe in case the workflow creation fails
47-
sed -i 's/Created Workflow: //g' ${workflow_dir}/workflow_id.txt || true
52+
sed -i 's/Created Workflow: //g' "${workflow_dir}/workflow_id.txt" || true
4853
}
4954

5055
# workflow_exists checks if a workflow record exists in tink before creating a new one
@@ -55,7 +60,8 @@ workflow_exists() {
5560
workflow "${workflow_dir}" "${mac_address}"
5661
return 0
5762
fi
58-
local workflow_id=$(cat "${workflow_dir}"/workflow_id.txt)
63+
local workflow_id
64+
workflow_id=$(cat "${workflow_dir}"/workflow_id.txt)
5965
if [ -z "${workflow_id}" ]; then
6066
workflow "${workflow_dir}" "${mac_address}"
6167
return 0
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env sh
2+
# This script is needed because we prefer bash scripts but
3+
# the pre-built tink-worker container image is alpine and does not
4+
# have bash naively installed.
5+
6+
set -x
7+
8+
# install_bash install bash, needed when running this script in an Alpine container, like tink-worker image
9+
install_bash() {
10+
apk update
11+
apk add bash
12+
}
13+
14+
# main runs the functions
15+
main() {
16+
install_bash
17+
bash "${GLUE_SCRIPT_NAME}" "$@"
18+
}
19+
20+
main "$@"

deploy/compose/osie/lastmile.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#!/usr/bin/env sh
2-
# shellcheck disable=SC2039
1+
#!/usr/bin/env bash
2+
# This script handles downloading, extracting, and copying/moving files in place
3+
# for OSIE and Hook. For more info on OSIE and Hook, see: https://docs.tinkerbell.org/services/osie/
34

45
set -xo pipefail
56

deploy/compose/registry/upload.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env bash
2-
# shellcheck disable=SC2001,SC2155,SC2046
2+
# This script handles uploading containers from one container registry to another.
3+
# It assumes the target registry requires username and password authentication.
34

45
set -xo pipefail
56

@@ -11,8 +12,10 @@ main() {
1112
# this confusing IFS= and the || is to capture the last line of the file if there is no newline at the end
1213
while IFS= read -r img || [ -n "${img}" ]; do
1314
# file is expected to have src and dst images delimited by a space
14-
local src_img="$(echo "${img}" | cut -d' ' -f1)"
15-
local dst_img="$(echo "${img}" | cut -d' ' -f2)"
15+
local src_img
16+
src_img="$(echo "${img}" | cut -d' ' -f1)"
17+
local dst_img
18+
dst_img="$(echo "${img}" | cut -d' ' -f2)"
1619
skopeo copy --all --dest-tls-verify=false --dest-creds="${reg_user}":"${reg_pw}" docker://"${src_img}" docker://"${reg_url}"/"${dst_img}"
1720
done <"${images_file}"
1821
}

deploy/compose/tls/generate.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
#!/usr/bin/env bash
2+
# This script handles the generation of the TLS certificates.
3+
# The output is 2 files:
4+
# 1. /certs/${FACILITY:-onprem}/server-key.pem (TLS private key)
5+
# 2. /certs/${FACILITY:-onprem}/bundle.pem (TLS public certificate)
26

37
set -xo pipefail
48

5-
# update_csr will add the sans_ip to the csr
9+
# update_csr will add the sans_ip, as a valid host domain in the csr
610
update_csr() {
711
local sans_ip="$1"
812
local csr_file="$2"

deploy/compose/ubuntu/setup_ubuntu.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#!/usr/bin/env bash
2+
# This script is designed to download a cloud image file (.img) and then convert it to a .raw file.
3+
# This is purpose built for the Ubuntu Cloud image https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img
4+
# so that the .raw file can be used in the Tinkerbell action "image2disk": https://artifacthub.io/packages/tbaction/tinkerbell-community/image2disk
25

36
set -xo pipefail
47

0 commit comments

Comments
 (0)