๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ‘ฉ‍๐Ÿ’ป Learn programming

[AWS/GIT] GitHub Action์„ ์ด์šฉํ•œ ์ž๋™ ๋ฐฐํฌ ๋งŒ๋“ค๊ธฐ - ํ”„๋ก ํŠธ

by ๋ฐ๊ตฅ์ž‰ 2022. 4. 26.
๋ฐ˜์‘ํ˜•

๐Ÿฑ GitHub Action์„ ์ด์šฉํ•œ ์ž๋™ ๋ฐฐํฌ ๋งŒ๋“ค๊ธฐ

โœ… S3 CloudFront์™€ GitHub Action์„ ์ด์šฉํ•ด์„œ CI/CD ๋งŒ๋“ค๊ธฐ

โœ… ๋งŒ๋“œ๋Š” ์ด์œ ๋Š” ์†Œ์Šค๋ฅผ push ํ•˜๋ฉด ๋ฐ”๋กœ ์ธํ”„๋ผ์— ๋ฐฐํฌํ•˜๋Š” ํ™˜๊ฒฝ์„ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด์„œ.

โœ… ๋ฐฐํฌ ํŒŒ์ดํ”„๋ผ์ธ, CI/CD ๋ผ๊ณ  ํ•จ.

 

 

1. IAM ๊ถŒํ•œ ์ถ”๊ฐ€

(1) IAM ์„œ๋น„์Šค ์ ‘์†, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ํด๋ฆญ !

 

 

 

 

(2) ๊ถŒํ•œ ์ถ”๊ฐ€ ํด๋ฆญ !

 

 

 

(3) ๊ธฐ์กด ์ •์ฑ… ์ง์ ‘ ์—ฐ๊ฒฐ -> CloudFrontFullAccess ์„ ํƒํ•˜์—ฌ ๊ถŒํ•œ ์ถ”๊ฐ€ 

 

 

 

(4) ๊ถŒํ•œ์— S3, CloudFront์— ๋Œ€ํ•œ ๊ถŒํ•œ ํ™•์ธ ์™„๋ฃŒ !

 

 

2. GitHub Action์„ ์ด์šฉํ•œ ๋ฐฐํฌ ์ค€๋น„ 

 

 

 

(1) GitHub repository ๋งŒ๋“ค๊ณ  Pycharm ์—ฐ๋™ํ•˜๊ธฐ

*๏ธโƒฃ ๋ฐฉ๋ฒ• !

 

[GIT] Git๊ณผ Pycharm ์—ฐ๋™ํ•˜๊ธฐ

๐Ÿฑ Git๊ณผ Pycharm ์—ฐ๋™ํ•˜๊ธฐ 1. Git๊ณผ Pycharm ์—ฐ๋™ํ•˜๊ธฐ (1) GitHub repository ๋งŒ๋“ค๊ธฐ (2) ํŒŒ์ด์ฐธ ์ ‘์†ํ•ด์„œ ์˜ค๋ฅธ ์ชฝ ์œ„์˜ 'Get from VCS' *๏ธโƒฃ ์ž‘์—… ์ค‘์ธ ํด๋”๋‚˜ ํŒŒ์ผ์ด ์—ด๋ ค์žˆ๋‹ค๋ฉด, ํŒŒ์ผ -> Close Project..

dearest-mingyeong.tistory.com

 

(2) ๋ฌธ์„œ ๋ณด๊ธฐ

*๏ธโƒฃ GitHub Action ์‚ฌ์šฉ๋ฒ• ์ฐธ๊ณ  ๋ฌธ์„œ 

 

GitHub Marketplace: actions to improve your workflow

Find the actions that help your team build better, together.

github.com

 

 

(3) ๋ฐฐํฌํ•  index.html ํŒŒ์ผ ์ถ”๊ฐ€

 

 

 

(4) ๋ฐฐํฌ ์Šคํฌ๋ฆฝํŠธ ์ถ”๊ฐ€ 

โœ… .github/workflows/main.yml

โœ… github ํด๋” -> workflows ํด๋” -> main.yml ํŒŒ์ผ ์ˆœ์œผ๋กœ ์ƒ์„ฑ 

๋”๋ณด๊ธฐ

*๏ธโƒฃ main.yml ์ฝ”๋“œ

name: my-front  //์ด๋ฆ„
on:
  push:
    branches:
      - main  //๋ธŒ๋žœ์น˜
jobs:
  build:
    runs-on: ubuntu-latest
    env:
      AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
      AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
      AWS_REGION: 'ap-northeast-2'

    steps:
      - name: Checkout source code.
        uses: actions/checkout@master

      - name: Upload binary to S3 bucket
        uses: jakejarvis/s3-sync-action@master
        with:
          args: --acl public-read --exclude '*' --include 'index.html'
        env:
          AWS_S3_BUCKET: ${{ secrets.BUCKET_NAME }}

      - name: Invalidate cache CloudFront
        uses: chetan/invalidate-cloudfront-action@master
        env:
          DISTRIBUTION: ${{ secrets.DISTRIBUTION_ID }}
          PATHS: '/index.html'
        continue-on-error: true

 

 

(5) [(3),(4)] ํŒŒ์ผ Commit, push ํ•˜๊ธฐ

 

 

 

(6) GitHub ์—์„œ Action ๋ฉ”๋‰ด ํด๋ฆญํ•˜์—ฌ Action ํ™•์ธ !

โœ… AWS Access key ๋ฅผ ์„ค์ •ํ•˜์ง€ ์•Š์•„์„œ ์˜ค๋ฅ˜ ๋ฐœ์ƒ. (7)๋ฒˆ์—์„œ ํ•ด๊ฒฐ !

 

 

 

(7) secret ์„ค์ •ํ•˜๊ธฐ

โœ… Setting -> secrets -> New repository secret

โœ… ์ด์ „์— ๋ณต์‚ฌํ•ด ๋‘” iam ์‚ฌ์šฉ์ž์˜ AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY๋ฅผ ๊ฐ๊ฐ ์ถ”๊ฐ€ !

 

โœ… ๊ฐ™์€ ๋ฐฉ๋ฒ•์œผ๋กœ BUCKET_NAME (S3 ์ฐธ๊ณ ), DISTRIBUTION_ID(CloudFront ์ฐธ๊ณ ) ์ถ”๊ฐ€ !

 

 

(8) ๋‹ค์‹œ ์ปค๋ฐ‹, ํ‘ธ์‹œ ํ•ด์„œ ํ™•์ธํ•˜๊ธฐ

โœ… ์ดˆ๋ก์ƒ‰ ์ฒดํฌ ๋ชจ์–‘ ๋œจ๋ฉด ์„ฑ๊ณต !

โœ… CloudFront์—์„œ URL ์ ‘์†ํ•˜๋ฉด ์—๋Ÿฌ ์—†์ด ์ž˜ ๋‚˜ํƒ€๋‚จ 

 

 

(9) ์„ฑ๊ณต ํ™•์ธ

โœ… index ํŒŒ์ผ ์ˆ˜์ • ํ›„ commit, push ํ–ˆ์„ ๋•Œ, ๋ฐ”๋กœ ๋ฐ˜์˜๋จ.

๋ฐ˜์‘ํ˜•