[github] github action으로 S3에 정적코드 자동 배포하기

주수호·2022년 5월 22일
0

준비물

  • S3 bucket
  • aws IAM권한
  • github action
  • 소스파일

IAM을 통해서 S3에 액세스가 가능한 권한 유저를 별도로 추가합니다

S3에 대한 별도의 IAM유저를 생성했습니다. IAM에 대한 내용은 따로 다뤄야 할 것 같네요. (편리하지만 알아야 할께 많은 AWS입니다.)

3.
이렇게 S3에 대한 IAM유저가 별도로 만들어졌습니다. 해당 유저의 키값을 통해, github-action으로 코드를 deploy하여, main에 commit이 되는 경우, 자동으로 S3로 코드가 업데이트 될 것입니다.

배포를 진행할 github repository에서 Sercurity > Secrets에 해당 키 등록

github-action script를 작성합니다

해당 레포지토리에 main브랜치에 대한 변화가 있을시에, s3로 해당 소스 파일들을 업로드 할 수 있도록 합니다.

# This is a basic workflow to help you get started with Actions

name: resume-front-CI

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the main branch
  push:
    branches: main
  pull_request:
    branches: main

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-18.04

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      - name: Checkout source code
        uses: actions/checkout@master
      # Runs a set of commands using the runners shell
      - name: Code Deploy
        env:
          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        run: aws s3 cp --recursive --region ap-northeast-2 . s3://suho-hompage
profile
항상 준비하는 엔지니어

0개의 댓글