local-infra: local, sandboxed atmosphere infra #684

closed
opened by boltless.me targeting master from sandboxed-atmosphere
+54
local-infra/Caddyfile
···
+
{
+
storage file_system /data/
+
debug
+
pki {
+
ca localtangled {
+
name "LocalTangledCA"
+
}
+
}
+
}
+
+
plc.tngl.boltless.dev {
+
tls {
+
issuer internal {
+
ca localtangled
+
}
+
}
+
reverse_proxy http://plc:8080
+
}
+
+
*.pds.tngl.boltless.dev, pds.tngl.boltless.dev {
+
tls {
+
issuer internal {
+
ca localtangled
+
}
+
}
+
reverse_proxy http://pds:3000
+
}
+
+
jetstream.tngl.boltless.dev {
+
tls {
+
issuer internal {
+
ca localtangled
+
}
+
}
+
reverse_proxy http://jetstream:6008
+
}
+
+
knot.tngl.boltless.dev {
+
tls {
+
issuer internal {
+
ca localtangled
+
}
+
}
+
reverse_proxy http://localhost:6000
+
}
+
+
spindle.tngl.boltless.dev {
+
tls {
+
issuer internal {
+
ca localtangled
+
}
+
}
+
reverse_proxy http://localhost:6555
+
}
+78
local-infra/docker-compose.yml
···
+
name: tangled-local-infra
+
services:
+
caddy:
+
container_name: caddy
+
image: caddy:2
+
depends_on:
+
- pds
+
restart: unless-stopped
+
cap_add:
+
- NET_ADMIN
+
ports:
+
- "80:80"
+
- "443:443"
+
- "443:443/udp"
+
volumes:
+
- ./Caddyfile:/etc/caddy/Caddyfile
+
- caddy_data:/data
+
- caddy_config:/config
+
+
plc:
+
image: ghcr.io/bluesky-social/did-method-plc:plc-f2ab7516bac5bc0f3f86842fa94e996bd1b3815b
+
# did-method-plc only provides linux/amd64
+
platform: linux/amd64
+
container_name: plc
+
restart: unless-stopped
+
ports:
+
- "4000:8080"
+
depends_on:
+
- plc_db
+
environment:
+
DEBUG_MODE: 1
+
LOG_ENABLED: "true"
+
LOG_LEVEL: "debug"
+
LOG_DESTINATION: 1
+
DB_CREDS_JSON: &DB_CREDS_JSON '{"username":"pg","password":"password","host":"plc_db","port":5432}'
+
DB_MIGRATE_CREDS_JSON: *DB_CREDS_JSON
+
PLC_VERSION: 0.0.1
+
PORT: 8080
+
+
plc_db:
+
image: postgres:14.4-alpine
+
container_name: plc_db
+
environment:
+
- POSTGRES_USER=pg
+
- POSTGRES_PASSWORD=password
+
- PGPORT=5432
+
volumes:
+
- plc:/var/lib/postgresql/data
+
+
pds:
+
container_name: pds
+
image: ghcr.io/bluesky-social/pds:0.4
+
restart: unless-stopped
+
ports:
+
- "4001:3000"
+
volumes:
+
- pds:/pds
+
env_file:
+
- ./pds.env
+
+
jetstream:
+
container_name: jetstream
+
image: ghcr.io/bluesky-social/jetstream:sha-0ab10bd
+
restart: unless-stopped
+
volumes:
+
- jetstream:/data
+
environment:
+
- JETSTREAM_DATA_DIR=/data
+
# livness check interval to restart when no events are received (default: 15sec)
+
- JETSTREAM_LIVENESS_TTL=300s
+
- JETSTREAM_WS_URL=ws://pds:3000/xrpc/com.atproto.sync.subscribeRepos
+
+
volumes:
+
caddy_config:
+
caddy_data:
+
plc:
+
pds:
+
jetstream:
+17
local-infra/pds.env
···
+
PDS_JWT_SECRET=8cae8bffcc73d9932819650791e4e89a
+
PDS_ADMIN_PASSWORD=d6a902588cd93bee1af83f924f60cfd3
+
PDS_PLC_ROTATION_KEY_K256_PRIVATE_KEY_HEX=2e92e336a50a618458e1097d94a1db86ec3fd8829d7735020cbae80625c761d7
+
+
LOG_ENABLED=true
+
+
# PDS_BSKY_APP_VIEW_DID=did:web:api.bsky.app
+
# PDS_BSKY_APP_VIEW_URL=https://api.bsky.app
+
+
PDS_DATA_DIRECTORY=/pds
+
PDS_BLOBSTORE_DISK_LOCATION=/pds/blocks
+
+
# PDS_DID_PLC_URL=http://plc:8080
+
PDS_HOSTNAME=pds.tngl.boltless.dev
+
+
# PDS_REPORT_SERVICE_DID=did:plc:ar7c4by46qjdydhdevvrndac
+
# PDS_REPORT_SERVICE_URL=https://mod.bsky.app
+14
local-infra/readme.md
···
+
run compose
+
```
+
docker compose up -d
+
```
+
+
copy the self-signed certificate to host machine
+
```
+
docker cp caddy:/data/pki/authorities/localtangled/root.crt localtangled.crt
+
```
+
+
trust the cert (macOS)
+
```
+
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ./localtangled.crt
+
```
+63
local-infra/scripts/create-test-account.sh
···
+
#!/bin/bash
+
set -o errexit
+
set -o nounset
+
set -o pipefail
+
+
source "$(dirname "$0")/../pds.env"
+
+
# curl a URL and fail if the request fails.
+
function curl_cmd_get {
+
curl --fail --silent --show-error "$@"
+
}
+
+
# curl a URL and fail if the request fails.
+
function curl_cmd_post {
+
curl --fail --silent --show-error --request POST --header "Content-Type: application/json" "$@"
+
}
+
+
# curl a URL but do not fail if the request fails.
+
function curl_cmd_post_nofail {
+
curl --silent --show-error --request POST --header "Content-Type: application/json" "$@"
+
}
+
+
USERNAME="${1:-}"
+
+
if [[ "${USERNAME}" == "" ]]; then
+
read -p "Enter a username: " USERNAME
+
fi
+
+
if [[ "${USERNAME}" == "" ]]; then
+
echo "ERROR: missing USERNAME parameter." >/dev/stderr
+
echo "Usage: $0 ${SUBCOMMAND} <USERNAME>" >/dev/stderr
+
exit 1
+
fi
+
+
PASSWORD="password"
+
INVITE_CODE="$(curl_cmd_post \
+
--user "admin:${PDS_ADMIN_PASSWORD}" \
+
--data '{"useCount": 1}' \
+
"https://${PDS_HOSTNAME}/xrpc/com.atproto.server.createInviteCode" | jq --raw-output '.code'
+
)"
+
RESULT="$(curl_cmd_post_nofail \
+
--data "{\"email\":\"${USERNAME}@${PDS_HOSTNAME}\", \"handle\":\"${USERNAME}.${PDS_HOSTNAME}\", \"password\":\"${PASSWORD}\", \"inviteCode\":\"${INVITE_CODE}\"}" \
+
"https://${PDS_HOSTNAME}/xrpc/com.atproto.server.createAccount"
+
)"
+
+
DID="$(echo $RESULT | jq --raw-output '.did')"
+
if [[ "${DID}" != did:* ]]; then
+
ERR="$(echo ${RESULT} | jq --raw-output '.message')"
+
echo "ERROR: ${ERR}" >/dev/stderr
+
echo "Usage: $0 <EMAIL> <HANDLE>" >/dev/stderr
+
exit 1
+
fi
+
+
echo
+
echo "Account created successfully!"
+
echo "-----------------------------"
+
echo "Handle : ${USERNAME}.${PDS_HOSTNAME}"
+
echo "DID : ${DID}"
+
echo "Password : ${PASSWORD}"
+
echo "-----------------------------"
+
echo "This is a test account with an insecure password."
+
echo "Make sure it's only used for development."
+
echo