Skip to main content

Deployment

Alchemy makes it simple to deploy infrastructure to production. This guide covers deployment strategies, best practices, and CI/CD integration.

Basic Deployment

Deploy your application by running your alchemy.run.ts script:
This will:
  1. Create or update resources
  2. Save state to .alchemy/
  3. Display resource URLs and outputs

Deployment Phases

Alchemy supports three phases:

Up Phase (Default)

Create or update resources:

Read Phase

Read resource state without making changes:
Use read mode to inspect current infrastructure state.

Destroy Phase

Delete all resources:
This will permanently delete all resources in the current stage. Use with caution.

Stages

Stages allow you to deploy multiple independent environments (dev, staging, production):

Using Stages

Each stage has isolated state:

Environment-Specific Configuration

Use different configurations per stage:
alchemy.run.ts

State Management

Local State (Default)

By default, Alchemy stores state locally in .alchemy/:
Local state is fine for development, but use remote state stores for CI/CD and teams.

Remote State

For production and teams, use a remote state store:
When running in CI, Alchemy requires a remote state store. Set ALCHEMY_CI_STATE_STORE_CHECK=false to disable this check (not recommended).

Secrets Management

Setting Passwords

Secrets require a password for encryption:
Or set it programmatically:

Per-Stage Passwords

Use different passwords for different stages:

CI/CD Integration

GitHub Actions

GitLab CI

.gitlab-ci.yml

CircleCI

.circleci/config.yml

Deployment Strategies

Blue-Green Deployment

Deploy to a new stage, test, then switch:

Canary Deployment

Gradually roll out changes:

Rollback

Quick Rollback

Destroy the current deployment and redeploy a previous version:

State-Based Rollback

Alchemy maintains state history. You can manually restore previous state:

Monitoring Deployments

Deployment Logs

Alchemy logs all resource operations:

Quiet Mode

Suppress logs in CI:
Or programmatically:

Telemetry

Alchemy sends anonymous telemetry by default. Opt out:
Or:

Best Practices

Multi-Region Deployment

Deploy to multiple regions:

Troubleshooting

State Conflicts

If multiple deployments run simultaneously:
Solution: Use a state store with locking (CloudflareStateStore, S3StateStore).

Missing Credentials

Ensure all required environment variables are set:

Orphaned Resources

If resources aren’t cleaned up:
This forces a full reconciliation.

Example: Production Deployment

Next Steps