115 lines
3.7 KiB
Shell
115 lines
3.7 KiB
Shell
|
|
#!/usr/bin/env bash
|
||
|
|
set -euo pipefail
|
||
|
|
|
||
|
|
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
|
||
|
|
source "$ROOT/tests/kind/lib.sh"
|
||
|
|
|
||
|
|
USER_KUBECONFIG_BEFORE="$(user_kubeconfig_digest)"
|
||
|
|
SUCCEEDED=false
|
||
|
|
OWNS_FIXTURE=false
|
||
|
|
APP_IMAGE=nuthatch-wp05:local
|
||
|
|
|
||
|
|
cleanup() {
|
||
|
|
local status=$?
|
||
|
|
trap - EXIT INT TERM
|
||
|
|
if [[ "${NUTHATCH_TESTBED_RETAIN:-0}" = 1 ]] && [[ "$SUCCEEDED" != true ]]; then
|
||
|
|
printf 'retained kubeconfig: %s\n' "$KUBECONFIG_PATH"
|
||
|
|
printf 'retained context: %s\n' "$CONTEXT"
|
||
|
|
exit "$status"
|
||
|
|
fi
|
||
|
|
if [[ "$OWNS_FIXTURE" = true ]]; then
|
||
|
|
destroy_fixture || status=1
|
||
|
|
fi
|
||
|
|
if [[ "$(user_kubeconfig_digest)" != "$USER_KUBECONFIG_BEFORE" ]]; then
|
||
|
|
printf 'user kubeconfig changed unexpectedly\n' >&2
|
||
|
|
status=1
|
||
|
|
fi
|
||
|
|
exit "$status"
|
||
|
|
}
|
||
|
|
|
||
|
|
trap cleanup EXIT
|
||
|
|
trap 'exit 130' INT
|
||
|
|
trap 'exit 143' TERM
|
||
|
|
|
||
|
|
render_application() {
|
||
|
|
local lane="$1"
|
||
|
|
local profile_file="$2"
|
||
|
|
local pg_conn
|
||
|
|
local redis_url
|
||
|
|
local s3_endpoint
|
||
|
|
local s3_region
|
||
|
|
local s3_bucket
|
||
|
|
local s3_access_key
|
||
|
|
local s3_secret_key
|
||
|
|
pg_conn="$(sed -n 's/^NUTHATCH_PG_CONN=//p' "$profile_file")"
|
||
|
|
redis_url="$(sed -n 's/^NUTHATCH_REDIS_URL=//p' "$profile_file")"
|
||
|
|
s3_endpoint="$(sed -n 's/^NUTHATCH_S3_ENDPOINT=//p' "$profile_file")"
|
||
|
|
s3_region="$(sed -n 's/^NUTHATCH_S3_REGION=//p' "$profile_file")"
|
||
|
|
s3_bucket="$(sed -n 's/^NUTHATCH_S3_BUCKET=//p' "$profile_file")"
|
||
|
|
s3_access_key="$(sed -n 's/^NUTHATCH_S3_ACCESS_KEY=//p' "$profile_file")"
|
||
|
|
s3_secret_key="$(sed -n 's/^NUTHATCH_S3_SECRET_KEY=//p' "$profile_file")"
|
||
|
|
sed \
|
||
|
|
-e "s|@@LANE@@|$lane|g" \
|
||
|
|
-e "s|@@APP_IMAGE@@|$APP_IMAGE|g" \
|
||
|
|
-e "s|@@PG_CONN@@|$pg_conn|g" \
|
||
|
|
-e "s|@@REDIS_URL@@|$redis_url|g" \
|
||
|
|
-e "s|@@S3_ENDPOINT@@|$s3_endpoint|g" \
|
||
|
|
-e "s|@@S3_REGION@@|$s3_region|g" \
|
||
|
|
-e "s|@@S3_BUCKET@@|$s3_bucket|g" \
|
||
|
|
-e "s|@@S3_ACCESS_KEY@@|$s3_access_key|g" \
|
||
|
|
-e "s|@@S3_SECRET_KEY@@|$s3_secret_key|g" \
|
||
|
|
"$ROOT/deploy/kubernetes/nuthatch.yaml.in" > "$RUNTIME/wp05-app-$lane.yaml"
|
||
|
|
}
|
||
|
|
|
||
|
|
cleanup_application() {
|
||
|
|
local lane="$1"
|
||
|
|
kube --namespace "$FIXTURE_NAMESPACE" delete \
|
||
|
|
"deployment/nuthatch-$lane" \
|
||
|
|
"service/nuthatch-$lane" \
|
||
|
|
"configmap/nuthatch-$lane" \
|
||
|
|
"secret/nuthatch-$lane" \
|
||
|
|
--ignore-not-found >/dev/null
|
||
|
|
rm -f "$RUNTIME/wp05-app-$lane.yaml"
|
||
|
|
}
|
||
|
|
|
||
|
|
acquire_fixture_lock
|
||
|
|
OWNS_FIXTURE=true
|
||
|
|
setup_fixture durable coordination target
|
||
|
|
source "$RUNTIME/fixture.env"
|
||
|
|
"$NUTHATCH_REAL_NERDCTL" --namespace "$NERDCTL_NAMESPACE" build \
|
||
|
|
--file "$ROOT/Dockerfile" \
|
||
|
|
--tag "$APP_IMAGE" \
|
||
|
|
"$ROOT"
|
||
|
|
load_local_image "$APP_IMAGE" "$NERDCTL_NAMESPACE"
|
||
|
|
|
||
|
|
while IFS=$'\t' read -r lane coordination oidc target; do
|
||
|
|
profile="$(write_lane_profile "$lane" "$coordination" "$oidc" "$target")"
|
||
|
|
render_application "$lane" "$RUNTIME/$profile.env"
|
||
|
|
kube apply --filename "$RUNTIME/wp05-app-$lane.yaml" >/dev/null
|
||
|
|
kube --namespace "$FIXTURE_NAMESPACE" rollout status \
|
||
|
|
"deployment/nuthatch-$lane" --timeout=180s
|
||
|
|
if [[ "${NUTHATCH_APP_INTERACTIVE:-0}" = 1 ]]; then
|
||
|
|
SUCCEEDED=true
|
||
|
|
OWNS_FIXTURE=false
|
||
|
|
printf 'interactive kubeconfig: %s\n' "$KUBECONFIG_PATH"
|
||
|
|
printf 'interactive context: %s\n' "$CONTEXT"
|
||
|
|
printf 'interactive namespace: %s\n' "$FIXTURE_NAMESPACE"
|
||
|
|
printf 'interactive service: nuthatch-%s:8080\n' "$lane"
|
||
|
|
exit 0
|
||
|
|
fi
|
||
|
|
job="wp05-app-$lane"
|
||
|
|
render_lane_job \
|
||
|
|
"$job" \
|
||
|
|
"$TESTBED/wp05-job.yaml.in" \
|
||
|
|
"$CURL_LOCAL_IMAGE" \
|
||
|
|
"$profile"
|
||
|
|
sed -i "s|@@LANE@@|$lane|g" "$RUNTIME/$job.yaml"
|
||
|
|
printf 'Running lane %s: coordination=%s target=%s\n' "$lane" "$coordination" "$target"
|
||
|
|
run_job_manifest "$job" "$RUNTIME/$job.yaml"
|
||
|
|
cleanup_application "$lane"
|
||
|
|
cleanup_lane_state "$lane" "$coordination" "$oidc" "$target"
|
||
|
|
cleanup_lane_resources "$job" "$profile"
|
||
|
|
done < <(expand_fixture_matrix coordination target)
|
||
|
|
|
||
|
|
SUCCEEDED=true
|
||
|
|
printf 'Nuthatch WP-05 app gate passed\n'
|