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 <jakobweinstock@gmail.com>
This commit is contained in:
parent
0ff1d633cd
commit
b3726acedf
@ -44,4 +44,4 @@ The following docs will help you get started.
|
||||
docker exec -i compose_tink-cli_1 tink workflow create -t <TEMPLATE ID> -r '{"device_1":"08:00:27:00:00:01"}')
|
||||
```
|
||||
|
||||
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
|
||||
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`)
|
||||
|
@ -27,7 +27,7 @@ services:
|
||||
|
||||
# OSIE work
|
||||
osie-work:
|
||||
image: alpine
|
||||
image: bash:4.4
|
||||
entrypoint: /scripts/lastmile.sh
|
||||
command:
|
||||
[
|
||||
@ -76,7 +76,7 @@ services:
|
||||
# Create hardware, template, and workflow records in tink-server
|
||||
create-tink-records:
|
||||
image: ${TINK_CLI_IMAGE}
|
||||
entrypoint: /manifests/apply_manifests.sh
|
||||
entrypoint: /manifests/exec_in_bash.sh
|
||||
command:
|
||||
[
|
||||
"$TINKERBELL_HARDWARE_MANIFEST",
|
||||
@ -87,6 +87,7 @@ services:
|
||||
"$TINKERBELL_CLIENT_MAC",
|
||||
]
|
||||
environment:
|
||||
GLUE_SCRIPT_NAME: "/manifests/apply_manifests.sh"
|
||||
TINKERBELL_GRPC_AUTHORITY: tink-server:42113
|
||||
TINKERBELL_CERT_URL: http://tink-server:42114/cert
|
||||
volumes:
|
||||
|
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env sh
|
||||
# shellcheck disable=SC2039,SC2155,SC2086
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -xo pipefail
|
||||
|
||||
@ -40,11 +39,13 @@ template() {
|
||||
workflow() {
|
||||
local workflow_dir="$1"
|
||||
local mac_address="$2"
|
||||
local mac=$(echo "${mac_address}" | tr '[:upper:]' '[:lower:]')
|
||||
local template_id=$(tink template get --no-headers 2>/dev/null | grep -v "+" | cut -d" " -f2 | xargs)
|
||||
tink workflow create --template "${template_id}" --hardware "{\"device_1\":\"${mac}\"}" | tee "${workflow_dir}"/workflow_id.txt
|
||||
local mac
|
||||
mac=$(echo "${mac_address}" | tr '[:upper:]' '[:lower:]')
|
||||
local template_id
|
||||
template_id=$(tink template get --no-headers 2>/dev/null | grep -v "+" | cut -d" " -f2 | xargs)
|
||||
tink workflow create --template "${template_id}" --hardware "{\"device_1\":\"${mac}\"}" | tee "${workflow_dir}/workflow_id.txt"
|
||||
# write just the workflow id to a file. `|| true` is a failsafe in case the workflow creation fails
|
||||
sed -i 's/Created Workflow: //g' ${workflow_dir}/workflow_id.txt || true
|
||||
sed -i 's/Created Workflow: //g' "${workflow_dir}/workflow_id.txt" || true
|
||||
}
|
||||
|
||||
# workflow_exists checks if a workflow record exists in tink before creating a new one
|
||||
@ -55,7 +56,8 @@ workflow_exists() {
|
||||
workflow "${workflow_dir}" "${mac_address}"
|
||||
return 0
|
||||
fi
|
||||
local workflow_id=$(cat "${workflow_dir}"/workflow_id.txt)
|
||||
local workflow_id
|
||||
workflow_id=$(cat "${workflow_dir}"/workflow_id.txt)
|
||||
if [ -z "${workflow_id}" ]; then
|
||||
workflow "${workflow_dir}" "${mac_address}"
|
||||
return 0
|
||||
|
20
deploy/compose/manifests/exec_in_bash.sh
Executable file
20
deploy/compose/manifests/exec_in_bash.sh
Executable file
@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env sh
|
||||
# This script is needed because we prefer bash scripts but
|
||||
# the pre-built tink-worker container image is alpine and does not
|
||||
# have bash naively installed.
|
||||
|
||||
set -x
|
||||
|
||||
# install_bash install bash, needed when running this script in an Alpine container, like tink-worker image
|
||||
install_bash() {
|
||||
apk update
|
||||
apk add bash
|
||||
}
|
||||
|
||||
# main runs the functions
|
||||
main() {
|
||||
install_bash
|
||||
bash "${GLUE_SCRIPT_NAME}" "$@"
|
||||
}
|
||||
|
||||
main "$@"
|
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env sh
|
||||
# shellcheck disable=SC2039
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -xo pipefail
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user