배포 가이드
SCF를 사용하여 static site를 효과적으로 배포하고 관리하는 방법을 알아보세요.
기본 배포
하나의 명령으로 사이트를 배포하세요:
bash
# 기본 배포 (scf.config.ts 사용)
npx scf-deploy deploy증분 배포
SCF는 기본적으로 증분 배포를 수행합니다. 파일 해시를 비교하여 변경된 파일만 업로드합니다.
장점:
- 더 빠른 배포
- S3 비용 절감
- 대역폭 사용량 감소
전체 재배포가 필요한 경우:
bash
# 전체 재배포 강제
npx scf-deploy deploy --forceEnvironment별 배포
--env 옵션으로 환경별 설정을 사용합니다:
bash
# 개발 환경
npx scf-deploy deploy --env dev
# 스테이징 환경
npx scf-deploy deploy --env staging
# 프로덕션 환경
npx scf-deploy deploy --env prod설정 파일에서 환경별 오버라이드:
typescript
import { defineConfig } from 'scf-deploy';
export default defineConfig({
app: 'my-static-site',
region: 'ap-northeast-2',
s3: {
bucketName: 'my-site-dev',
buildDir: './dist',
},
cloudfront: {
enabled: true,
priceClass: 'PriceClass_100',
},
environments: {
dev: {
s3: { bucketName: 'my-site-dev' },
cloudfront: { enabled: false },
},
staging: {
s3: { bucketName: 'my-site-staging' },
},
prod: {
s3: { bucketName: 'my-site-prod' },
cloudfront: {
priceClass: 'PriceClass_All',
customDomain: {
domainName: 'www.example.com',
},
},
},
},
});Cache Invalidation
CloudFront는 성능을 위해 콘텐츠를 캐시합니다. SCF는 배포 후 자동으로 캐시를 무효화합니다.
bash
# 기본 배포 (자동 캐시 무효화 포함)
npx scf-deploy deploy
# 캐시 무효화 건너뛰기
npx scf-deploy deploy --skip-cache상태 복구
상태 파일을 잃어버린 경우, AWS에서 기존 리소스를 검색하여 복구할 수 있습니다:
bash
# 상태 파일 복구
npx scf-deploy recover
# 모든 SCF 관리 리소스 검색
npx scf-deploy recover --all리소스 삭제
배포된 AWS 리소스를 삭제합니다:
bash
# 리소스 삭제 (확인 프롬프트)
npx scf-deploy remove
# 확인 없이 강제 삭제
npx scf-deploy remove --force
# 특정 리소스만 유지
npx scf-deploy remove --keep-bucket
npx scf-deploy remove --keep-distribution모범 사례
1. 버전 관리 사용
설정을 커밋하세요:
bash
git add scf.config.ts
git commit -m "Add SCF configuration"2. State File 무시
.gitignore에 추가:
gitignore
# SCF state file
.deploy/
*.deploy.json3. 환경 변수 사용
민감한 정보는 환경 변수로 관리:
bash
# 환경 변수 설정
export AWS_ACCESS_KEY_ID=your-access-key
export AWS_SECRET_ACCESS_KEY=your-secret-key
# 또는 AWS 프로필 사용
npx scf-deploy deploy --profile my-aws-profileCI/CD 통합
GitHub Actions
yaml
name: Deploy to AWS
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- name: Install dependencies
run: npm install
- name: Build
run: npm run build
- name: Deploy to AWS
run: npx scf-deploy deploy --env prod
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}보안: AWS 자격 증명을 GitHub Secrets에 저장하세요.
GitLab CI
yaml
deploy:
stage: deploy
image: node:18
script:
- npm install
- npm run build
- npx scf-deploy deploy --env prod
only:
- main
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY배포 옵션 요약
| 옵션 | 설명 |
|---|---|
--env <name> | 환경 이름 |
--config <path> | 설정 파일 경로 |
--profile <name> | AWS 프로필 |
--dry-run | 미리보기 모드 |
--force | 전체 재배포 |
--no-cloudfront | CloudFront 건너뛰기 |
--skip-cache | 캐시 무효화 건너뛰기 |
--skip-build | 자동 빌드 건너뛰기 |