Files
tf_provider/devops/02_generate_resources_and_docs_v2.sh
T
“Naeel” 612aa53caf api-gateway: migrate YAML gen + provider core from deck-api (?endpoint=) to lk-api-gateway (REST paths)
- service_spec_gen: callAPI() auto-detects proxy vs REST mode by index.cfm presence
- core/client.go: buildURL() replaces all 4 ?endpoint= harcoded sites
- build-provider.sh: -ldflags -X main.version=${VERSION} for correct binary version
- 01_generate_yamls.sh (devops + root): Python auto-detect proxy vs REST
- 02_generate_resources_and_docs_v2.sh: pass -api-endpoint to doc generators
- 04_build_and_publish_docs.sh: normalize_api_endpoint without forced /index.cfm
- docs_template_gen + v2: -api-endpoint flag, hardcoded deck-api replaced
- provider.go (both): TODO(api-gateway) comments
- profiles/test/profile.env: NUBES_API_ENDPOINT -> lk-api-gateway-test
- HISTORY: 2026-07-02_api_gateway_migration.md
2026-07-02 12:40:47 +04:00

109 lines
3.3 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# Canonical resources+docs generator (template format).
# Restores instruction-style docs structure (manual/example/params_create/params_modify/outputs/ops/params landing).
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT_DIR="${ROOT_DIR:-$(cd "${SCRIPT_DIR}/.." && pwd)}"
PROVIDER_DIR="${ROOT_DIR}/universal_rebuild"
PROFILE_DIR="${PROFILE_DIR:-}"
resolve_root_path() {
local path_value="$1"
if [[ -z "$path_value" ]]; then
echo ""
return
fi
if [[ "$path_value" = /* ]]; then
echo "$path_value"
return
fi
echo "${ROOT_DIR}/${path_value}"
}
if [[ "${1:-}" == "--profile" ]]; then
PROFILE_DIR="${2:-}"
shift 2
fi
if [[ -n "$PROFILE_DIR" ]]; then
if [[ ! -d "$PROFILE_DIR" ]]; then
echo "Error: profile directory not found: $PROFILE_DIR" >&2
exit 2
fi
PROFILE_ENV_FILE="${PROFILE_DIR}/profile.env"
if [[ -f "$PROFILE_ENV_FILE" ]]; then
set -a
# shellcheck disable=SC1090
source "$PROFILE_ENV_FILE"
set +a
fi
fi
if [[ -z "$PROFILE_DIR" ]]; then
echo "Error: --profile <path> is required. Strict mode stores generated files per stand only." >&2
exit 2
fi
PROFILE_DIR="$(resolve_root_path "$PROFILE_DIR")"
RESOURCES_YAML_DIR_DEFAULT="${PROFILE_DIR}/generated/resources_yaml"
DOCS_DIR_DEFAULT="${PROFILE_DIR}/generated/docs"
SERVICES_LIST_PATH_DEFAULT="${PROFILE_DIR}/services_list.txt"
GO_OUTPUT_DIR_DEFAULT="${PROFILE_DIR}/generated/go"
RESOURCES_YAML_DIR="${RESOURCES_YAML_DIR:-$RESOURCES_YAML_DIR_DEFAULT}"
DOCS_DIR="${DOCS_DIR:-$DOCS_DIR_DEFAULT}"
SERVICES_LIST_PATH="${SERVICES_LIST_PATH:-$SERVICES_LIST_PATH_DEFAULT}"
GO_OUTPUT_DIR="${GO_OUTPUT_DIR:-$GO_OUTPUT_DIR_DEFAULT}"
RESOURCES_YAML_DIR="$(resolve_root_path "$RESOURCES_YAML_DIR")"
DOCS_DIR="$(resolve_root_path "$DOCS_DIR")"
SERVICES_LIST_PATH="$(resolve_root_path "$SERVICES_LIST_PATH")"
GO_OUTPUT_DIR="$(resolve_root_path "$GO_OUTPUT_DIR")"
if [[ ! -d "$RESOURCES_YAML_DIR" ]]; then
echo "Error: resources yaml directory not found: $RESOURCES_YAML_DIR" >&2
exit 2
fi
if [[ ! -f "$SERVICES_LIST_PATH" ]]; then
echo "Error: services list not found: $SERVICES_LIST_PATH" >&2
exit 2
fi
cd "$PROVIDER_DIR"
echo "Generating resources from unified YAML specs..."
TMP_GEN_DIR="$(mktemp -d)"
trap 'rm -rf "$TMP_GEN_DIR"' EXIT
NUBES_RESOURCES_DIR="$RESOURCES_YAML_DIR" \
NUBES_RESOURCES_GEN_DIR="$TMP_GEN_DIR" \
go run ./tools/gen_v2
mkdir -p "$GO_OUTPUT_DIR"
rm -rf "${GO_OUTPUT_DIR}"/*
cp -R "$TMP_GEN_DIR/." "$GO_OUTPUT_DIR/"
echo "Generating docs via template generator..."
mkdir -p "$DOCS_DIR"
# Determine API endpoint for doc examples.
# Use NUBES_API_ENDPOINT from profile.env, fall back to production default.
DOCS_API_ENDPOINT="${NUBES_API_ENDPOINT:-https://deck-api.ngcloud.ru/api/v1/index.cfm}"
# If endpoint looks like new REST gateway (no index.cfm), keep as-is.
# If it's old-style without index.cfm, append it for backward compat in docs.
if [[ "$DOCS_API_ENDPOINT" != *"/index.cfm"* ]] && [[ "$DOCS_API_ENDPOINT" != *"/svc"* ]]; then
DOCS_API_ENDPOINT="${DOCS_API_ENDPOINT%/}/index.cfm"
fi
go run ./tools/docs_template_gen_v2 \
-resources "$RESOURCES_YAML_DIR" \
-docs "$DOCS_DIR" \
-services "$SERVICES_LIST_PATH" \
-api-endpoint "$DOCS_API_ENDPOINT"
echo "Resources and docs generated in template format."