Git

GitAction(간단히)

KK_Ryong 2023. 3. 3. 17:54

■■■GitHub Repositories 생성 ■■■

■■■배포 할 Repo 선택 후 배포 할 서버의 정보를 Secrets에 넣어주기 ■■■

■■■브런치 생성 (main, stg 각각 만들어 주기)■■■

브런치 명에 따라 action 가능 

 

■■■Action에 활용 할 yml 파일 ■■■

name: stg-deploy-to-s3

on:
  push:
    branches:
    - stg 
   #main stg prd 등 브런치 이름 적기
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout source code.
        uses: actions/checkout@v2
     
      - name: Setup Python for AWS CLI
        uses: actions/setup-python@v1
        with:
          python-version: '3.x'

      - name: Install AWS CLI
        run: pip3 install awscli --upgrade --user

      - name: Cache node modules
        uses: actions/cache@v1
        with:
          path: node_modules
          key: ${{ runner.OS }}-build-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ runner.OS }}-build-
            ${{ runner.OS }}-
           
      - name: Install Dependencies
        run: npm install
       
      - name: Build
        run: npm run build_stg

      - name: Deploy to s3 and Cloudfront distribution
        env:
          AWS_ACCESS_KEY_ID: ${{ secrets.ACCESS_KEY_ID }}
          AWS_SECRET_ACCESS_KEY: ${{ secrets.SECRET_ACCESS_KEY }}
        run: |
          aws s3 cp \
            --recursive \
            --region ap-northeast-2 \
            _stage s3://[버킷 위치]
          aws cloudfront create-invalidation --distribution-id [CF배포ID] --paths "/*"     
#distribution 은 CF 캐시 무효화 설정 되어있을때  잠시 내렸다  배포 하고 올리는 역할

**방화벽에서 22 port 오픈을 해주어야 한다

정상 Commit 될 경우