separated quotation and payments

This commit is contained in:
Stephan D
2026-02-10 18:29:47 +01:00
parent 6745bc0f6f
commit 296cc7b86a
163 changed files with 13516 additions and 191 deletions

View File

@@ -17,6 +17,7 @@ RUN bash ci/scripts/proto/generate.sh
# Copy service dependencies (needed for go.mod replace directives)
COPY api/ledger ./api/ledger
COPY api/payments/orchestrator ./api/payments/orchestrator
COPY api/payments/storage ./api/payments/storage
COPY api/gateway/tron ./api/gateway/tron
COPY api/billing/fees ./api/billing/fees
COPY api/fx/oracle ./api/fx/oracle
@@ -38,6 +39,7 @@ COPY --from=builder /src/api/pkg ./api/pkg
# Copy service dependencies
COPY --from=builder /src/api/ledger ./api/ledger
COPY --from=builder /src/api/payments/orchestrator ./api/payments/orchestrator
COPY --from=builder /src/api/payments/storage ./api/payments/storage
COPY --from=builder /src/api/gateway/tron ./api/gateway/tron
COPY --from=builder /src/api/billing/fees ./api/billing/fees
COPY --from=builder /src/api/fx/oracle ./api/fx/oracle

View File

@@ -15,6 +15,7 @@ COPY ci/scripts/proto/generate.sh ./ci/scripts/proto/
RUN bash ci/scripts/proto/generate.sh
# Copy service dependencies (needed for go.mod replace directives)
COPY api/payments/storage ./api/payments/storage
COPY api/ledger ./api/ledger
COPY api/billing/fees ./api/billing/fees
COPY api/fx/oracle ./api/fx/oracle
@@ -35,6 +36,7 @@ COPY --from=builder /src/api/proto ./api/proto
COPY --from=builder /src/api/pkg ./api/pkg
# Copy service dependencies
COPY --from=builder /src/api/payments/storage ./api/payments/storage
COPY --from=builder /src/api/ledger ./api/ledger
COPY --from=builder /src/api/billing/fees ./api/billing/fees
COPY --from=builder /src/api/fx/oracle ./api/fx/oracle

View File

@@ -0,0 +1,52 @@
# Development Dockerfile for Payments Quotation Service with Air hot reload
FROM golang:alpine AS builder
RUN apk add --no-cache bash git build-base protoc protobuf-dev && \
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest && \
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest && \
go install github.com/air-verse/air@latest
WORKDIR /src
COPY api/proto ./api/proto
COPY api/pkg ./api/pkg
COPY ci/scripts/proto/generate.sh ./ci/scripts/proto/
RUN bash ci/scripts/proto/generate.sh
# Copy service dependencies (needed for go.mod replace directives)
COPY api/payments/storage ./api/payments/storage
COPY api/ledger ./api/ledger
COPY api/billing/fees ./api/billing/fees
COPY api/fx/oracle ./api/fx/oracle
COPY api/fx/storage ./api/fx/storage
COPY api/gateway/chain ./api/gateway/chain
COPY api/gateway/mntx ./api/gateway/mntx
# Runtime stage for development with Air
FROM golang:alpine
RUN apk add --no-cache bash git build-base && \
go install github.com/air-verse/air@latest
WORKDIR /src
# Copy generated proto and pkg from builder
COPY --from=builder /src/api/proto ./api/proto
COPY --from=builder /src/api/pkg ./api/pkg
# Copy service dependencies
COPY --from=builder /src/api/payments/storage ./api/payments/storage
COPY --from=builder /src/api/ledger ./api/ledger
COPY --from=builder /src/api/billing/fees ./api/billing/fees
COPY --from=builder /src/api/fx/oracle ./api/fx/oracle
COPY --from=builder /src/api/fx/storage ./api/fx/storage
COPY --from=builder /src/api/gateway/chain ./api/gateway/chain
COPY --from=builder /src/api/gateway/mntx ./api/gateway/mntx
# Source code will be mounted at runtime
WORKDIR /src/api/payments/quotation
EXPOSE 50064 9414
CMD ["air", "-c", ".air.toml", "--", "-config.file", "/app/config.yml", "-debug"]

View File

@@ -141,6 +141,13 @@ PAYMENTS_SERVICE_NAME=sendico_payments_orchestrator
PAYMENTS_GRPC_PORT=50062
PAYMENTS_METRICS_PORT=9403
# Payments quotation stack
PAYMENTS_QUOTATION_DIR=payments_quotation
PAYMENTS_QUOTATION_COMPOSE_PROJECT=sendico-payments-quotation
PAYMENTS_QUOTATION_SERVICE_NAME=sendico_payments_quotation
PAYMENTS_QUOTATION_GRPC_PORT=50064
PAYMENTS_QUOTATION_METRICS_PORT=9414
# Payments orchestrator Mongo settings
PAYMENTS_MONGO_HOST=sendico_db1
PAYMENTS_MONGO_PORT=27017
@@ -212,4 +219,4 @@ TRON_GATEWAY_MONGO_HOST=sendico_db1
TRON_GATEWAY_MONGO_PORT=27017
TRON_GATEWAY_MONGO_DATABASE=tron_gateway
TRON_GATEWAY_MONGO_AUTH_SOURCE=admin
TRON_GATEWAY_MONGO_REPLICA_SET=sendico-rs
TRON_GATEWAY_MONGO_REPLICA_SET=sendico-rs

View File

@@ -32,6 +32,7 @@ services:
CHAIN_GATEWAY_ADDRESS: ${CHAIN_GATEWAY_SERVICE_NAME}:${CHAIN_GATEWAY_GRPC_PORT}
LEDGER_ADDRESS: ${LEDGER_SERVICE_NAME}:${LEDGER_GRPC_PORT}
PAYMENTS_ADDRESS: ${PAYMENTS_SERVICE_NAME}:${PAYMENTS_GRPC_PORT}
PAYMENTS_QUOTE_ADDRESS: ${PAYMENTS_QUOTATION_SERVICE_NAME}:${PAYMENTS_QUOTATION_GRPC_PORT}
MONGO_HOST: ${MONGO_HOST}
MONGO_PORT: ${MONGO_PORT}
MONGO_DATABASE: ${MONGO_DATABASE}

View File

@@ -0,0 +1,40 @@
# syntax=docker/dockerfile:1.7
ARG TARGETOS=linux
ARG TARGETARCH=amd64
FROM golang:alpine AS build
ARG APP_VERSION=dev
ARG GIT_REV=unknown
ARG BUILD_BRANCH=unknown
ARG BUILD_DATE=unknown
ARG BUILD_USER=ci
ENV GO111MODULE=on
ENV PATH="/go/bin:${PATH}"
WORKDIR /src
COPY . .
RUN apk add --no-cache bash git build-base protoc protobuf-dev \
&& go install google.golang.org/protobuf/cmd/protoc-gen-go@latest \
&& go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest \
&& bash ci/scripts/proto/generate.sh
WORKDIR /src/api/payments/quotation
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
go build -trimpath -ldflags "\
-s -w \
-X github.com/tech/sendico/payments/quotation/internal/appversion.Version=${APP_VERSION} \
-X github.com/tech/sendico/payments/quotation/internal/appversion.Revision=${GIT_REV} \
-X github.com/tech/sendico/payments/quotation/internal/appversion.Branch=${BUILD_BRANCH} \
-X github.com/tech/sendico/payments/quotation/internal/appversion.BuildUser=${BUILD_USER} \
-X github.com/tech/sendico/payments/quotation/internal/appversion.BuildDate=${BUILD_DATE}" \
-o /out/payments-quotation .
FROM alpine:latest AS runtime
RUN apk add --no-cache ca-certificates tzdata wget
WORKDIR /app
COPY api/payments/quotation/config.yml /app/config.yml
COPY --from=build /out/payments-quotation /app/payments-quotation
EXPOSE 50064 9414
ENTRYPOINT ["/app/payments-quotation"]
CMD ["--config.file", "/app/config.yml"]

View File

@@ -0,0 +1,47 @@
# Compose v2 - Payments Quotation
x-common-env: &common-env
env_file:
- ../env/.env.runtime
- ../env/.env.version
networks:
sendico-net:
external: true
name: sendico-net
services:
sendico_payments_quotation:
<<: *common-env
container_name: sendico-payments-quotation
restart: unless-stopped
image: ${REGISTRY_URL}/payments/quotation:${APP_V}
pull_policy: always
environment:
PAYMENTS_MONGO_HOST: ${PAYMENTS_MONGO_HOST}
PAYMENTS_MONGO_PORT: ${PAYMENTS_MONGO_PORT}
PAYMENTS_MONGO_DATABASE: ${PAYMENTS_MONGO_DATABASE}
PAYMENTS_MONGO_USER: ${PAYMENTS_MONGO_USER}
PAYMENTS_MONGO_PASSWORD: ${PAYMENTS_MONGO_PASSWORD}
PAYMENTS_MONGO_AUTH_SOURCE: ${PAYMENTS_MONGO_AUTH_SOURCE}
PAYMENTS_MONGO_REPLICA_SET: ${PAYMENTS_MONGO_REPLICA_SET}
NATS_URL: ${NATS_URL}
NATS_HOST: ${NATS_HOST}
NATS_PORT: ${NATS_PORT}
NATS_USER: ${NATS_USER}
NATS_PASSWORD: ${NATS_PASSWORD}
FEES_ADDRESS: ${FEES_SERVICE_NAME}:${FEES_GRPC_PORT}
ORACLE_ADDRESS: ${FX_ORACLE_SERVICE_NAME}:${FX_ORACLE_GRPC_PORT}
CHAIN_GATEWAY_ADDRESS: ${CHAIN_GATEWAY_SERVICE_NAME}:${CHAIN_GATEWAY_GRPC_PORT}
command: ["--config.file", "/app/config.yml"]
ports:
- "0.0.0.0:${PAYMENTS_QUOTATION_GRPC_PORT}:50064"
- "0.0.0.0:${PAYMENTS_QUOTATION_METRICS_PORT}:9414"
healthcheck:
test: ["CMD-SHELL","wget -qO- http://localhost:9414/health | grep -q '\"status\":\"ok\"'"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
networks:
- sendico-net

View File

@@ -0,0 +1,135 @@
#!/usr/bin/env bash
set -euo pipefail
[[ "${DEBUG_DEPLOY:-0}" = "1" ]] && set -x
trap 'echo "[deploy-payments-quotation] error at line $LINENO" >&2' ERR
: "${REMOTE_BASE:?missing REMOTE_BASE}"
: "${SSH_USER:?missing SSH_USER}"
: "${SSH_HOST:?missing SSH_HOST}"
: "${PAYMENTS_QUOTATION_DIR:?missing PAYMENTS_QUOTATION_DIR}"
: "${PAYMENTS_QUOTATION_COMPOSE_PROJECT:?missing PAYMENTS_QUOTATION_COMPOSE_PROJECT}"
: "${PAYMENTS_QUOTATION_SERVICE_NAME:?missing PAYMENTS_QUOTATION_SERVICE_NAME}"
REMOTE_DIR="${REMOTE_BASE%/}/${PAYMENTS_QUOTATION_DIR}"
REMOTE_TARGET="${SSH_USER}@${SSH_HOST}"
COMPOSE_FILE="payments_quotation.yml"
SERVICE_NAMES="${PAYMENTS_QUOTATION_SERVICE_NAME}"
REQUIRED_SECRETS=(
PAYMENTS_MONGO_USER
PAYMENTS_MONGO_PASSWORD
)
for var in "${REQUIRED_SECRETS[@]}"; do
if [[ -z "${!var:-}" ]]; then
echo "missing required secret env: ${var}" >&2
exit 65
fi
done
if [[ ! -s .env.version ]]; then
echo ".env.version is missing; run version step first" >&2
exit 66
fi
b64enc() {
printf '%s' "$1" | base64 | tr -d '\n'
}
PAYMENTS_MONGO_USER_B64="$(b64enc "${PAYMENTS_MONGO_USER}")"
PAYMENTS_MONGO_PASSWORD_B64="$(b64enc "${PAYMENTS_MONGO_PASSWORD}")"
SSH_OPTS=(
-i /root/.ssh/id_rsa
-o StrictHostKeyChecking=no
-o UserKnownHostsFile=/dev/null
-o LogLevel=ERROR
-q
)
if [[ "${DEBUG_DEPLOY:-0}" = "1" ]]; then
SSH_OPTS=("${SSH_OPTS[@]/-q/}" -vv)
fi
RSYNC_FLAGS=(-az --delete)
[[ "${DEBUG_DEPLOY:-0}" = "1" ]] && RSYNC_FLAGS=(-avz --delete)
ssh "${SSH_OPTS[@]}" "$REMOTE_TARGET" "mkdir -p ${REMOTE_DIR}/{compose,env}"
rsync "${RSYNC_FLAGS[@]}" -e "ssh ${SSH_OPTS[*]}" ci/prod/compose/ "$REMOTE_TARGET:${REMOTE_DIR}/compose/"
rsync "${RSYNC_FLAGS[@]}" -e "ssh ${SSH_OPTS[*]}" ci/prod/.env.runtime "$REMOTE_TARGET:${REMOTE_DIR}/env/.env.runtime"
rsync "${RSYNC_FLAGS[@]}" -e "ssh ${SSH_OPTS[*]}" .env.version "$REMOTE_TARGET:${REMOTE_DIR}/env/.env.version"
SERVICES_LINE="${SERVICE_NAMES}"
ssh "${SSH_OPTS[@]}" "$REMOTE_TARGET" \
REMOTE_DIR="$REMOTE_DIR" \
COMPOSE_FILE="$COMPOSE_FILE" \
COMPOSE_PROJECT="$PAYMENTS_QUOTATION_COMPOSE_PROJECT" \
SERVICES_LINE="$SERVICES_LINE" \
PAYMENTS_MONGO_USER_B64="$PAYMENTS_MONGO_USER_B64" \
PAYMENTS_MONGO_PASSWORD_B64="$PAYMENTS_MONGO_PASSWORD_B64" \
bash -s <<'EOSSH'
set -euo pipefail
cd "${REMOTE_DIR}/compose"
set -a
. ../env/.env.runtime
load_kv_file() {
local file="$1"
while IFS= read -r line || [ -n "$line" ]; do
case "$line" in
''|\#*) continue ;;
esac
if printf '%s' "$line" | grep -Eq '^[[:alpha:]_][[:alnum:]_]*='; then
local key="${line%%=*}"
local value="${line#*=}"
key="$(printf '%s' "$key" | tr -d '[:space:]')"
value="${value#"${value%%[![:space:]]*}"}"
value="${value%"${value##*[![:space:]]}"}"
if [[ -n "$key" ]]; then
export "$key=$value"
fi
fi
done <"$file"
}
load_kv_file ../env/.env.version
set +a
if base64 -d >/dev/null 2>&1 <<<'AA=='; then
BASE64_DECODE_FLAG='-d'
else
BASE64_DECODE_FLAG='--decode'
fi
decode_b64() {
val="$1"
if [[ -z "$val" ]]; then
printf ''
return
fi
printf '%s' "$val" | base64 "${BASE64_DECODE_FLAG}"
}
PAYMENTS_MONGO_USER="$(decode_b64 "$PAYMENTS_MONGO_USER_B64")"
PAYMENTS_MONGO_PASSWORD="$(decode_b64 "$PAYMENTS_MONGO_PASSWORD_B64")"
export PAYMENTS_MONGO_USER PAYMENTS_MONGO_PASSWORD
COMPOSE_PROJECT_NAME="$COMPOSE_PROJECT"
export COMPOSE_PROJECT_NAME
read -r -a SERVICES <<<"${SERVICES_LINE}"
pull_cmd=(docker compose -f "$COMPOSE_FILE" pull)
up_cmd=(docker compose -f "$COMPOSE_FILE" up -d --remove-orphans)
ps_cmd=(docker compose -f "$COMPOSE_FILE" ps)
if [[ "${#SERVICES[@]}" -gt 0 ]]; then
pull_cmd+=("${SERVICES[@]}")
up_cmd+=("${SERVICES[@]}")
ps_cmd+=("${SERVICES[@]}")
fi
"${pull_cmd[@]}"
"${up_cmd[@]}"
"${ps_cmd[@]}"
date -Is > .last_deploy
logger -t "deploy-${COMPOSE_PROJECT_NAME}" "${COMPOSE_PROJECT_NAME} deployed at $(date -Is) in ${REMOTE_DIR}"
EOSSH

View File

@@ -0,0 +1,85 @@
#!/bin/sh
set -eu
if ! set -o pipefail 2>/dev/null; then
:
fi
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.$$"
tr -d '\r' <"$file" >"$tmp"
mv "$tmp" "$file"
}
load_env_file() {
file="$1"
while IFS= read -r line || [ -n "$line" ]; do
case "$line" in
''|\#*) continue ;;
esac
key="${line%%=*}"
value="${line#*=}"
key="$(printf '%s' "$key" | tr -d '[:space:]')"
value="${value#"${value%%[![:space:]]*}"}"
value="${value%"${value##*[![:space:]]}"}"
export "$key=$value"
done <"$file"
}
PAYMENTS_QUOTATION_ENV_NAME="${PAYMENTS_QUOTATION_ENV:-prod}"
RUNTIME_ENV_FILE="./ci/${PAYMENTS_QUOTATION_ENV_NAME}/.env.runtime"
if [ ! -f "${RUNTIME_ENV_FILE}" ]; then
echo "[payments-quotation-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 "${RUNTIME_ENV_FILE}"
load_env_file ./.env.version
REGISTRY_URL="${REGISTRY_URL:?missing REGISTRY_URL}"
APP_V="${APP_V:?missing APP_V}"
PAYMENTS_QUOTATION_DOCKERFILE="${PAYMENTS_QUOTATION_DOCKERFILE:?missing PAYMENTS_QUOTATION_DOCKERFILE}"
PAYMENTS_QUOTATION_IMAGE_PATH="${PAYMENTS_QUOTATION_IMAGE_PATH:?missing PAYMENTS_QUOTATION_IMAGE_PATH}"
REGISTRY_HOST="${REGISTRY_URL#http://}"
REGISTRY_HOST="${REGISTRY_HOST#https://}"
REGISTRY_USER="$(cat secrets/REGISTRY_USER)"
REGISTRY_PASSWORD="$(cat secrets/REGISTRY_PASSWORD)"
: "${REGISTRY_USER:?missing registry user}"
: "${REGISTRY_PASSWORD:?missing registry password}"
mkdir -p /kaniko/.docker
AUTH_B64="$(printf '%s:%s' "$REGISTRY_USER" "$REGISTRY_PASSWORD" | base64 | tr -d '\n')"
cat <<EOC >/kaniko/.docker/config.json
{
"auths": {
"https://${REGISTRY_HOST}": { "auth": "${AUTH_B64}" }
}
}
EOC
BUILD_CONTEXT="${PAYMENTS_QUOTATION_BUILD_CONTEXT:-${WOODPECKER_WORKSPACE:-${CI_WORKSPACE:-${PWD:-/workspace}}}}"
if [ ! -d "${BUILD_CONTEXT}" ]; then
BUILD_CONTEXT="/workspace"
fi
/kaniko/executor \
--context "${BUILD_CONTEXT}" \
--dockerfile "${PAYMENTS_QUOTATION_DOCKERFILE}" \
--destination "${REGISTRY_URL}/${PAYMENTS_QUOTATION_IMAGE_PATH}:${APP_V}" \
--build-arg APP_VERSION="${APP_V}" \
--build-arg GIT_REV="${GIT_REV}" \
--build-arg BUILD_BRANCH="${BUILD_BRANCH}" \
--build-arg BUILD_DATE="${BUILD_DATE}" \
--build-arg BUILD_USER="${BUILD_USER}" \
--single-snapshot

View File

@@ -0,0 +1,55 @@
#!/bin/sh
set -eu
if ! set -o pipefail 2>/dev/null; then
:
fi
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.$$"
tr -d '\r' <"$file" >"$tmp"
mv "$tmp" "$file"
}
load_env_file() {
file="$1"
while IFS= read -r line || [ -n "$line" ]; do
case "$line" in
''|\#*) continue ;;
esac
key="${line%%=*}"
value="${line#*=}"
key="$(printf '%s' "$key" | tr -d '[:space:]')"
value="${value#"${value%%[![:space:]]*}"}"
value="${value%"${value##*[![:space:]]}"}"
export "$key=$value"
done <"$file"
}
PAYMENTS_QUOTATION_ENV_NAME="${PAYMENTS_QUOTATION_ENV:-prod}"
RUNTIME_ENV_FILE="./ci/${PAYMENTS_QUOTATION_ENV_NAME}/.env.runtime"
if [ ! -f "${RUNTIME_ENV_FILE}" ]; then
echo "[payments-quotation-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 "${RUNTIME_ENV_FILE}"
load_env_file ./.env.version
PAYMENTS_QUOTATION_MONGO_SECRET_PATH="${PAYMENTS_QUOTATION_MONGO_SECRET_PATH:?missing PAYMENTS_QUOTATION_MONGO_SECRET_PATH}"
export PAYMENTS_MONGO_USER="$(./ci/vlt kv_get kv "${PAYMENTS_QUOTATION_MONGO_SECRET_PATH}" user)"
export PAYMENTS_MONGO_PASSWORD="$(./ci/vlt kv_get kv "${PAYMENTS_QUOTATION_MONGO_SECRET_PATH}" password)"
bash ci/prod/scripts/bootstrap/network.sh
bash ci/prod/scripts/deploy/payments_quotation.sh