-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.sh
executable file
·84 lines (76 loc) · 3.13 KB
/
cli.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
export HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH="$(cd "$(dirname "$1")"; pwd -P)/$(basename "$1")"
filepath=$1
connector=$(basename "$filepath")
subgraph=$(echo $filepath | cut -d'/' -f2)
SUBGRAPH=$(echo $subgraph | tr '[:lower:]' '[:upper:]')
CONNECTOR=$(echo $connector | tr '[:lower:]' '[:upper:]')
content=$(cat compose.yaml)
echo $HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH
mkdir -p $HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH
#rm -rf ${HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH}
#mkdir -p ${HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH}
docker run --entrypoint ndc-calcite-cli -e "OTEL_LOG_LEVEL=trace" -e "OTEL_LOGS_EXPORTER=console" -e "OTEL_TRACES_EXPORTER=console" -e "RUST_LOG=debug" -e "LOG_LEVEL=all" -e HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH -v "${HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH}":/app/output -v "${HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH}":/etc/connector:ro ghcr.io/hasura/ndc-calcite:latest update
echo "include:\n - path: ${filepath}/compose.yaml" > temp.yml
echo "$content" >> temp.yml
mv temp.yml compose.yaml
global_env=$(cat << EOF
${SUBGRAPH}_${CONNECTOR}_HASURA_SERVICE_TOKEN_SECRET=$3
${SUBGRAPH}_${CONNECTOR}_OTEL_EXPORTER_OTLP_METRICS_ENDPOINT="http://local.hasura.dev:4317"
${SUBGRAPH}_${CONNECTOR}_OTEL_EXPORTER_OTLP_TRACES_ENDPOINT="http://local.hasura.dev:4317"
${SUBGRAPH}_${CONNECTOR}_OTEL_EXPORTER_OTLP_ENDPOINT="http://local.hasura.dev:4317"
EOF
)
echo "$global_env" >> .env
rm -rf $filepath/compose.yaml
connector_compose_yaml=$(cat << EOF
services:
${subgraph}_${connector}:
build:
context: .
dockerfile_inline: |-
FROM ghcr.io/hasura/ndc-calcite:latest
COPY ./ /etc/connector
develop:
watch:
- path: ./
action: sync+restart
target: /etc/connector
environment:
HASURA_SERVICE_TOKEN_SECRET: \$${SUBGRAPH}_${CONNECTOR}_HASURA_SERVICE_TOKEN_SECRET
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: \$${SUBGRAPH}_${CONNECTOR}_OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT: \$${SUBGRAPH}_${CONNECTOR}_OTEL_EXPORTER_OTLP_METRICS_ENDPOINT
OTEL_EXPORTER_OTLP_ENDPOINT: \$${SUBGRAPH}_${CONNECTOR}_OTEL_EXPORTER_OTLP_ENDPOINT
OTEL_SERVICE_NAME: \$${SUBGRAPH}_${CONNECTOR}_OTEL_SERVICE_NAME
extra_hosts:
- local.hasura.dev=host-gateway
ports:
- mode: ingress
target: 8080
published: "$2"
protocol: tcp
EOF
)
echo "$connector_compose_yaml" > $filepath/compose.yaml
rm -rf $filepath/connector.yaml
connector_yaml=$(cat << EOF
kind: Connector
version: v2
definition:
name: ${connector}
subgraph: ${subgraph}
source: hasura/postgres:v1.1.0
context: .
envMapping:
HASURA_SERVICE_TOKEN_SECRET:
fromEnv: ${SUBGRAPH}_${CONNECTOR}_HASURA_SERVICE_TOKEN_SECRET
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT:
fromEnv: ${SUBGRAPH}_${CONNECTOR}_OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT:
fromEnv: ${SUBGRAPH}_${CONNECTOR}_OTEL_EXPORTER_OTLP_METRICS_ENDPOINT
OTEL_EXPORTER_OTLP_ENDPOINT:
fromEnv: ${SUBGRAPH}_${CONNECTOR}_OTEL_EXPORTER_OTLP_ENDPOINT
OTEL_SERVICE_NAME:
fromEnv: ${SUBGRAPH}_${CONNECTOR}_OTEL_SERVICE_NAME
EOF
)
echo "$connector_yaml" > $filepath/connector.yaml