|
| 1 | +# Deploying the UserClouds Docs Site |
| 2 | + |
| 3 | +This documentation explains how to deploy the UserClouds docs site to AWS using SST and GitHub Actions. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +This project uses: |
| 8 | + |
| 9 | +- Next.js for the documentation site |
| 10 | +- SST for infrastructure as code |
| 11 | +- AWS services (S3, CloudFront, Lambda) |
| 12 | +- GitHub Actions for CI/CD |
| 13 | + |
| 14 | +The site is primarily built statically with the `/api/search` endpoint running as a serverless function using Next.js API routes. |
| 15 | + |
| 16 | +## Prerequisites |
| 17 | + |
| 18 | +- Node.js 18 or later |
| 19 | +- pnpm |
| 20 | +- AWS account with appropriate credentials |
| 21 | +- GitHub repository access |
| 22 | + |
| 23 | +## Configuration |
| 24 | + |
| 25 | +### Environment Variables |
| 26 | + |
| 27 | +Create a `.env` file (for local development) with the following variables: |
| 28 | + |
| 29 | +``` |
| 30 | +# AWS region for deployment |
| 31 | +REGION=us-east-1 |
| 32 | +
|
| 33 | +# Optional: Custom domain name |
| 34 | +DOMAIN=yourdomain.com |
| 35 | +``` |
| 36 | + |
| 37 | +For GitHub Actions deployments, add these secrets to your repository: |
| 38 | + |
| 39 | +- `AWS_ACCESS_KEY_ID` |
| 40 | +- `AWS_SECRET_ACCESS_KEY` |
| 41 | +- `DOMAIN_NAME` (optional) |
| 42 | + |
| 43 | +### SST Configuration |
| 44 | + |
| 45 | +The deployment uses `sst.config.ts` in the project root, which defines: |
| 46 | + |
| 47 | +1. A Next.js site hosted on S3/CloudFront |
| 48 | +2. Configuration for serverless functions to handle API routes and dynamic content |
| 49 | +3. Any required resources (Buckets, etc.) |
| 50 | + |
| 51 | +## Local Development |
| 52 | + |
| 53 | +1. Install dependencies: |
| 54 | + |
| 55 | + ```bash |
| 56 | + pnpm install |
| 57 | + ``` |
| 58 | + |
| 59 | +2. Run the development server: |
| 60 | + |
| 61 | + ```bash |
| 62 | + pnpm dev |
| 63 | + ``` |
| 64 | + |
| 65 | +3. Test the SST deployment locally: |
| 66 | + ```bash |
| 67 | + pnpm sst:dev |
| 68 | + ``` |
| 69 | + |
| 70 | +## Deployment |
| 71 | + |
| 72 | +### Manual Deployment |
| 73 | + |
| 74 | +1. Build the Next.js site: |
| 75 | + |
| 76 | + ```bash |
| 77 | + pnpm build |
| 78 | + ``` |
| 79 | + |
| 80 | +2. Deploy using SST: |
| 81 | + ```bash |
| 82 | + pnpm sst:deploy --stage prod |
| 83 | + ``` |
| 84 | + |
| 85 | +To remove the deployment: |
| 86 | + |
| 87 | +```bash |
| 88 | +pnpm sst:remove --stage prod |
| 89 | +``` |
| 90 | + |
| 91 | +### GitHub Actions Deployment |
| 92 | + |
| 93 | +The project includes a GitHub Actions workflow in `.github/workflows/deploy.yml` that: |
| 94 | + |
| 95 | +1. Triggers on pushes to `main` and pull requests |
| 96 | +2. Installs dependencies |
| 97 | +3. Builds the Next.js site |
| 98 | +4. Deploys to AWS using SST |
| 99 | + |
| 100 | +For main branch deployments, it uses the production stage. For pull requests, it creates a temporary stage named `pr-{PR_NUMBER}`. |
| 101 | + |
| 102 | +## Architecture Details |
| 103 | + |
| 104 | +### Static Assets |
| 105 | + |
| 106 | +- Next.js static files are built using `pnpm build` |
| 107 | +- Static files are uploaded to an S3 bucket |
| 108 | +- CloudFront serves these files with appropriate caching |
| 109 | + |
| 110 | +### API Endpoint |
| 111 | + |
| 112 | +- The `/api/search` endpoint is implemented as a Next.js API route |
| 113 | +- The function is defined in `app/api/search/route.js` within the Next.js app |
| 114 | +- SST automatically deploys this route as a serverless function |
| 115 | +- The endpoint receives search queries and returns search results |
| 116 | + |
| 117 | +### Custom Domain (Optional) |
| 118 | + |
| 119 | +If a custom domain is provided: |
| 120 | + |
| 121 | +- SSL certificate is automatically provisioned |
| 122 | +- CloudFront distribution uses the custom domain |
| 123 | +- DNS records are created (if using Route 53) |
| 124 | + |
| 125 | +## Troubleshooting |
| 126 | + |
| 127 | +### Common Issues |
| 128 | + |
| 129 | +1. **Deployment fails with credential errors** |
| 130 | + |
| 131 | + - Ensure AWS credentials are correctly set up |
| 132 | + - Check that the IAM user has appropriate permissions |
| 133 | + |
| 134 | +2. **Custom domain not working** |
| 135 | + |
| 136 | + - Verify that the domain is correctly configured in your DNS provider |
| 137 | + - Check that the SSL certificate has been validated |
| 138 | + |
| 139 | +3. **API function timeout** |
| 140 | + - Increase the timeout setting for Next.js API routes in the SST configuration |
| 141 | + - Optimize the API route code for better performance |
| 142 | + - Consider implementing caching for frequently accessed search results |
| 143 | + |
| 144 | +### Getting Help |
| 145 | + |
| 146 | +If you encounter issues: |
| 147 | + |
| 148 | +1. Check the CloudWatch logs for the Lambda functions |
| 149 | +2. Review the CloudFormation events in the AWS console |
| 150 | +3. Refer to the [SST documentation](https://docs.sst.dev/) |
| 151 | + |
| 152 | +## Additional Resources |
| 153 | + |
| 154 | +- [SST Documentation](https://docs.sst.dev/) |
| 155 | +- [Next.js Documentation](https://nextjs.org/docs) |
| 156 | +- [AWS Lambda Documentation](https://docs.aws.amazon.com/lambda/) |
0 commit comments