Skip to content

๐Ÿ“ธ [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ํŒŒ์ผ์ด๋ผ๊ณ  ์ƒ๊ฐํ•˜๋ฉด ๋  ๋“ฏ ํ•ฉ๋‹ˆ๋‹ค
  • 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 : ๋ฐฐํฌ๋œ ํŒŒ์ผ ์ค‘ ์—†๋Š” ํŒŒ์ผ์ด ์žˆ๋‹ค๋ฉด ์ง€์šฐ๊ธฐ
  • name: CloudFront Invalidate Cache

    • run: aws cloudfront create-invalidation --distribution-id AWS_CLOUDFRONT_DISTRIBUTION_ID --paths '/*'
      • cloudFront ๊ฐ์ฒด ๋ฌดํšจํ™” ํ•˜๊ธฐ
        • ์ด๋ ‡๊ฒŒ ํ•ด์•ผ ๋ณ€ํ™”๋ฅผ ๋ฐ”๋กœ ์ธ์‹ํ•ด์„œ ๋ฐฐํฌ๋ฅผ ๋ฐ”๋กœ ์ ์šฉ ์‹œํ‚ฌ ์ˆ˜ ์žˆ๋‹ค.

์ฐธ๊ณ 

๐ŸŒˆWelcome to the 42arcade.gg.client wiki!๐ŸŒˆ

๐Ÿ—ฃ ํšŒ์˜๋ก

๐Ÿค Team Rule

๐Ÿ“Œ ์„ค๊ณ„

๐Ÿงฉ ๋ฌธ์ œ ํ•ด๊ฒฐ

๐Ÿ’ช ๊ณต๋ถ€ ์ž๋ฃŒ

Clone this wiki locally