Skip to content

Commit ee4a03e

Browse files
committed
feat: Add fullstack Docusaurus CloudFront template
- Add modular Terraform infrastructure for Docusaurus on AWS - Support 4 authentication types: none, basic, cognito, ip - Add CloudFront Functions for Basic auth - Add Lambda@Edge for Cognito OAuth2 auth - Add AWS WAF for IP-based access control - Add Docusaurus static site template - Add mise configuration for version management (Terraform 1.9.8, Node.js 20) - Add GitHub Actions workflow for automated deployment - Add comprehensive documentation (README.md, MISE.md)
1 parent 25bbd90 commit ee4a03e

30 files changed

+2030
-0
lines changed

.github/workflows/deploy.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Deploy Docusaurus to S3 + CloudFront
2+
3+
on:
4+
# push:
5+
# branches:
6+
# - main
7+
# paths:
8+
# - 'docs-site/**'
9+
# - '.github/workflows/deploy.yml'
10+
workflow_dispatch:
11+
12+
permissions:
13+
id-token: write
14+
contents: read
15+
16+
jobs:
17+
deploy:
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
24+
- name: Setup Node.js
25+
uses: actions/setup-node@v4
26+
with:
27+
node-version: '20'
28+
cache: 'npm'
29+
cache-dependency-path: 'docs-site/package-lock.json'
30+
31+
- name: Install dependencies
32+
working-directory: docs-site
33+
run: npm ci
34+
35+
- name: Build Docusaurus site
36+
working-directory: docs-site
37+
run: npm run build
38+
39+
- name: Configure AWS credentials
40+
uses: aws-actions/configure-aws-credentials@v4
41+
with:
42+
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
43+
aws-region: ap-northeast-1
44+
45+
- name: Sync to S3
46+
working-directory: docs-site/build
47+
run: |
48+
aws s3 sync . s3://${{ secrets.AWS_S3_BUCKET }} \
49+
--delete \
50+
--cache-control "public, max-age=31536000, immutable" \
51+
--exclude "*.html" \
52+
--exclude "*.xml" \
53+
--exclude "*.json"
54+
55+
# HTML files with no cache
56+
aws s3 sync . s3://${{ secrets.AWS_S3_BUCKET }} \
57+
--cache-control "public, max-age=0, must-revalidate" \
58+
--content-type "text/html" \
59+
--exclude "*" \
60+
--include "*.html"
61+
62+
# XML and JSON files with short cache
63+
aws s3 sync . s3://${{ secrets.AWS_S3_BUCKET }} \
64+
--cache-control "public, max-age=3600" \
65+
--exclude "*" \
66+
--include "*.xml" \
67+
--include "*.json"
68+
69+
- name: Invalidate CloudFront cache
70+
run: |
71+
aws cloudfront create-invalidation \
72+
--distribution-id ${{ secrets.AWS_CLOUDFRONT_DISTRIBUTION_ID }} \
73+
--paths "/*"
74+
75+
- name: Deployment summary
76+
run: |
77+
echo " Deployment completed successfully!"
78+
echo "=� S3 Bucket: ${{ secrets.AWS_S3_BUCKET }}"
79+
echo "< CloudFront Distribution: ${{ secrets.AWS_CLOUDFRONT_DISTRIBUTION_ID }}"

.gitignore

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Dependencies
2+
node_modules/
3+
package-lock.json
4+
yarn.lock
5+
6+
# Production build
7+
build/
8+
dist/
9+
.docusaurus/
10+
.cache-loader/
11+
12+
# Terraform
13+
**/.terraform/
14+
**/.terraform.lock.hcl
15+
**/terraform.tfstate
16+
**/terraform.tfstate.backup
17+
**/terraform.tfvars
18+
**/lambda_build/
19+
**/lambda_function.zip
20+
21+
# Environment variables
22+
.env
23+
.env.local
24+
.env.*.local
25+
26+
# IDE
27+
.vscode/
28+
.idea/
29+
*.swp
30+
*.swo
31+
*~
32+
.DS_Store
33+
34+
# Logs
35+
npm-debug.log*
36+
yarn-debug.log*
37+
yarn-error.log*
38+
logs/
39+
*.log
40+
41+
# OS
42+
Thumbs.db
43+
.DS_Store
44+
45+
# mise
46+
.mise.local.toml

.mise.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# mise configuration for fullstack-docusaurus-cloudfront
2+
# https://mise.jdx.dev/
3+
4+
[tools]
5+
# Global tools
6+
terraform = "1.9.8"
7+
node = "20.18.0"
8+
9+
[env]
10+
# Environment variables
11+
_.file = ".env"

MISE.md

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
# mise Version Management Guide
2+
3+
This project uses [mise](https://mise.jdx.dev/) for managing tool versions (Terraform and Node.js).
4+
5+
## Why mise?
6+
7+
- **Consistent versions**: Ensure everyone uses the same Terraform 1.9.8 and Node.js 20
8+
- **Automatic switching**: Automatically use correct versions when entering directories
9+
- **Project isolation**: Different projects can use different versions
10+
- **Built-in tasks**: Run common commands with `mise run <task>`
11+
12+
## Installation
13+
14+
### macOS/Linux
15+
```bash
16+
curl https://mise.run | sh
17+
```
18+
19+
### Alternative: Homebrew (macOS)
20+
```bash
21+
brew install mise
22+
```
23+
24+
### Shell Setup
25+
26+
Add to your shell profile (`~/.bashrc`, `~/.zshrc`, etc.):
27+
28+
```bash
29+
eval "$(mise activate bash)" # for bash
30+
eval "$(mise activate zsh)" # for zsh
31+
```
32+
33+
## Quick Start
34+
35+
```bash
36+
# 1. Clone and enter project
37+
cd fullstack-docusaurus-cloudfront
38+
39+
# 2. Trust the mise configuration
40+
mise trust
41+
42+
# 3. Install all tools (Terraform + Node.js)
43+
mise install
44+
45+
# 4. Verify installation
46+
mise list
47+
# terraform 1.9.8
48+
# node 20.18.0
49+
```
50+
51+
## Configuration Files
52+
53+
### Root: `.mise.toml`
54+
- Global tools for the entire project
55+
- Terraform 1.9.8
56+
- Node.js 20.18.0
57+
58+
### `infra/.mise.toml`
59+
- Terraform-specific configuration
60+
- Useful tasks for infrastructure management
61+
62+
### `docs-site/.mise.toml`
63+
- Node.js-specific configuration
64+
- Useful tasks for Docusaurus development
65+
66+
## Using mise Tasks
67+
68+
### Infrastructure Tasks (from `infra/` directory)
69+
70+
```bash
71+
cd infra
72+
73+
# Initialize Terraform
74+
mise run init
75+
76+
# Plan infrastructure changes
77+
mise run plan
78+
79+
# Apply changes
80+
mise run apply
81+
82+
# Format Terraform files
83+
mise run fmt
84+
85+
# Install Lambda dependencies
86+
mise run lambda-install
87+
```
88+
89+
### Docusaurus Tasks (from `docs-site/` directory)
90+
91+
```bash
92+
cd docs-site
93+
94+
# Install dependencies
95+
mise run install
96+
97+
# Start development server
98+
mise run dev
99+
100+
# Build for production
101+
mise run build
102+
103+
# Type checking
104+
mise run typecheck
105+
```
106+
107+
## Using Tools Directly
108+
109+
mise ensures correct versions are used:
110+
111+
```bash
112+
# Terraform (automatically uses 1.9.8)
113+
cd infra/environments/dev
114+
terraform init
115+
terraform plan
116+
117+
# Node.js (automatically uses 20.18.0)
118+
cd docs-site
119+
npm install
120+
npm start
121+
```
122+
123+
## Explicit Execution with mise exec
124+
125+
Force use of mise-managed versions:
126+
127+
```bash
128+
# Explicit Terraform execution
129+
mise exec -- terraform init
130+
mise exec -- terraform plan
131+
132+
# Explicit npm execution
133+
mise exec -- npm install
134+
mise exec -- npm run build
135+
```
136+
137+
## Checking Current Versions
138+
139+
```bash
140+
# Show all installed tools
141+
mise list
142+
143+
# Show current directory's tool versions
144+
mise current
145+
146+
# Show tool installation path
147+
mise which terraform
148+
mise which node
149+
```
150+
151+
## Updating Tool Versions
152+
153+
Edit `.mise.toml` files and run:
154+
155+
```bash
156+
mise install
157+
```
158+
159+
Example:
160+
```toml
161+
[tools]
162+
terraform = "1.10.0" # Update to newer version
163+
node = "22.0.0" # Update to newer version
164+
```
165+
166+
## Troubleshooting
167+
168+
### Tools not found
169+
```bash
170+
# Reinstall tools
171+
mise install
172+
173+
# Check if mise is activated in shell
174+
which mise
175+
```
176+
177+
### Wrong version being used
178+
```bash
179+
# Check current versions
180+
mise current
181+
182+
# Ensure you've trusted the config
183+
mise trust
184+
185+
# Reload shell
186+
exec $SHELL
187+
```
188+
189+
### Task not found
190+
```bash
191+
# List all available tasks
192+
mise tasks
193+
194+
# Run from correct directory
195+
cd infra # for infrastructure tasks
196+
cd docs-site # for docusaurus tasks
197+
```
198+
199+
## Without mise
200+
201+
You can still use the project without mise by installing:
202+
- Terraform 1.9.8 manually
203+
- Node.js 20.18.0 manually
204+
205+
Just run commands directly without `mise run` or `mise exec`.
206+
207+
## References
208+
209+
- [mise Documentation](https://mise.jdx.dev/)
210+
- [mise GitHub](https://github.com/jdx/mise)
211+
- [Task Runner](https://mise.jdx.dev/tasks/)

README.md

7.7 KB
Binary file not shown.

docs-site/.mise.toml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# mise configuration for Docusaurus site
2+
# https://mise.jdx.dev/
3+
4+
[tools]
5+
node = "20.18.0"
6+
7+
[tasks.install]
8+
description = "Install dependencies"
9+
run = "npm install"
10+
11+
[tasks.dev]
12+
description = "Start development server"
13+
run = "npm start"
14+
15+
[tasks.build]
16+
description = "Build for production"
17+
run = "npm run build"
18+
19+
[tasks.serve]
20+
description = "Serve production build"
21+
run = "npm run serve"
22+
23+
[tasks.typecheck]
24+
description = "Run TypeScript type checking"
25+
run = "npm run typecheck"
26+
27+
[tasks.clean]
28+
description = "Clean build artifacts"
29+
run = "npm run clear"

0 commit comments

Comments
 (0)