Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1 +1 @@
RUST_LOG=st0x_rest_api=info,rocket=warn,warn
RUST_LOG=albion_rest_api=info,rocket=warn,warn
10 changes: 10 additions & 0 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Deploy

on:
push:
branches:
- main
workflow_dispatch:

concurrency:
Expand All @@ -14,6 +17,8 @@ permissions:
jobs:
deploy:
runs-on: ubuntu-latest
env:
DEFAULT_DEPLOY_HOST: 104.236.85.154
steps:
- name: Free disk space
uses: jlumbroso/free-disk-space@v1.3.1
Expand Down Expand Up @@ -61,6 +66,9 @@ jobs:
if [ -n "${{ secrets.DEPLOY_HOST }}" ]; then
host_ip="${{ secrets.DEPLOY_HOST }}"
echo "Using DEPLOY_HOST secret"
elif [ -n "$DEFAULT_DEPLOY_HOST" ]; then
host_ip="$DEFAULT_DEPLOY_HOST"
echo "Using default branch deploy host"
else
host_ip=$(nix run .#resolveIp -- -i ~/.ssh/id_ed25519)
echo "Using resolved host IP from terraform state"
Expand All @@ -80,4 +88,6 @@ jobs:
- run: ./prep.sh

- name: Build and deploy
env:
DEPLOY_HOST: ${{ env.HOST_IP }}
run: nix run .#deployService -- rest-api
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ jobs:
- uses: nixbuild/nix-quick-install-action@v30

- name: Build docs
run: nix build .#st0x-docs
run: nix build .#albion-docs
120 changes: 84 additions & 36 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "st0x_rest_api"
name = "albion_rest_api"
version = "0.1.0"
edition = "2021"

Expand All @@ -24,6 +24,7 @@ sqlx = { version = "0.8.6", features = ["runtime-tokio", "sqlite", "migrate"] }
argon2 = "0.5.3"
base64 = "0.22.1"
clap = { version = "4.5.58", features = ["derive"] }
moka = { version = "0.12", features = ["future"] }
toml = "0.8"
reqwest = { version = "0.13.2", features = ["json"] }
rain_orderbook_js_api = { path = "lib/rain.orderbook/crates/js_api", default-features = false }
Expand Down
24 changes: 12 additions & 12 deletions DEPLOY.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519
### 3. DigitalOcean account setup
- Create a **Personal Access Token** (read+write) at: DigitalOcean → API → Tokens
- Upload your SSH public key to DigitalOcean under: Settings → Security → SSH Keys
- Note the **name** you give it — you'll need it below (default expected: `st0x-op`)
- Note the **name** you give it — you'll need it below (default expected: `albion-deployments`)

### 4. Enter the Nix dev shell
All commands below must be run inside this shell:
Expand Down Expand Up @@ -75,9 +75,9 @@ do_token = "your-digitalocean-api-token"

Optional overrides (defaults shown):
```hcl
ssh_key_name = "st0x-op" # Name of your SSH key in DigitalOcean
ssh_key_name = "albion-deployments" # Name of your SSH key in DigitalOcean
region = "nyc3" # DigitalOcean region slug
droplet_size = "s-2vcpu-4gb"
droplet_size = "s-4vcpu-8gb-amd"
volume_size_gb = 5
```

Expand All @@ -100,8 +100,8 @@ nix develop -c tf-apply
```

This provisions:
- Ubuntu 24.04 droplet (`st0x-rest-api-nixos`) in the chosen region
- 5 GB block storage volume (`st0x-rest-api-data`) mounted at `/mnt/data`
- Ubuntu 24.04 droplet (`albion-rest-api-nixos`) in the chosen region
- 5 GB block storage volume (`albion-rest-api-data`) mounted at `/mnt/data`
- A reserved IP attached to the droplet

The Terraform state is encrypted with `rage` and committed as
Expand Down Expand Up @@ -175,7 +175,7 @@ The deploy-rs workflow:

## Step 7 — DNS and TLS

1. Point your domain (`api.st0x.io` or your fork's domain) to the **reserved IP**
1. Point your domain (`api.albion.rest` or your fork's domain) to the **reserved IP**
output by Terraform:
```bash
nix develop -c resolve-ip # prints the reserved IP
Expand All @@ -185,7 +185,7 @@ The deploy-rs workflow:

Check the domain in `os.nix`:
```nix
virtualHosts."api.st0x.io" = { ... };
virtualHosts."api.albion.rest" = { ... };
```
Update it to your domain before deploying if this is a fork.

Expand All @@ -203,7 +203,7 @@ SSH into the server and create the first API key:
nix develop -c remote # opens an SSH session as root

# On the server:
/nix/var/nix/profiles/per-service/rest-api/bin/st0x_rest_api \
/nix/var/nix/profiles/per-service/rest-api/bin/albion_rest_api \
keys create --config /nix/var/nix/profiles/per-service/rest-api/../../../... \
--name "admin"
```
Expand Down Expand Up @@ -233,7 +233,7 @@ nix develop -c remote
# on server:
journalctl -u rest-api -f
# or log files:
ls /mnt/data/st0x-rest-api/logs/
ls /mnt/data/albion-rest-api/logs/
```

### Check service status
Expand Down Expand Up @@ -261,8 +261,8 @@ Your machine

Server (NixOS on DigitalOcean)
├─ Nginx (443) → reverse proxy → Rocket API (127.0.0.1:8000)
├─ SQLite DB → /mnt/data/st0x-rest-api/st0x.db
├─ Logs → /mnt/data/st0x-rest-api/logs/
├─ SQLite DB → /mnt/data/albion-rest-api/albion.db
├─ Logs → /mnt/data/albion-rest-api/logs/
└─ /mnt/data → DigitalOcean block volume (persists across reboots)
```

Expand All @@ -272,7 +272,7 @@ Server (NixOS on DigitalOcean)

Set `RUST_LOG` to control log verbosity (configured in `.env`):
```
RUST_LOG=st0x_rest_api=info,rocket=warn,warn
RUST_LOG=albion_rest_api=info,rocket=warn,warn
```

This is read by the systemd service environment. To change it on the server,
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# st0x REST API
# Albion REST API

REST API for st0x orderbook operations. Built with Rocket, backed by SQLite, and authenticated via API keys using HTTP Basic auth.
REST API for Albion orderbook operations. Built with Rocket, backed by SQLite, and authenticated via API keys using HTTP Basic auth.

## Setup

### 1. Clone and initialize submodules

```sh
git clone <repo-url>
cd st0x-rest-api
cd albion.rest.api
git submodule update --init --recursive
```

Expand All @@ -25,8 +25,8 @@ This writes `COMMIT_SHA` to `.env` and bootstraps the orderbook submodule.
The binary has two subcommands:

```
st0x_rest_api serve Start the API server
st0x_rest_api keys Manage API keys
albion_rest_api serve Start the API server
albion_rest_api keys Manage API keys
```

### Starting the server
Expand Down
2 changes: 1 addition & 1 deletion config/dev.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
log_dir = "./logs"
database_url = "sqlite:./data/st0x.db"
database_url = "sqlite:./data/albion.db"
registry_url = "https://raw.githubusercontent.com/rainlanguage/rain.strategies/5d0a11ad4a3e89531c922317b09216200ea7bdc0/registry"
rate_limit_global_rpm = 600
rate_limit_per_key_rpm = 60
Expand Down
8 changes: 4 additions & 4 deletions config/rest-api.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
log_dir = "/mnt/data/st0x-rest-api/logs"
database_url = "sqlite:///mnt/data/st0x-rest-api/st0x.db"
log_dir = "/mnt/data/albion-rest-api/logs"
database_url = "sqlite:///mnt/data/albion-rest-api/albion.db"
registry_url = "https://raw.githubusercontent.com/rainlanguage/rain.strategies/5d0a11ad4a3e89531c922317b09216200ea7bdc0/registry"
rate_limit_global_rpm = 600
rate_limit_per_key_rpm = 60
docs_dir = "/var/lib/st0x-docs"
local_db_path = "/mnt/data/st0x-rest-api/raindex.db"
docs_dir = "/var/lib/albion-docs"
local_db_path = "/mnt/data/albion-rest-api/raindex.db"
Loading
Loading