///
Aruuri leverages a sophisticated deployment strategy centered around **fully ephemeral preview environments**. This system is designed to provide complete isolation for each development branch, ensuri
236 views
~236 views from guests
Guest views are estimated from total page views. These include anonymous visitors and users who weren't logged in when they viewed the page.
Aruuri leverages a sophisticated deployment strategy centered around fully ephemeral preview environments. This system is designed to provide complete isolation for each development branch, ensuring high-fidelity testing while maintaining operational efficiency and cost control.
The ephemeral preview system is built on four key principles:
42 would be accessible at https://preview-pr-42.aruuri.so.The ephemeral preview architecture is orchestrated using SST v3 (Serverless Stack Toolkit), which simplifies the deployment and management of serverless applications on AWS. Cloudflare is used for DNS management to handle custom domains for each stage.
Here's how these technologies work together:
removal: 'remove' configuration for non-production stages is critical for automatic cleanup.apps/web) is deployed as a serverless application using AWS Lambda and S3 for static assets, managed by SST's sst.aws.Nextjs construct.aruuri-{stage}-mediabucket-*) to store media uploads and static content, configured for CloudFront access.aruuri.so) to route traffic to the correct CloudFront distributions and Next.js applications, enabling custom preview-pr-*.aruuri.so domains.The following configuration files illustrate how the ephemeral preview system is set up:
sst.config.ts: This is the central SST configuration file.
aruuri) and the AWS region (eu-west-2).protect: isProtectedStage and removal: isProtectedStage ? 'retain' : 'remove' are used to ensure that only production and dev stages retain resources, while all other stages (including previews) have their resources automatically removed on deletion.packages/infrastructure/ to create the Next.js app, media CDN, storage, and domain configuration based on the deployment stage.mediaDistribution, mediaOAC, uploadBucket) to SST, allowing the toolkit to track and manage their lifecycle for proper cleanup ordering.packages/infrastructure/domains.ts: The getDomainConfig function dynamically determines the domain for each stage:
production uses aruuri.so with www.aruuri.so redirect.dev uses dev.aruuri.so.preview-{stage}.aruuri.so, ensuring a unique and predictable URL for each pull request. This configuration uses sst.cloudflare.dns to manage the DNS records within Cloudflare.packages/infrastructure/storage.ts: The createMediaStorage function creates an S3 bucket for media files:
new sst.aws.Bucket(${RESOURCE_IDS.MEDIA_BUCKET}-${stage}, { access: 'cloudfront' }) ensures that each stage (production, dev, pr-123) receives its own isolated S3 bucket.access: 'cloudfront' property automatically configures the necessary bucket policy, granting CloudFront the s3:GetObject permission via an Origin Access Control (OAC).packages/infrastructure/cdn.ts: The createMediaCDN function sets up the CloudFront Content Delivery Network:
aws.cloudfront.OriginAccessControl (OAC) and links it to the S3 bucket created in storage.ts. This secure setup prevents direct public access to the S3 bucket.aws.cloudfront.Distribution is created with comment: Media CDN for ${stage} stage for easy identification.defaultCacheBehavior uses CACHE_POLICY.CACHING_OPTIMIZED for efficient static media delivery and viewerProtocolPolicy: 'redirect-to-https' for security.mediaDistribution and mediaOAC are explicitly returned by sst.config.ts to SST. This ensures that SST correctly tracks their dependencies and deletes the CloudFront distribution before the OAC during cleanup, preventing OriginAccessControlInUse errors.packages/infrastructure/app.ts: The createNextjsApp function deploys the main Next.js web application (apps/web):
sst.aws.Nextjs resource, passing the dynamically generated domain configuration.ARUURI_*_DATABASE_URL*), CLOUDFRONT_MEDIA_URL, PAYLOAD_SECRET, and S3 configuration, are injected, ensuring that each instance runs with the correct stage-specific settings.uploadBucket is linked to the Next.js application, allowing it to interact with the stage-specific S3 storage.All preview environments follow a consistent URL pattern:
https://preview-pr-{number}.aruuri.so
Where {number} corresponds to the GitHub Pull Request number.
Aruuri provides a suite of pnpm scripts to manage deployments and ephemeral environments:
pnpm run deploy: Deploys the application to the production stage.pnpm run deploy:dev: Deploys to the dev stage.pnpm run deploy:preview <stage-name>: Deploys to a specific preview stage. This is typically run in CI/CD pipelines when a PR is opened, using sst deploy --stage pr-{number}.pnpm run remove:dev: Removes the dev stage deployment.pnpm run remove:previews [stage1] [stage2] ... or pnpm run remove:previews --all-previews: This powerful script (scripts/remove-previews.ts) is designed to remove specific preview environments or all active pr-* stages.
sst unlock and then sst remove the stage.CloudFront OAC blocking removal errors. If such an error occurs, it executes the scripts/cleanup-cloudfront-distributions.ts script to disable and delete the stubborn CloudFront distributions before retrying the sst remove command.pnpm run cleanup:cloudfront <stage>: A dedicated utility script (scripts/cleanup-cloudfront-distributions.ts) to manually force the removal of CloudFront distributions for a given stage, especially useful in cases where SST's automatic cleanup might get stuck due to CloudFront's slow propagation times.During early development, all Aruuri environments (local, preview, production) are protected with a password-based login form. This is a temporary measure for security and will be removed before public launch.
SITE_PASSWORD environment variable..env.local file or managed with Doppler.SITE_PASSWORD must be configured in GitHub Secrets for CI/CD.apps/web/src/middleware.ts file intercepts requests to enforce this password protection, redirecting unauthenticated users to a /login page. It also supports Basic Auth headers for automated testing (e.g., Playwright).This comprehensive ephemeral preview system allows Aruuri to maintain a rapid development pace, ensure high code quality through isolated testing, and manage cloud infrastructure costs effectively.