-
Notifications
You must be signed in to change notification settings - Fork 8
๐ธ [s3 cloudFront github action] ๋ฐฐํฌ ์๋ํ ๋งค๋ด์ผ ๐ธ
kipark edited this page Jul 7, 2022
·
1 revision
- ๋ฐฐํฌ ๋ฐฉ๋ฒ
- ๋ฐฐํฌ ๋ฐฉ๋ฒ์ workflowํ์ผ์ ํธ๋ฆฌ๊ฑฐ ๋ถ๋ถ์ ๋จผ์ ํ์ธํ๋ค.
- on: push: branches: - deploy
- ํธ๋ฆฌ๊ฑฐ ๋ฐฉ๋ฒ์ ๋ง์ถฐ์ ๊น ํ๋ธ ์ด๋ฒคํธ๋ฅผ ์ฃผ๋ฉด ๋๋ค
- ์ง๊ธ๊ณผ ๊ฐ์ ๊ฒฝ์ฐ๋ push branches : deploy ๋ก ๋์ด ์์ผ๋ deploy์ Push๊ฐ ๋๋ฉด ์๋์ผ๋ก github Action ์ผ๋ก ๋ค์ด๊ฐ workFlow๊ฐ ์๋๋๋ค.
- ๋ฐฐํฌ ํ์ธ
- github Action ํ์ด์ง๋ก ๊ฐ๋ฉด ์ง๊ธ๊น์ง ํด์จ workFlow๋ฅผ ๋ณผ ์ ์๋ค.
- ๋ํ ๊ฐ workFlow๋ก ๋ค์ด๊ฐ๋ฉด ํ๋ก์ธ์ค๋ก ๋ฐฐํฌ๊ฐ ๋์๋์ง๋ฅผ ํ์ธํ ์ ์๋ค
-
๋ฐฐํฌ ์๋ํ
-
๋ฐฐํฌ ์๋ํ ํ ๋ ํฌ์งํ ๋ฆฌ์ ์ต์์ ํด๋์ .
github/workflows
ํด๋๋ฅผ ๋ง๋ค๊ธฐ -
workflowsํด๋ ์์ main-deploy.yml ํ์ผ์ ๋ง๋ ๋ค
-
๋ฐฐํฌ ์๋ํ ํ ์ฝ๋๋ฅผ ๊ตฌ์ฑํ๋ค
name: Deploy to 42ggClientS3 on: push: branches: - deploy jobs: continuous-deployment: runs-on: macos-12 steps: - name: Git Checkout uses: actions/checkout@v2 - name: Use Node.js version 16.x uses: actions/setup-node@v1 with: node-version: 16.x - name: Build env: NEXT_PUBLIC_SERVER_ENDPOINT: ${{ secrets.NEXT_PUBLIC_SERVER_ENDPOINT }} NEXT_PUBLIC_GOOGLE_ANALYTICS: ${{ secrets.NEXT_PUBLIC_GOOGLE_ANALYTICS }} GENERATE_SOURCEMAP: ${{ secrets.GENERATE_SOURCEMAP }} run: | npm install npm run build - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v1 with: aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} aws-region: ${{ secrets.AWS_BUCKET_REGION }} - name: Deploy to S3 run: aws s3 sync ./${{ secrets.BUILD_DIRECTORY }} ${{ secrets.AWS_BUCKET_NAME }} --acl public-read --delete - name: CloudFront Invalidate Cache run: aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CLOUDFRONT_DISTRIBUTION_ID }} --paths '/*'
-
ํ์ฌ ๋ฐฐํฌ ์๋ํ ์ฝ๋๋ ๋ค์ ๊ณผ ๊ฐ๋ค.
on: push: branches: - deploy
- workFlow ์คํ ํธ๋ฆฌ๊ฑฐ๋ฅผ deploy ๋ธ๋์น์ push๊ฐ ๋๋ฉด ์คํํ๊ฒ ๊ตฌ์ฑ
jobs: continuous-deployment: runs-on: macos-12 steps: - name: Git Checkout uses: actions/checkout@v2 - name: Use Node.js version 16.x uses: actions/setup-node@v1 with: node-version: 16.x - name: Build env: NEXT_PUBLIC_SERVER_ENDPOINT: ${{ secrets.NEXT_PUBLIC_SERVER_ENDPOINT }} NEXT_PUBLIC_GOOGLE_ANALYTICS: ${{ secrets.NEXT_PUBLIC_GOOGLE_ANALYTICS }} GENERATE_SOURCEMAP: ${{ secrets.GENERATE_SOURCEMAP }} run: | npm install npm run build - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v1 with: aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} aws-region: ${{ secrets.AWS_BUCKET_REGION }} - name: Deploy to S3 run: aws s3 sync ./${{ secrets.BUILD_DIRECTORY }} ${{ secrets.AWS_BUCKET_NAME }} --acl public-read --delete - name: CloudFront Invalidate Cache run: aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CLOUDFRONT_DISTRIBUTION_ID }} --paths '/*'
-
-
-
runs-on : macos-12
- workFlow๋ฅผ ์คํ ํ ์๋ฒ์ ํ๊ฒฝ์ ์ง์ ํด์ค๋ค
- ๋ค๋ฅธ ์ต์
์ผ๋ก
ubuntu-latest
๊ฐ์ ์ต์ ์ด ์๋ค
-
name: Use Node.js version 16.x uses: actions/setup-node@v1 with: node-version: 16.x
- ๋ ธ๋๋ฅผ ๋ค์ด๋ก๋ ๋ฐ๋๋ค node-version๋ ๊ฐ๋ฐ ํ๊ฒฝ์ ๋ง์ถฐ์ ๋ณ๊ฒฝํ๊ธฐ
-
name: Build env : โฆ run: | npm install npm run build
- env:
- build๋ฅผ ํ ๋ ํ์ํ env ํ์ผ ๋ค์ ์ธํ ํด์ค๋ค github secret์ด๋ผ๋ ๊ธฐ๋ฅ์ด ์๋๋ฐ ๋ ํฌ์งํ ๋ฆฌ ์ธํ ์ ๋ค์ด๊ฐ๋ฉด ํ์ธํ ์ ์๋ค ๋ ํฌ envํ์ผ์ด๋ผ๊ณ ์๊ฐํ๋ฉด ๋ ๋ฏ ํฉ๋๋ค
- env:
-
name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v1 with: โฆ
- aws ๊ณ์ ๊ณผ ์ฐ๊ฒฐํด์ค๋๋ค
- aws๋ IAM์ ์๋ ๊ณ์ ์ผ๋ก s3๋ฒํท ๊ฐ์ ์ธ์คํด์ค๋ค์ ์ปจํธ๋กค ํ ์ ์๋ค ๊ทธ ๊ณ์ ๊ณผ ์ฐ๊ฒฐํ๋ ๋ถ๋ถ
- ๊ณ์ ์ access key๋ฅผ ๋ฐ์์ ์์ฑํด์ฃผ๊ธฐ
-
name: Deploy to S3
- run: aws s3 sync [๋ฐฐํฌ ํ ํ์ผ ํด๋ ์์น] [aws ๋ฒํท ์ด๋ฆ] --acl public-read --delete
- aws s3 sync ๋ช ๋ น์ด๋ฅผ ์ฌ์ฉํด์ ํ์ผ์ ๋ฐฐํฌ
- acl public-read : ๋ฐฐํฌ๋ ํ์ผ์ ๋ชจ๋ user๊ฐ ์ฝ์ ์ ์๋ค
- โdelete : ๋ฐฐํฌ๋ ํ์ผ ์ค ์๋ ํ์ผ์ด ์๋ค๋ฉด ์ง์ฐ๊ธฐ
- run: aws s3 sync [๋ฐฐํฌ ํ ํ์ผ ํด๋ ์์น] [aws ๋ฒํท ์ด๋ฆ] --acl public-read --delete
-
name: CloudFront Invalidate Cache
- run: aws cloudfront create-invalidation --distribution-id AWS_CLOUDFRONT_DISTRIBUTION_ID --paths '/*'
- cloudFront ๊ฐ์ฒด ๋ฌดํจํ ํ๊ธฐ
- ์ด๋ ๊ฒ ํด์ผ ๋ณํ๋ฅผ ๋ฐ๋ก ์ธ์ํด์ ๋ฐฐํฌ๋ฅผ ๋ฐ๋ก ์ ์ฉ ์ํฌ ์ ์๋ค.
- cloudFront ๊ฐ์ฒด ๋ฌดํจํ ํ๊ธฐ
- run: aws cloudfront create-invalidation --distribution-id AWS_CLOUDFRONT_DISTRIBUTION_ID --paths '/*'