[내배캠/TIL(6/30)]github action을 통한 eb 배포

손홍서·2022년 6월 30일
1

day48 TIL

day48 느낀점

오늘은 프로젝트 배포 환경 구축하는데 다 썼다. 좀 기능도 추가하고싶고 앞으로 남은 할 일이 무엇인지 체크하고 계획하는 시간도 갖고싶었는데... 후....그냥 좀 늦게 잘 것 같다.

그래도 오늘덕분에 github action을 통한 배포는 이제 조금 알 것 같다.

github action을 활용한 eb 배포를 위한 .github/workflows/main.yml 파일

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

name: #그냥 이름을 적어주세요

# 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" ]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# 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-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      - name: Checkout
        uses: actions/checkout@v3
        
      - name: Set up JDK 11 #자바 11 환경으로 설정하였습니다.
        uses: actions/setup-java@v3
        with:
          distribution: 'zulu'
          java-version: 11
      
      - name: Grant execute permission for gradlew
        run: chmod +x ./gradlew
        shell: bash
        
      - name: Build with Gradle
        run: ./gradlew clean build
        shell: bash
        
      - name: Get current time
        uses: josStorer/get-current-time@v2.0.0
        id: current-time
        with:
          format: YYYY-MM-DDTHH-mm-ss # 다른 포맷으로 변경 가능
          utcOffset: "+09:00" ## 한국시간에 맞추기 위함
      
      # Gradle build를 통해 만들어진 JAR를 beanstalk에 배포하기 위한 ZIP 파일로 만드는 것
      - name: Generate deployment package
        run: |
          mkdir -p deploy
          cp build/libs/*.jar deploy/application.jar  # 빌드 완료 시 JAR 파일명을 application.jar로 변경
          cp Procfile deploy/Procfile
          cp -r .ebextensions deploy/.ebextensions
          cp -r .platform deploy/.platform
          cd deploy && zip -r deploy.zip . # Procfile, .ebextensions, .playform 포함하여 zip 생성

      # Beanstalk Deploy 플러그인 사용
      - name: Beanstalk Deploy
        uses: einaregilsson/beanstalk-deploy@v20
        with:
          aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }} # github secrets로 등록한 값 사용
          aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} # github secrets로 등록한 값 사용
          application_name:  # EB application 이름
          environment_name:  # EB environment 이름
          version_label: Github Action-${{steps.current-time.outputs.formattedTime}} # 배포 버전은 타임스탬프를 이용하여 구분
          region: ap-northeast-2
          deployment_package: deploy/deploy.zip
          wait_for_environment_recovery: 180 # default wait time은 30초이며, 필자의 EB가 느려서 180초로 지정했습니다(지정 안하면 간혹 timeout 발생).

https://velog.io/@yyong3519/elasticbeanstalk
이 블로그를 바탕으로 작성하였다.

profile
Hello World!!

0개의 댓글