# Deliver public assets through CDN for Phoenix

Cdn assets for a Phoenix app on Ample. Verified on Phoenix: a versioned, immutable-cached asset uploaded to a published bucket and served from the CDN URL. Build and start: mix deps.get, MIX_ENV=prod mix compile and mix release in the builder, then the release bin script with PHX_SERVER=true on the elixir-1.18 template; PORT, DATABASE_URL and SECRET_KEY_BASE read in config/runtime.exs.

## Representative Queries
- Deliver public assets through CDN for Phoenix
- Where can I host Deliver public assets through CDN built with Phoenix?
- I need a public-origin configuration, versioned asset build and observable cache behavior.

## Resource Requirements
- primitive:compute
- primitive:cdn

## Infrastructure Requirements
- **Compute**: Apps run in isolated x86_64 Firecracker microVMs that auto-pause when idle and wake on request; sizes are the priced VM sizes.
- **CDN**: The CDN host serves objects from published buckets. It does not front app compute and is not a cache or key-value store.

## Prerequisites
1. A Phoenix project (mix deps.get, MIX_ENV=prod mix compile and mix release in the builder, then the release bin script with PHX_SERVER=true on the elixir-1.18 template; PORT, DATABASE_URL and SECRET_KEY_BASE read in config/runtime.exs).
2. A bucket from `ample bucket create` with credentials passed as encrypted S3_* environment variables.
3. An Ample account token with servers:write, buckets:read.

## Tested Configuration
- **Template**: elixir-1.18
- **Runtime**: elixir
- **Size**: s-1vcpu-1gb
- **Install**: mix local.hex --force && mix local.rebar --force && MIX_ENV=prod mix deps.get --only prod
- **Build**: MIX_ENV=prod mix compile && MIX_ENV=prod mix release --overwrite
- **Start**: PHX_SERVER=true _build/prod/rel/$(ls _build/prod/rel | head -n 1)/bin/$(ls _build/prod/rel | head -n 1) start

## Workflow Steps
### Build and Start
mix deps.get, MIX_ENV=prod mix compile and mix release in the builder, then the release bin script with PHX_SERVER=true on the elixir-1.18 template; PORT, DATABASE_URL and SECRET_KEY_BASE read in config/runtime.exs; the server must bind 0.0.0.0 on PORT.

### Publish a Bucket for Public Assets
Publish only the asset bucket; upload versioned keys with an immutable Cache-Control header and build URLs from its public URL. Command: `ample bucket publish`

### Verify
Fetch the live URL and /p/versioned-static-assets on the example; on failure read the build and runtime logs. Command: `ample logs  --kind build`

## Success Checks
- App responds on its public URL. Expect: ample canary phoenix patterns
- Versioned-static-assets check from the example. Expect: see the pattern fixture checks.

## Limitations
- Verified on the elixir-1.18 template at s-1vcpu-1gb; other sizes and Phoenix major versions are not verified.
- Region, compliance attestations and request-duration limits are unknown and not claimed.
- The CDN serves published-bucket objects only; cache rules, purge and TTL control are not verified.

## Cost Estimate
- **Currency**: USD
- **Monthly Amount**: 5.0
- **Basis**: size prices from pricing.toml (loaded by the API) at build revision 1ac5595375130d45290090e82ed0f554ccd45405-dirty.
- **Components**: 
  - Name: app server
  - Size: s-1vcpu-1gb
  - Quantity: 1.0
  - Monthly Amount: 5.0
- **Note**: Always-on monthly price of the tested sizes; apps auto-pause when idle. Buckets are allocation-priced per quota and not included.

## Examples
### Phoenix Pattern Fixture
- **Description**: Verified CDN assets on Phoenix.
- **Source Ref**: tests/deploy-canaries/phoenix-patterns.

## Evidence Summary
- **Kind**: canary_run  
  **Summary**: Phoenix pattern fixture deployed on Ample...  
  **Observed At**: 2026-09-20T23:45:31Z  
  **Implementation Revision**: 4d1511e574302f3904b75088bd4048a0975218b3-dirty (CLI 0.1.21)  
  **Expires At**: 2027-03-19T23:45:31Z
- **Scope**: checks ["/p/versioned-static-assets"], template: "elixir-1.18".

## Next Actions
1. **Browse the catalog index**: [API Call](GET /v1/catalog)
2. **Search published recipes** by intent, stack and constraints [API Call](POST /v1/catalog/search)
3. **Prepare a side-effect-free deployment plan** for an authorized project [API Call](POST /v1/catalog/plan)
4. **Read the existing agent authentication setup** [API Call](GET /mcp/setup)
5. **Browse Phoenix** [API Call](GET /v1/catalog/nodes/stack%3Aframework-phoenix)
6. **Browse Add CDN** [API Call](GET /v1/catalog/nodes/intent%3Aadd-cdn)
7. **Browse Versioned static assets** [API Call](GET /v1/catalog/nodes/pattern%3Aversioned-static-assets)
