1
0
mirror of git://f0xx.org/android_cast synced 2026-07-29 05:58:14 +03:00
This commit is contained in:
Anton Afanasyeu
2026-06-11 22:45:47 +02:00
parent f878700a0c
commit fef93d7cdc
23 changed files with 831 additions and 97 deletions

View File

@@ -2,65 +2,63 @@
**Topology:** same as [INFRA.md](../../docs/INFRA.md) — TLS on Gentoo FE, app on Alpine BE `:80`.
## Prerequisites (confirmed)
## Prerequisites
| Item | Status |
|------|--------|
| DNS `s.f0xx.org` → FE | PO |
| FE TLS cert | `/etc/letsencrypt/live/s.f0xx.org/` |
| Git remote | `git://f0xx.org/androicast_project/url-shortener` |
| MariaDB schema `url_shortener` | `sql/schema.mariadb.sql` |
| DB app user | **`androidcast`** (shared with crash reporter; same password as `androidcast_crashes` in crashes `config.php`) |
| DNS `s.f0xx.org` → FE | Done |
| FE TLS + BE nginx | Done |
| MariaDB `url_shortener` | Done |
| DB user | **`androidcast`** (same password as crashes `config.php`) |
## MariaDB (BE)
**Database:** `url_shortener`
**App user:** `androidcast` @ `localhost` + `127.0.0.1`**same password** as crash reporter (`examples/crash_reporter/backend/config/config.php``db.mysql.password`).
## Sync to BE
```bash
# 1) Schema (root)
mysql -u root -p < sql/schema.mariadb.sql
# From dev machine (example — adjust paths)
rsync -av backend/url-shortener/ alpine-be:/var/www/localhost/htdocs/apps/s/
# 2) Grants for existing androidcast user (root) — skip if already granted
./scripts/init-mariadb-grants.sh
# On BE
cp /var/www/localhost/htdocs/apps/s/config/config.example.php \
/var/www/localhost/htdocs/apps/s/config/config.php
# set db.mysql.password = same as crash reporter
# 3) Config on BE
cp config/config.example.php config/config.php
# edit password to match crashes config (do not commit config.php)
# 4) Smoke
mysql -u androidcast -p -h 127.0.0.1 url_shortener -e 'SHOW TABLES;'
apk add libqrencode-tools # QR PNG (/api/v1/qr/…)
rc-service php-fpm81 restart
```
Template: [config/config.example.php](config/config.example.php)
## MariaDB (one-time)
```bash
mysql -u root -p < sql/schema.mariadb.sql
./scripts/init-mariadb-grants.sh
php scripts/seed_bearer.php --label=prod # save printed bearer token
```
Optional cron (purge expired links + audit >90d):
```cron
0 4 * * * php81 /var/www/localhost/htdocs/apps/s/scripts/purge_url_shortener.php
```
## FE (Gentoo)
Add `deploy/nginx.fe-s.f0xx.org.snippet` inside a new `server { listen 443 ssl; server_name s.f0xx.org; }` block
(mirror `apps.f0xx.org` TLS paths; cert paths above).
See [deploy/nginx.fe-s.f0xx.org.snippet](deploy/nginx.fe-s.f0xx.org.snippet) — full URI → BE `:80`.
```bash
nginx -t && rc-service nginx reload
```
## BE nginx
## BE (Alpine)
See [deploy/nginx.be-url-shortener.fragment](deploy/nginx.be-url-shortener.fragment).
1. Sync this tree to docroot (suggested): `/var/www/localhost/htdocs/apps/s/`
2. Include `deploy/nginx.be-url-shortener.fragment` in `apps.conf` **or** dedicated `server_name` on BE
3. Apply SQL migration
4. `rc-service php-fpm81 restart` if needed
```bash
nginx -t && rc-service nginx reload
```
**Alpine/nginx note:** regex locations with `{n,m}` quantifiers must be **double-quoted** or nginx parses `{` as a block delimiter (`nginx: [emerg] improper regexp`).
**Quoted regex required:** `location ~ "^/[a-f0-9]{6,16}$"`
## Verify
```bash
curl -sSI https://s.f0xx.org/api/v1/health
./scripts/smoke_shorten.sh
curl -fsS https://s.f0xx.org/api/v1/health
export BEARER='…' ./scripts/smoke_shorten.sh
./scripts/demo_curl.sh
examples/crash_reporter/backend/scripts/validate_be_services.sh
```
Not added to `validate_be_services.sh` until first production deploy (SPEC).
## Config
[config/config.example.php](config/config.example.php) — prefer **`socket`** `/run/mysqld/mysqld.sock` on Alpine (same as crashes when TCP refused).