Skip to content

Commit 05a5495

Browse files
committed
feat: present public Raindex market API
1 parent d176c47 commit 05a5495

40 files changed

Lines changed: 3878 additions & 1377 deletions
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: Deploy Raindex API
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
scope:
6+
description: Deployment scope
7+
required: true
8+
default: service
9+
type: choice
10+
options:
11+
- service
12+
- all
13+
- system
14+
concurrency:
15+
group: deploy-raindex-api-production
16+
cancel-in-progress: false
17+
permissions:
18+
contents: read
19+
jobs:
20+
deploy:
21+
runs-on: ubuntu-latest
22+
environment: Production
23+
env:
24+
RAINDEX_API_HOSTNAME: ${{ vars.RAINDEX_API_HOSTNAME }}
25+
steps:
26+
- uses: actions/checkout@v6
27+
with:
28+
submodules: recursive
29+
- uses: nixbuild/nix-quick-install-action@v30
30+
with:
31+
nix_conf: |
32+
accept-flake-config = true
33+
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
34+
- uses: cachix/cachix-action@v15
35+
continue-on-error: true
36+
with:
37+
name: rainlanguage
38+
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
39+
useDaemon: false
40+
- uses: nix-community/cache-nix-action@v7
41+
with:
42+
primary-key: nix-${{ runner.os }}-${{ hashFiles('**/*.nix', '**/flake.lock') }}
43+
restore-prefixes-first-match: nix-${{ runner.os }}-
44+
gc-max-store-size-linux: 8G
45+
- name: Validate deployment definitions
46+
run: |
47+
nix flake check --no-build --impure
48+
nix build .#raindex-api --no-link
49+
nix shell .#opentofu -c tofu -chdir=infra init -backend=false
50+
nix shell .#opentofu -c tofu -chdir=infra validate
51+
- name: Configure authenticated SSH
52+
env:
53+
SSH_KEY: ${{ secrets.RAINDEX_API_SSH_KEY }}
54+
run: |
55+
test -n "$SSH_KEY"
56+
install -d -m 700 ~/.ssh
57+
printf '%s\n' "$SSH_KEY" > ~/.ssh/id_ed25519
58+
chmod 600 ~/.ssh/id_ed25519
59+
60+
host_ip=$(nix run .#resolveIp -- -i ~/.ssh/id_ed25519)
61+
host_key=$(nix eval --raw --file keys.nix keys.host)
62+
test "$host_key" != "ssh-ed25519 REPLACE_AFTER_BOOTSTRAP"
63+
printf '%s %s\n' "$host_ip" "$host_key" > ~/.ssh/known_hosts
64+
- name: Deploy
65+
env:
66+
SCOPE: ${{ inputs.scope }}
67+
run: |
68+
case "$SCOPE" in
69+
service) nix run .#deployService -- -i ~/.ssh/id_ed25519 rest-api ;;
70+
system) nix run .#deployNixos -- -i ~/.ssh/id_ed25519 ;;
71+
all) nix run .#deployAll -- -i ~/.ssh/id_ed25519 ;;
72+
*) echo "Unsupported deployment scope: $SCOPE" >&2; exit 1 ;;
73+
esac
74+
- name: Verify deployment
75+
run: |
76+
api_hostname="${RAINDEX_API_HOSTNAME:-api.raindex.finance}"
77+
health_url="https://$api_hostname/health/detailed"
78+
for _ in $(seq 1 60); do
79+
if curl --fail --silent --show-error --max-time 5 "$health_url"; then
80+
exit 0
81+
fi
82+
sleep 5
83+
done
84+
85+
host_ip=$(nix run .#resolveIp -- -i ~/.ssh/id_ed25519)
86+
ssh -i ~/.ssh/id_ed25519 "root@$host_ip" \
87+
'systemctl status rest-api.service --no-pager || true; journalctl -u rest-api.service -n 200 --no-pager || true'
88+
exit 1

.github/workflows/raindex-api.yaml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Raindex API
2+
on:
3+
push:
4+
branches:
5+
- main
6+
paths:
7+
- "Cargo.lock"
8+
- "Cargo.toml"
9+
- "crates/**"
10+
- "*.nix"
11+
- "flake.lock"
12+
- "infra/**"
13+
- ".github/workflows/raindex-api.yaml"
14+
- ".github/workflows/deploy-raindex-api.yaml"
15+
pull_request:
16+
paths:
17+
- "Cargo.lock"
18+
- "Cargo.toml"
19+
- "crates/**"
20+
- "*.nix"
21+
- "flake.lock"
22+
- "infra/**"
23+
- ".github/workflows/raindex-api.yaml"
24+
- ".github/workflows/deploy-raindex-api.yaml"
25+
concurrency:
26+
group: ${{ github.workflow }}-${{ github.ref }}
27+
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
28+
permissions:
29+
contents: read
30+
jobs:
31+
production-build:
32+
runs-on: ubuntu-latest
33+
steps:
34+
- uses: actions/checkout@v6
35+
with:
36+
submodules: recursive
37+
- uses: nixbuild/nix-quick-install-action@v30
38+
with:
39+
nix_conf: |
40+
accept-flake-config = true
41+
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
42+
- uses: cachix/cachix-action@v15
43+
continue-on-error: true
44+
with:
45+
name: rainlanguage
46+
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
47+
useDaemon: false
48+
- uses: nix-community/cache-nix-action@v7
49+
with:
50+
primary-key: nix-${{ runner.os }}-${{ hashFiles('**/*.nix', '**/flake.lock', 'Cargo.lock') }}
51+
restore-prefixes-first-match: nix-${{ runner.os }}-
52+
gc-max-store-size-linux: 8G
53+
- name: Validate reproducible service and host definitions
54+
run: |
55+
nix flake check --no-build --impure
56+
nix build .#raindex-api --no-link
57+
- name: Validate infrastructure and workflows
58+
run: |
59+
nix shell .#opentofu -c tofu -chdir=infra init -backend=false
60+
nix shell .#opentofu -c tofu -chdir=infra validate
61+
nix shell .#actionlint -c actionlint \
62+
.github/workflows/raindex-api.yaml \
63+
.github/workflows/deploy-raindex-api.yaml

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ packages/raindex/cjs.d.ts
1414
packages/raindex/esm.js
1515
packages/raindex/esm.d.ts
1616
.direnv/
17+
.raindex/
1718

1819
# Audit proposed fixes
1920
.fixes/

Cargo.lock

Lines changed: 97 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

REUSE.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,16 @@ path = [
2525
"package-lock.json",
2626
"Cargo.lock",
2727
"Cargo.toml",
28+
"deploy.nix",
29+
"disko.nix",
2830
".devcontainer.json",
2931
".env.example",
32+
"infra/**/",
33+
"keys.nix",
34+
"os.nix",
3035
"packages/**/",
36+
"rust.nix",
37+
"services.nix",
3138
"ai_commands/**/",
3239
"subgraph/**/",
3340
"crates/**/",

crates/rest_api/Cargo.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,24 @@ path = "src/main.rs"
1313

1414
[dependencies]
1515
raindex_common = { workspace = true }
16+
async-trait = "0.1"
17+
moka = { version = "0.12", features = ["future"] }
1618
rocket = { version = "0.5.1", features = ["json"] }
1719
rocket_cors = "0.6"
1820
serde = { workspace = true, features = ["derive"] }
1921
serde_json = { workspace = true }
2022
thiserror = { workspace = true }
23+
tracing = { workspace = true }
24+
tracing-appender = "0.2"
25+
tracing-subscriber = { workspace = true, features = ["env-filter", "json"] }
2126
utoipa = { version = "5", features = ["rocket_extras"] }
22-
utoipa-swagger-ui = { version = "9", features = ["rocket"] }
27+
utoipa-swagger-ui = { version = "9", features = ["rocket", "vendored"] }
28+
uuid = { version = "1", features = ["v4"] }
2329

2430
[target.'cfg(not(target_family = "wasm"))'.dependencies]
2531
tokio = { workspace = true, features = ["full"] }
2632

2733
[dev-dependencies]
2834
tokio = { workspace = true, features = ["full", "macros"] }
2935
alloy = { workspace = true }
36+
tempfile = "3"

0 commit comments

Comments
 (0)