Skip to content

Commit

Permalink
chore: initial Tiltfile (#3412)
Browse files Browse the repository at this point in the history
* chore: initial Tiltfile

* chore: add lnd1 to Tiltfile

* chore: add core api to Tiltfile

* chore: add serve_env to api

* chore: add auth deps to Tiltfile

* chore: run consent test in tilt

* build: add xvfb-run to tilt

* fix: bring back .env

* ci: fix --test opt in tilt.yml

* ci: pass labels to tilt
  • Loading branch information
bodymindarts authored Oct 26, 2023
1 parent 11f4bc2 commit 808208e
Show file tree
Hide file tree
Showing 45 changed files with 1,461 additions and 11 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/tilt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: "Tilt CI"
on:
pull_request:
branches: [ main ]
types: [opened, synchronize, labeled, unlabeled]

jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v22
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
- name: Prepare tilt args from labels
id: prepare_args
run: |
ARGS=""
cat <<EOF > labels.json
${{ toJSON(github.event.pull_request.labels.*.name) }}
EOF
for LABEL in $(jq -r '.[]' < labels.json); do
case "$LABEL" in
dashboard|consent)
ARGS+=" $LABEL"
;;
esac
done
echo "Prepared args: $ARGS"
echo "args=$ARGS" >> "$GITHUB_OUTPUT"
- name: Tilt CI
run: nix develop -c bash -c "cd dev && xvfb-run tilt ci -- --test ${{ steps.prepare_args.outputs.args }}"
17 changes: 17 additions & 0 deletions apps/consent/BUCK
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
load("@toolchains//workspace-pnpm:macros.bzl",
"dev_pnpm_task_binary",
"dev_pnpm_task_test",
"build_node_modules",
"next_build",
"next_build_bin",
"eslint"
)

dev_pnpm_task_binary(
name = "dev",
command = "dev",
)

dev_pnpm_task_binary(
name = "open-cypress",
command = "cypress:open",
)

dev_pnpm_task_test(
name = "cypress",
command = "cypress:run",
)

export_file(
name = "package.json",
visibility = ["PUBLIC"],
Expand Down
8 changes: 3 additions & 5 deletions apps/consent/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { defineConfig } from "cypress"
import dotenv from "dotenv"
dotenv.config()
dotenv.config({ path: ".env.test" })
dotenv.config({ path: "../../dev/.envs/consent.env" })

export default defineConfig({
e2e: {
baseUrl: "http://127.0.0.1:3000",
// setupNodeEvents(on, config) {},
baseUrl: "http://localhost:3000",
},
defaultCommandTimeout: 60000,
env: {
...process.env,
AUTHORIZATION_URL: process.env.AUTHORIZATION_URL,
},
component: {
devServer: {
Expand Down
2 changes: 1 addition & 1 deletion apps/consent/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ declare namespace Cypress {
}

Cypress.Commands.add("getOTP", (email) => {
const query = `docker exec -i api-kratos-pg-1 psql -U dbuser -d default -t -c "SELECT body FROM courier_messages WHERE recipient='${email}' ORDER BY created_at DESC LIMIT 1;"`
const query = `docker exec -i galoy-dev-kratos-pg-1 psql -U dbuser -d default -t -c "SELECT body FROM courier_messages WHERE recipient='${email}' ORDER BY created_at DESC LIMIT 1;"`
cy.exec(query).then((result) => {
const rawMessage = result.stdout
const otpMatch = rawMessage.match(/(\d{6})/)
Expand Down
4 changes: 2 additions & 2 deletions apps/consent/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { z } from "zod"
export const env = createEnv({
server: {
HYDRA_ADMIN_URL: z.string().default("http://localhost:4445"),
CORE_AUTH_URL: z.string().default("http://localhost:4002/auth"),
CORE_AUTH_URL: z.string().default("http://localhost:4455/auth"),
},
shared: {
GRAPHQL_ENDPOINT: z.string().default("http://localhost:4002/graphql"),
GRAPHQL_ENDPOINT: z.string().default("http://localhost:4455/graphql"),
},
runtimeEnv: {
CORE_AUTH_URL: process.env.CORE_AUTH_URL,
Expand Down
2 changes: 1 addition & 1 deletion core/api/src/config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const env = createEnv({
KRATOS_CALLBACK_API_KEY: z.string().min(1),

BRIA_HOST: z.string().min(1),
BRIA_PORT: z.number().min(1).or(z.string()).pipe(z.coerce.number()),
BRIA_PORT: z.number().min(1).or(z.string()).pipe(z.coerce.number()).default(2742),
BRIA_API_KEY: z.string().min(1),

GEETEST_ID: z.string().min(1).optional(),
Expand Down
3 changes: 3 additions & 0 deletions dev/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.*.json
.*.env
.envs
143 changes: 142 additions & 1 deletion dev/Tiltfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,148 @@
is_ci=sys.argv[1] == "ci"

config.define_string_list("test")
cfg = config.parse()

groups = {
"auth": [
"oathkeeper",
"hydra",
"hydra-migrate",
"hydra-pg",
"kratos",
"kratos-pg",
],
"core": [
"apollo-router",
"mongodb",
"redis",
],
"bitcoin": [
"lnd1",
"bria",
"postgres-bria",
"fulcrum",
"bitcoind-signer",
"bitcoind",
],
"tracing": [
"otel-agent",
],
}

consent_test_target = "//apps/consent:cypress"
local_resource(
"consent-test",
labels = ["test"],
auto_init = is_ci and "consent" in cfg.get("test", []),
cmd = "buck2 test {}".format(consent_test_target),
resource_deps = [
"consent",
"init-test-user",
"hydra-consent"
],
)

local_resource(
name='init-test-user',
labels = ['test'],
cmd='bin/init-user.sh',
resource_deps = [
"oathkeeper",
"kratos",
"api",
]
)

consent_target = "//apps/consent:dev"
if is_ci:
consent_target = '//apps/consent:consent'
local_resource(
"consent",
labels = ["auth"],
cmd = "buck2 build {}".format(consent_target),
serve_cmd = "buck2 run {}".format(consent_target),
resource_deps = [
"apollo-router",
"hydra",
"api",
],
links = [
link("http://localhost:3000", "consent"),
],
)

local_resource(
name='hydra-consent',
labels = ['auth'],
cmd=['bin/setup-hydra-client.sh', 'consent', 'http://localhost:3000'],
resource_deps = [
"hydra",
]
)

api_target = "//core/api:api"
local_resource(
"api",
labels = ["frontend"],
labels = ["core"],
cmd = "buck2 build {}".format(api_target),
serve_cmd = "buck2 run {}".format(api_target),
serve_env = {
"HELMREVISION": "dev",
"NETWORK": "regtest",
"OATHKEEPER_DECISION_ENDPOINT": "http://localhost:4456",
"TWILIO_ACCOUNT_SID": "AC_twilio_id",
"TWILIO_AUTH_TOKEN": "AC_twilio_auth_token",
"TWILIO_VERIFY_SERVICE_ID": "VA_twilio_service",
"KRATOS_PG_CON": "postgres://dbuser:secret@localhost:5433/default?sslmode=disable",
"KRATOS_PUBLIC_API": "http://localhost:4433",
"KRATOS_ADMIN_API": "http://localhost:4434",
"KRATOS_MASTER_USER_PASSWORD": "passwordHardtoFindWithNumber123",
"KRATOS_CALLBACK_API_KEY": "The-Value-of-My-Key",
"BRIA_HOST": "localhost",
"BRIA_API_KEY": "bria_dev_000000000000000000000",
"MONGODB_CON": "mongodb://localhost:27017/galoy",
"REDIS_MASTER_NAME": "mymaster",
"REDIS_PASSWORD": "",
"REDIS_0_DNS": "localhost",
"REDIS_0_PORT": "6379",
"REDIS_TYPE": "standalone",
"UNSECURE_IP_FROM_REQUEST_OBJECT": "true",
"UNSECURE_DEFAULT_LOGIN_CODE": "000000",
"GEETEST_ID": "geetest_id",
"GEETEST_KEY": "geetest_key"
},
allow_parallel = True,
readiness_probe = probe(
period_secs = 5,
http_get = http_get_action(
path = "healthz",
port = 4012,
),
),
resource_deps = [
"init-onchain",
"lnd1",
]
)

local_resource(
name='init-onchain',
labels = ['bitcoin'],
cmd='bin/init-onchain.sh',
resource_deps = [
"bitcoind",
"bria",
]
)

docker_compose("./docker-compose.deps.yml", project_name = "galoy-dev")

for service in groups["bitcoin"]:
dc_resource(service, labels = ["bitcoin"])
for service in groups["tracing"]:
dc_resource(service, labels = ["tracing"])
for service in groups["core"]:
dc_resource(service, labels = ["core"])
for service in groups["auth"]:
dc_resource(service, labels = ["auth"])
24 changes: 24 additions & 0 deletions dev/bin/init-onchain.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

set -e

DEV_DIR="$(dirname "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")")"
source "${DEV_DIR}/helpers/cli.sh"

echo "Seeding some regtest blocks..."

bitcoin_cli createwallet "outside" || true
bitcoin_cli -generate 200 > /dev/null 2>&1

bitcoin_signer_cli createwallet "dev" || true
bitcoin_signer_cli -rpcwallet=dev importdescriptors "$(cat ./config/bitcoind/bitcoind_signer_descriptors.json)"

echo "Checking that bria is running..."

for _ in {1..20}; do
bria_cli wallet-balance -w dev-wallet && break
sleep 1
done
bria_cli wallet-balance -w dev-wallet || exit 1

echo "DONE"
16 changes: 16 additions & 0 deletions dev/bin/init-user.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

set -e

set -x

DEV_DIR="$(dirname "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")")"
source "${DEV_DIR}/helpers/auth.sh"
source "${DEV_DIR}/helpers/gql.sh"

user_phone="+16505554350"
email="test@galoy.com"

auth_token="$(login_user "${user_phone}")"

register_email_to_user "${auth_token}" "${email}"
34 changes: 34 additions & 0 deletions dev/bin/setup-hydra-client.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

set -e

DEV_DIR="$(dirname "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")")"
source "${DEV_DIR}/helpers/cli.sh"

hydra_client_name="${1}"
redirect_uri="${2}"

HYDRA_CLIENT_JSON="${DEV_DIR}/../.${hydra_client_name}-hydra-client.json"
HYDRA_CLIENT_ENV="${DEV_DIR}/../.${hydra_client_name}-hydra-client.env"
HYDRA_ADMIN_API="http://localhost:4445"
HYDRA_PUBLIC_API="http://localhost:4444"

hydra_cli create client \
--endpoint "${HYDRA_ADMIN_API}" \
--grant-type authorization_code,refresh_token \
--response-type code,id_token \
--format json \
--scope offline --scope transactions:read --scope payments:send \
--redirect-uri "$redirect_uri" > "${HYDRA_CLIENT_JSON}"

CLIENT_ID=$(jq -r '.client_id' < "${HYDRA_CLIENT_JSON}")
CLIENT_SECRET=$(jq -r '.client_secret' < "${HYDRA_CLIENT_JSON}")

AUTHORIZATION_URL="${HYDRA_PUBLIC_API}/oauth2/auth?client_id=$CLIENT_ID&scope=offline%20transactions:read&response_type=code&redirect_uri=$redirect_uri&state=kfISr3GhH0rqheByU6A6hqIG_f14pCGkZLSCUTHnvlI"

echo "export CLIENT_ID=$CLIENT_ID" > "${HYDRA_CLIENT_ENV}"
echo "export CLIENT_SECRET=$CLIENT_SECRET" >> "${HYDRA_CLIENT_ENV}"
echo "export AUTHORIZATION_URL=$AUTHORIZATION_URL" >> "${HYDRA_CLIENT_ENV}"

mkdir -p "${DEV_DIR}/.envs"
cp "${HYDRA_CLIENT_ENV}" "${DEV_DIR}/.envs/${hydra_client_name}.env"
19 changes: 19 additions & 0 deletions dev/config/bitcoind/bitcoin.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
rpcuser=rpcuser
rpcpassword=rpcpassword
debug=mempool
debug=rpc
server=1
txindex=1
printtoconsole=1
zmqpubrawtx=tcp://0.0.0.0:28333
zmqpubrawblock=tcp://0.0.0.0:28332
blockfilterindex=1
bind=0.0.0.0
fallbackfee=0.0002
rpcallowip=0.0.0.0/0
regtest=1
[regtest]
bind=0.0.0.0
fallbackfee=0.0002
rpcallowip=0.0.0.0/0
rpcbind=0.0.0.0
1 change: 1 addition & 0 deletions dev/config/bitcoind/bitcoind_signer_descriptors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"active":true,"desc":"wpkh([6f2fa1b2/84'/0'/0']tprv8gXB88g1VCScmqPp8WcetpJPRxix24fRJJ6FniYCcCUEFMREDrCfwd34zWXPiY5MW2xp8e1Z6EeBrh74zMSgfQQmTorWtE1zyBtv7yxdcoa/0/*)#88k4937c","timestamp":0},{"active":true,"desc":"wpkh([6f2fa1b2/84'/0'/0']tprv8gXB88g1VCScmqPp8WcetpJPRxix24fRJJ6FniYCcCUEFMREDrCfwd34zWXPiY5MW2xp8e1Z6EeBrh74zMSgfQQmTorWtE1zyBtv7yxdcoa/1/*)#knn5cywq","internal":true,"timestamp":0}]
8 changes: 8 additions & 0 deletions dev/config/bria.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
app:
blockchain:
network: regtest
electrum_url: fulcrum:50001
tracing:
host: "otel-agent"
port: 4318
service_name: "bria-dev"
7 changes: 7 additions & 0 deletions dev/config/fulcrum/fulcrum.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
bitcoind = bitcoind:18443
rpcuser = rpcuser
rpcpassword = rpcpassword
peering = false
announce = false
tcp = 0.0.0.0:50001
ssl = 0.0.0.0:50002
Loading

0 comments on commit 808208e

Please sign in to comment.