monetix gateway
This commit is contained in:
85
ci/scripts/mntx/build-image.sh
Normal file
85
ci/scripts/mntx/build-image.sh
Normal 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"
|
||||
}
|
||||
|
||||
MNTX_GATEWAY_ENV_NAME="${MNTX_GATEWAY_ENV:-prod}"
|
||||
RUNTIME_ENV_FILE="./ci/${MNTX_GATEWAY_ENV_NAME}/.env.runtime"
|
||||
|
||||
if [ ! -f "${RUNTIME_ENV_FILE}" ]; then
|
||||
echo "[mntx-gateway-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}"
|
||||
MNTX_GATEWAY_DOCKERFILE="${MNTX_GATEWAY_DOCKERFILE:?missing MNTX_GATEWAY_DOCKERFILE}"
|
||||
MNTX_GATEWAY_IMAGE_PATH="${MNTX_GATEWAY_IMAGE_PATH:?missing MNTX_GATEWAY_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 <<EOF >/kaniko/.docker/config.json
|
||||
{
|
||||
"auths": {
|
||||
"https://${REGISTRY_HOST}": { "auth": "${AUTH_B64}" }
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
BUILD_CONTEXT="${MNTX_GATEWAY_BUILD_CONTEXT:-${WOODPECKER_WORKSPACE:-${CI_WORKSPACE:-${PWD:-/workspace}}}}"
|
||||
if [ ! -d "${BUILD_CONTEXT}" ]; then
|
||||
BUILD_CONTEXT="/workspace"
|
||||
fi
|
||||
|
||||
/kaniko/executor \
|
||||
--context "${BUILD_CONTEXT}" \
|
||||
--dockerfile "${MNTX_GATEWAY_DOCKERFILE}" \
|
||||
--destination "${REGISTRY_URL}/${MNTX_GATEWAY_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
|
||||
64
ci/scripts/mntx/deploy.sh
Normal file
64
ci/scripts/mntx/deploy.sh
Normal file
@@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
[[ "${DEBUG_DEPLOY:-0}" = "1" ]] && set -x
|
||||
trap 'echo "[mntx-gateway-deploy] error at line $LINENO" >&2' ERR
|
||||
|
||||
REPO_ROOT="$(cd "$(dirname "$0")/../../.." && pwd)"
|
||||
cd "${REPO_ROOT}"
|
||||
|
||||
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
|
||||
if printf '%s' "$line" | grep -Eq '^[[:alpha:]_][[:alnum:]_]*='; then
|
||||
key="${line%%=*}"
|
||||
value="${line#*=}"
|
||||
key="$(printf '%s' "$key" | tr -d '[:space:]')"
|
||||
value="${value#"${value%%[![:space:]]*}"}"
|
||||
value="${value%"${value##*[![:space:]]}"}"
|
||||
export "$key=$value"
|
||||
fi
|
||||
done <"$file"
|
||||
}
|
||||
|
||||
MNTX_GATEWAY_ENV_NAME="${MNTX_GATEWAY_ENV:-prod}"
|
||||
RUNTIME_ENV_FILE="./ci/${MNTX_GATEWAY_ENV_NAME}/.env.runtime"
|
||||
|
||||
if [ ! -f "${RUNTIME_ENV_FILE}" ]; then
|
||||
echo "[mntx-gateway-deploy] runtime env file not found: ${RUNTIME_ENV_FILE}" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ ! -f ./.env.version ]; then
|
||||
echo "[mntx-gateway-deploy] .env.version is missing; run version step first" >&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
|
||||
|
||||
MNTX_GATEWAY_MONETIX_SECRET_PATH="${MNTX_GATEWAY_MONETIX_SECRET_PATH:-sendico/gateway/monetix}"
|
||||
MNTX_GATEWAY_NATS_SECRET_PATH="${MNTX_GATEWAY_NATS_SECRET_PATH:-sendico/nats}"
|
||||
: "${NATS_HOST:?missing NATS_HOST}"
|
||||
: "${NATS_PORT:?missing NATS_PORT}"
|
||||
|
||||
export MONETIX_PROJECT_ID="$(./ci/vlt kv_get kv "${MNTX_GATEWAY_MONETIX_SECRET_PATH}" project_id)"
|
||||
export MONETIX_SECRET_KEY="$(./ci/vlt kv_get kv "${MNTX_GATEWAY_MONETIX_SECRET_PATH}" secret_key)"
|
||||
|
||||
export NATS_USER="$(./ci/vlt kv_get kv "${MNTX_GATEWAY_NATS_SECRET_PATH}" user)"
|
||||
export NATS_PASSWORD="$(./ci/vlt kv_get kv "${MNTX_GATEWAY_NATS_SECRET_PATH}" password)"
|
||||
export NATS_URL="nats://${NATS_USER}:${NATS_PASSWORD}@${NATS_HOST}:${NATS_PORT}"
|
||||
|
||||
bash ci/prod/scripts/bootstrap/network.sh
|
||||
bash ci/prod/scripts/deploy/mntx_gateway.sh
|
||||
@@ -110,6 +110,12 @@ if [ -f "${PROTO_DIR}/gateway/chain/v1/chain.proto" ]; then
|
||||
generate_go_with_grpc "${PROTO_DIR}/gateway/chain/v1/chain.proto"
|
||||
fi
|
||||
|
||||
if [ -f "${PROTO_DIR}/gateway/mntx/v1/mntx.proto" ]; then
|
||||
info "Compiling Monetix gateway protos"
|
||||
clean_pb_files "./pkg/proto/gateway/mntx"
|
||||
generate_go_with_grpc "${PROTO_DIR}/gateway/mntx/v1/mntx.proto"
|
||||
fi
|
||||
|
||||
if [ -f "${PROTO_DIR}/payments/orchestrator/v1/orchestrator.proto" ]; then
|
||||
info "Compiling payments orchestrator protos"
|
||||
clean_pb_files "./pkg/proto/payments/orchestrator"
|
||||
|
||||
Reference in New Issue
Block a user