From f9b7114a6d0fc3e6e81e82ebb265313c3e8b402e Mon Sep 17 00:00:00 2001 From: Stephan D Date: Sat, 8 Nov 2025 02:58:00 +0100 Subject: [PATCH] fx build fix --- ci/prod/compose/fx_ingestor.dockerfile | 1 + ci/prod/compose/fx_oracle.dockerfile | 1 + .../common}/ensure_env_version.sh | 0 .../fx/build.sh => scripts/fx/build-image.sh} | 18 ++- ci/{pipelines => scripts}/fx/deploy.sh | 18 ++- ci/scripts/proto/generate.sh | 112 ++++++++++++++++++ 6 files changed, 144 insertions(+), 6 deletions(-) rename ci/{pipelines/fx => scripts/common}/ensure_env_version.sh (100%) rename ci/{pipelines/fx/build.sh => scripts/fx/build-image.sh} (82%) rename ci/{pipelines => scripts}/fx/deploy.sh (76%) create mode 100755 ci/scripts/proto/generate.sh diff --git a/ci/prod/compose/fx_ingestor.dockerfile b/ci/prod/compose/fx_ingestor.dockerfile index cf5cedf..314aeef 100644 --- a/ci/prod/compose/fx_ingestor.dockerfile +++ b/ci/prod/compose/fx_ingestor.dockerfile @@ -9,6 +9,7 @@ ARG GIT_REV=unknown ARG BUILD_BRANCH=unknown ARG BUILD_DATE=unknown ARG BUILD_USER=ci +ENV GO111MODULE=on WORKDIR /src COPY . . WORKDIR /src/api/fx/ingestor diff --git a/ci/prod/compose/fx_oracle.dockerfile b/ci/prod/compose/fx_oracle.dockerfile index b3033d4..f8ddb56 100644 --- a/ci/prod/compose/fx_oracle.dockerfile +++ b/ci/prod/compose/fx_oracle.dockerfile @@ -9,6 +9,7 @@ ARG GIT_REV=unknown ARG BUILD_BRANCH=unknown ARG BUILD_DATE=unknown ARG BUILD_USER=ci +ENV GO111MODULE=on WORKDIR /src COPY . . WORKDIR /src/api/fx/oracle diff --git a/ci/pipelines/fx/ensure_env_version.sh b/ci/scripts/common/ensure_env_version.sh similarity index 100% rename from ci/pipelines/fx/ensure_env_version.sh rename to ci/scripts/common/ensure_env_version.sh diff --git a/ci/pipelines/fx/build.sh b/ci/scripts/fx/build-image.sh similarity index 82% rename from ci/pipelines/fx/build.sh rename to ci/scripts/fx/build-image.sh index 5f568f3..7971a30 100755 --- a/ci/pipelines/fx/build.sh +++ b/ci/scripts/fx/build-image.sh @@ -5,7 +5,11 @@ if ! set -o pipefail 2>/dev/null; then : fi -sh ci/pipelines/fx/ensure_env_version.sh +REPO_ROOT="$(cd "$(dirname "$0")/../.." && pwd)" +cd "${REPO_ROOT}" + +sh ci/scripts/common/ensure_env_version.sh + normalize_env_file() { file="$1" tmp="${file}.tmp.$$" @@ -28,10 +32,18 @@ load_env_file() { done <"$file" } -normalize_env_file ./ci/prod/.env.runtime +FX_ENV_NAME="${FX_ENV:-prod}" +RUNTIME_ENV_FILE="./ci/${FX_ENV_NAME}/.env.runtime" + +if [ ! -f "${RUNTIME_ENV_FILE}" ]; then + echo "[fx-build] runtime env file not found: ${RUNTIME_ENV_FILE}" >&2 + exit 1 +fi + +normalize_env_file "${RUNTIME_ENV_FILE}" normalize_env_file ./.env.version -load_env_file ./ci/prod/.env.runtime +load_env_file "${RUNTIME_ENV_FILE}" load_env_file ./.env.version REGISTRY_URL="${REGISTRY_URL:?missing REGISTRY_URL}" diff --git a/ci/pipelines/fx/deploy.sh b/ci/scripts/fx/deploy.sh similarity index 76% rename from ci/pipelines/fx/deploy.sh rename to ci/scripts/fx/deploy.sh index afe065d..3104c92 100755 --- a/ci/pipelines/fx/deploy.sh +++ b/ci/scripts/fx/deploy.sh @@ -5,7 +5,11 @@ if ! set -o pipefail 2>/dev/null; then : fi -sh ci/pipelines/fx/ensure_env_version.sh +REPO_ROOT="$(cd "$(dirname "$0")/../.." && pwd)" +cd "${REPO_ROOT}" + +sh ci/scripts/common/ensure_env_version.sh + normalize_env_file() { file="$1" tmp="${file}.tmp.$$" @@ -28,10 +32,18 @@ load_env_file() { done <"$file" } -normalize_env_file ./ci/prod/.env.runtime +FX_ENV_NAME="${FX_ENV:-prod}" +RUNTIME_ENV_FILE="./ci/${FX_ENV_NAME}/.env.runtime" + +if [ ! -f "${RUNTIME_ENV_FILE}" ]; then + echo "[fx-deploy] runtime env file not found: ${RUNTIME_ENV_FILE}" >&2 + exit 1 +fi + +normalize_env_file "${RUNTIME_ENV_FILE}" normalize_env_file ./.env.version -load_env_file ./ci/prod/.env.runtime +load_env_file "${RUNTIME_ENV_FILE}" load_env_file ./.env.version FX_MONGO_SECRET_PATH="${FX_MONGO_SECRET_PATH:?missing FX_MONGO_SECRET_PATH}" diff --git a/ci/scripts/proto/generate.sh b/ci/scripts/proto/generate.sh new file mode 100755 index 0000000..83d37c3 --- /dev/null +++ b/ci/scripts/proto/generate.sh @@ -0,0 +1,112 @@ +#!/usr/bin/env bash + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +REPO_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)" +API_DIR="${REPO_ROOT}/api" +PROTO_DIR="./proto" +PROTOC_BIN="${PROTOC:-protoc}" + +if ! command -v "${PROTOC_BIN}" >/dev/null 2>&1; then + echo "[proto] protoc binary not found" >&2 + exit 1 +fi +if ! command -v protoc-gen-go >/dev/null 2>&1; then + echo "[proto] protoc-gen-go is not installed" >&2 + exit 1 +fi +if ! command -v protoc-gen-go-grpc >/dev/null 2>&1; then + echo "[proto] protoc-gen-go-grpc is not installed" >&2 + exit 1 +fi + +info() { + printf '[proto] %s\n' "$1" +} + +generate_go() { + local out_dir="$1" + shift + mkdir -p "${out_dir}" + "${PROTOC_BIN}" \ + -I="${PROTO_DIR}" \ + --go_out="${out_dir}" \ + --go_opt=paths=source_relative \ + "$@" +} + +generate_go_with_grpc() { + local out_dir="$1" + shift + mkdir -p "${out_dir}" + "${PROTOC_BIN}" \ + -I="${PROTO_DIR}" \ + --go_out="${out_dir}" \ + --go_opt=paths=source_relative \ + --go-grpc_out="${out_dir}" \ + --go-grpc_opt=paths=source_relative \ + "$@" +} + +clean_pb_files() { + local target="$1" + if [ -d "${target}" ]; then + find "${target}" -type f -name '*.pb.go' -delete + fi +} + +cd "${API_DIR}" + +# Messaging / notification protos (top-level files). +mapfile -t messaging_protos < <(find "${PROTO_DIR}" -maxdepth 1 -type f -name '*.proto' | sort) +if [ "${#messaging_protos[@]}" -gt 0 ]; then + info "Compiling messaging protos" + rm -rf ./pkg/messaging/internal/generated + generate_go "./pkg/messaging/internal/generated" "${messaging_protos[@]}" +fi + +# Common shared protos +mapfile -t common_protos < <(find "${PROTO_DIR}/common" -type f -name '*.proto' | sort) +if [ "${#common_protos[@]}" -gt 0 ]; then + info "Compiling common shared protos" + clean_pb_files "./pkg/proto" + generate_go "./pkg/proto" "${common_protos[@]}" +fi + +# Ledger shared protos +if [ -f "${PROTO_DIR}/ledger/v1/ledger.proto" ]; then + info "Compiling ledger protos" + clean_pb_files "./pkg/proto/ledger" + generate_go_with_grpc "./pkg/proto/ledger/v1" "${PROTO_DIR}/ledger/v1/ledger.proto" +fi + +# Oracle shared protos +if [ -f "${PROTO_DIR}/oracle/v1/oracle.proto" ]; then + info "Compiling oracle protos" + clean_pb_files "./pkg/proto/oracle" + generate_go_with_grpc "./pkg/proto/oracle/v1" "${PROTO_DIR}/oracle/v1/oracle.proto" +fi + +# Chain gateway shared protos +if [ -f "${PROTO_DIR}/chain/gateway/v1/gateway.proto" ]; then + info "Compiling chain gateway protos" + clean_pb_files "./pkg/proto/chain/gateway" + generate_go_with_grpc "./pkg/proto/chain/gateway/v1" "${PROTO_DIR}/chain/gateway/v1/gateway.proto" +fi + +# Payments orchestrator shared protos +if [ -f "${PROTO_DIR}/payments/orchestrator/v1/orchestrator.proto" ]; then + info "Compiling payments orchestrator protos" + clean_pb_files "./pkg/proto/payments/orchestrator" + generate_go_with_grpc "./pkg/proto/payments/orchestrator/v1" "${PROTO_DIR}/payments/orchestrator/v1/orchestrator.proto" +fi + +# Billing fees shared protos +if [ -f "${PROTO_DIR}/billing/fees/v1/fees.proto" ]; then + info "Compiling billing fees protos" + clean_pb_files "./pkg/proto/billing/fees" + generate_go_with_grpc "./pkg/proto/billing/fees/v1" "${PROTO_DIR}/billing/fees/v1/fees.proto" +fi + +info "Protobuf generation completed"