๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ“‚ ์•Œ์“ธ ์ง€์‹/์•Œ์•„๋‘๋ฉด ์ข‹์„

ํด๋ผ์ด์–ธํŠธ ๋ฐฐํฌ๋Š” ์‹ ๊ธฐํ•˜๊ณ  ์žฌ๋ฐŒ์–ด ๊ทธ๋ฆฌ๊ณ  ๊ธด์žฅ๋ผ ...

by Dev. Ella 2023. 6. 5.

๐Ÿ› ๏ธ Todo

๋งŒ๋“ค์–ด ๋‘” ์›น์„ Github Actions์™€ Amazon S3๋ฅผ ํ™œ์šฉํ•ด ๋นŒ๋“œ ๋ฐ ๋ฐฐํฌํ•˜์—ฌ, ์‚ฌ์šฉ์ž๋“ค์ด ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•˜๊ธฐ

์ด๋ฒˆ ํด๋ผ์ด์–ธํŠธ ๋ฐฐํฌ์˜ 3๋‹จ๊ณ„
1. Source : Github ๋ธŒ๋žœ์น˜์— ์ฝ”๋“œ๊ฐ€ commit ๋˜๋ฉด
2. Build : Github Actions์˜ YAML ํŒŒ์ผ์— ์ ํžŒ ๋ช…๋ น์–ด๋ฅผ ํ† ๋Œ€๋กœ Webpack์„ ์ด์šฉํ•ด build ํ•˜๊ธฐ
3. Deploy : Github Actions์˜ YAML ํŒŒ์ผ์— ์ ํžŒ ๋ช…๋ น์–ด๋ฅผ ํ† ๋Œ€๋กœ S3๋กœ build ๊ฒฐ๊ณผ๋ฅผ upload ํ•˜๊ธฐ

 

 

๐Ÿง YAML ํŒŒ์ผ์— ์ฝ”๋“œ ์ ๊ธฐ

1. ํ•ด๋‹น repository์˜ ๋ธŒ๋žœ์น˜ ์ด๋ฆ„์„ ์ ์–ด์ค€๋‹ค.

ํ˜„์žฌ ๋ธŒ๋žœ์น˜ ๋ช…์„ ํ™•์ธํ•˜๋ ค๋ฉด git branch๋ผ๋Š” ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅ ํ›„ ํ™•์ธ, q๋ฅผ ๋ˆŒ๋Ÿฌ ์ข…๋ฃŒํ•˜๋ฉด ๋œ๋‹ค.

name: client
on:
  push:
    branches:
      - reference # ๋ธŒ๋žœ์น˜ ๋ช…

 

2. working-directory์—๋Š” ์ž‘์—…ํ•œ ๋””๋ ‰ํ† ๋ฆฌ ๋ช…์„ ์ ์–ด์ค€๋‹ค.

๋„๋ฉ”์ธ ๋ช… ์•„๋‹˜ ์ฃผ์˜!

jobs:
  build:
    runs-on: ubuntu-20.04
    steps:
      - name: Checkout source code.
        uses: actions/checkout@v2
      - name: Install dependencies
        run: npm install # install ์‹œ ๋ช…๋ น์–ด
        working-directory: ./my-agora-states-client-react # ์ž‘์—…ํ•œ ๋””๋ ‰ํ† ๋ฆฌ ๋ช…

 

3. install, build ์‹œ ๋ช…๋ น์–ด๋“ค์„ ์ ์–ด์ค€๋‹ค.

e.g. npm install, npm run build ๋“ฑ

      - name: Build
        run: npm run build # build ์‹œ ๋ช…๋ น์–ด
        working-directory: ./my-agora-states-client-react # ์ž‘์—…ํ•œ ๋””๋ ‰ํ† ๋ฆฌ ๋ช… 
      - name: SHOW AWS CLI VERSION
        run: aws --version # aws version ํ™•์ธ ๋ช…๋ น์–ด

 

4. yml ํŒŒ์ผ์— ์‹œํฌ๋ฆฟ ํ‚ค '์ด๋ฆ„'์„ ์ž…๋ ฅํ•œ๋‹ค.

์ฃผ์˜ํ•  ์ ์€ ์ ˆ๋Œ€ ์‹œํฌ๋ฆฟ ํ‚ค ์ž์ฒด๋ฅผ ์ž…๋ ฅํ•˜์ง€ ๋ง์•„์•ผ ํ•œ๋‹ค๋Š” ๊ฒƒ์ด๋‹ค. ์ž์„ธํ•œ ๋ฐฉ๋ฒ•์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

 

(1) Github์˜ ํ•ด๋‹น ๋ ˆํฌ์ง€ํ† ๋ฆฌ > Settings > ์ขŒ์ธก์˜ Secrets and variables > Actions > [New repository secret]์„ ๋ˆŒ๋Ÿฌ AWS์—์„œ ๋ฐœ๊ธ‰๋ฐ›์€ ํ‚ค๋ฅผ ๋“ฑ๋กํ•œ๋‹ค.

(2) ๊นƒํ—™์— AWS_ACCESS_KEY๋ผ๊ณ  ๋“ฑ๋กํ–ˆ๋‹ค๋ฉด > yml ํŒŒ์ผ์—๋„ AWS_ACCESS_KEY ๋ผ๊ณ  ์ž…๋ ฅํ•ด์•ผ ํ•œ๋‹ค.

      - name: Sync Bucket
        env:
          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY }} # AWS access ํ‚ค
          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_KEY }} # AWS secret ํ‚ค
          AWS_EC2_METADATA_DISABLED: true

 

5. ๋ฒ„ํ‚ท ์ด๋ฆ„์„ ๊ธฐ์žฌํ•œ๋‹ค. 

๋ฒ„ํ‚ท ์ด๋ฆ„์€ S3 > ๋ฒ„ํ‚ท > ์†์„ฑ์—์„œ > Amazon ๋ฆฌ์†Œ์Šค ์ด๋ฆ„ (ARN)์˜ ::: ๋’ท๋ถ€๋ถ„์„ ์ž…๋ ฅํ•œ๋‹ค.

        run: |
          aws s3 sync \ # ๋ฒ„ํ‚ท์˜ ์†์„ฑ
            --region ap-northeast-2 \ # ๋ฆฌ์ „ 
            build s3://๋ฒ„ํ‚ท ์ด๋ฆ„ \ # ๋ฒ„ํ‚ท ์ด๋ฆ„์„ ๊ธฐ์žฌ
            --delete
        working-directory: ./my-agora-states-client-react # ์ž‘์—…ํ•œ ๋””๋ ‰ํ† ๋ฆฌ ๋ช…

 

 

๐Ÿคฉ ์™„์„ฑํ•œ client.yml ์ฝ”๋“œ

name: client
on:
  # PUSH ------------------------------------------------
  push:
    branches:
      - reference # ๋ธŒ๋žœ์น˜ ๋ช…
jobs:
  # BUILD ------------------------------------------------
  build:
    runs-on: ubuntu-20.04
    steps:
      - name: Checkout source code.
        uses: actions/checkout@v2
        # INSTALL ------------------------------------------------
      - name: Install dependencies
        run: npm install # install ์‹œ ๋ช…๋ น์–ด
        working-directory: ./my-agora-states-client-react # ์ž‘์—…ํ•œ ๋””๋ ‰ํ† ๋ฆฌ ๋ช…   
        # BUILD ------------------------------------------------
      - name: Build
        run: npm run build # build ์‹œ ๋ช…๋ น์–ด
        working-directory: ./my-agora-states-client-react # ์ž‘์—…ํ•œ ๋””๋ ‰ํ† ๋ฆฌ ๋ช… 
        # AWS VERSION ------------------------------------------------
      - name: SHOW AWS CLI VERSION
        run: aws --version # aws version ํ™•์ธ ๋ช…๋ น์–ด
        # AWS BUCKET and KEY ------------------------------------------------
      - name: Sync Bucket
        env:
          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY }} # AWS access ํ‚ค
          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_KEY }} # AWS secret ํ‚ค
          AWS_EC2_METADATA_DISABLED: true
        run: |
          aws s3 sync \
            --region ap-northeast-2 \ # ๋ฆฌ์ „ 
            build s3://๋ฒ„ํ‚ท ์ด๋ฆ„ \ # ๋ฒ„ํ‚ท ์ด๋ฆ„์„ ๊ธฐ์žฌ
            --delete
        working-directory: ./my-agora-states-client-react # ์ž‘์—…ํ•œ ๋””๋ ‰ํ† ๋ฆฌ ๋ช…

 

 

๐Ÿฅณ ๋นŒ๋“œ์™€ ๋ฐฐํฌ

1. ์ž‘์„ฑํ•œ yml ํŒŒ์ผ์„ ์ปค๋ฐ‹, ๊ทธ๋ฆฌ๊ณ  ํ‘ธ์‹œํ•œ๋‹ค.

2. ๊นƒํ—™์˜ ํ•ด๋‹น repository > Actions์—์„œ ํ™•์ธํ•œ๋‹ค.

์•„๋ž˜์™€ ๊ฐ™์ด ๋…ธ๋ž‘๋ถˆ > ์ดˆ๋ก์ƒ‰ ์ฒดํฌํ‘œ์‹œ๋กœ ๋ฐ”๋€Œ๋ฉด ์„ฑ๊ณต! (๊ฒฐ๊ณผ๋ฅผ ๊ธฐ๋‹ค๋ฆด ๋•Œ ์€๊ทผ ๊ธด์žฅ๋œ๋‹ค... ๊ธฐ๋„ ๋ฉ”ํƒ€ ๐Ÿ™๐Ÿป) ๋งŒ์•ฝ ๋นจ๊ฐ„์ƒ‰ X ํ‘œ์‹œ๊ฐ€ ๋œฌ๋‹ค๋ฉด ํ•ด๋‹น ์—๋Ÿฌ๋ฅผ ํ•ด๊ฒฐํ•œ ํ›„, ๋‹ค์‹œ ํ‘ธ์‹œํ•ด์•ผ ํ•œ๋‹ค.

3. ์—”๋“œํฌ์ธํŠธ๋ฅผ ํ†ตํ•ด ์ ‘์†ํ•œ๋‹ค.

AWS > S3  > ๋ฒ„ํ‚ท  > ์†์„ฑ > ์†์„ฑ ํŽ˜์ด์ง€ ๋งจ ํ•˜๋‹จ์˜ '๋ฒ„ํ‚ท ์›น ์‚ฌ์ดํŠธ ์—”๋“œ ํฌ์ธํŠธ'๋ฅผ ํด๋ฆญํ•˜๋ฉด 

4. ์•„๋ž˜์™€ ๊ฐ™์ด ๋‚ด๊ฐ€ ๋งŒ๋“  ์›น ์‚ฌ์ดํŠธ๊ฐ€ ๋œฌ๋‹ค!

 

 

๋Œ“๊ธ€