728x90
스프링 부트와 AWS로 혼자 구현하는 웹 서비스와 향로님 블로그를 보면서 무중단 배포를 만들 생각이다.
CodeDeploy를 사용하던것과 달리 Beanstalk을 사용하면 구현상에 깔끔한 구조가 가능하다.
- 배포파일전송을 위해 S3에 업로드 하는 과정이 없다.
- EC2에 배포를 위해 별도의 agent 설치가 필요가 없다.
- Nginx설치 / OS 설정 등 OS상에 필요한 모든 설정은 코드로 관리가 가능하다.
Github Action yml 파일 생성하기
name: Java CI with Gradle
on:
push:
branches: [ "dev" ]
pull_request:
branches: [ "dev" ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
- name: make application-db.yml
run: |
# create application-db.yml
pwd
cd ./src/main/resources
# application-db.yml 파일 생성
touch ./application-db.yml
# GitHub-Actions 에서 설정한 값을 application-db.yml 파일에 쓰기
echo "${{ secrets.DB_YML }}" >> ./application-db.yml
shell: bash
- name: make application-mail.yml
run: |
# create application-mail.yml
pwd
cd ./src/main/resources
# application-mail.yml 파일 생성
touch ./application-mail.yml
# GitHub-Actions 에서 설정한 값을 application-mail.yml 파일에 쓰기
echo "${{ secrets.MAIL_YML }}" >> ./application-mail.yml
shell: bash
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew clean build -x test
- github action의 트리거 브랜치는 dev로 지정한다. (dev 브랜치에 push 하거나 pull request가 되면 실행한다.)
- github action 스크립트가 작동될 OS 환경은 ubuntu-latest다.
- uses: actions/checkout@v3는 프로젝트 코드를 checkout 한다.
- actions/setup-java@v3는 github action이 실행될 OS에 Java를 설치한다.
- run: chmod +x ./gradlew는 gradle wrapper를 실행할 수 있도록 실행 권한 (+x)을 준다.
- run: ./gradlew clean build는 gradle wrapper를 통해 해당 프로젝트를 build 한다.
Github Action 빌드하기
Github Action에 Time Action 추가하기
build 시점의 현재 시간을 확인하는 기능
# 현재시간가져오기
- name: Get current time
uses: josStorer/get-current-time@v2.0.2
id: current-time
with:
format: YYYY-MM-DDTHH-mm-ss
utcOffset: "+09:00"
# 현재시간 사용
- name: Use current time
env:
TIME: "${{ steps.current-time.outputs.time }}"
R_TIME: "${{ steps.current-time.outputs.readableTime }}"
F_TIME: "${{ steps.current-time.outputs.formattedTime }}"
YEAR: "${{ steps.current-time.outputs.year }}"
DAY: "${{ steps.current-time.outputs.day }}"
run: echo $TIME $R_TIME $F_TIME $YEAR $DAY
# 현재시간 출력
- name: Show Current Time
run: echo "CurrentTime=${{steps.current-time.outputs.formattedTime}}"
shell: bash
- josStorer/get-current-time@v2.0.2는 github action이 실행되는 시간을 가져올 수 있게 한다.
- utcOffset: "+09:00": 해당 action의 기준이 UTC이기 때문에 한국시간이 KST를 맞추기 위해서는 +9시간이 필요하여 offset을 추가한다.
- ${{steps.current-time.outputs.formattedTime}}은 get-current-time 에서 지정한 포맷대로 현재 시간을 출력한다.
빌드 yml 파일
name: Java CI with Gradle
on:
push:
branches: [ "dev" ]
pull_request:
branches: [ "dev" ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
- name: make application-db.yml
run: |
# create application-db.yml
pwd
cd ./src/main/resources
# application-db.yml 파일 생성
touch ./application-db.yml
# GitHub-Actions 에서 설정한 값을 application-db.yml 파일에 쓰기
echo "${{ secrets.DB_YML }}" >> ./application-db.yml
shell: bash
- name: make application-mail.yml
run: |
# create application-mail.yml
pwd
cd ./src/main/resources
# application-mail.yml 파일 생성
touch ./application-mail.yml
# GitHub-Actions 에서 설정한 값을 application-mail.yml 파일에 쓰기
echo "${{ secrets.MAIL_YML }}" >> ./application-mail.yml
shell: bash
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew clean build -x test
#2 현재시간가져오기
- name: Get current time
uses: josStorer/get-current-time@v2.0.2
id: current-time
with:
format: YYYY-MM-DDTHH-mm-ss
utcOffset: "+09:00"
Github Actions + CodeDeploy + Nginx 로 무중단 배포하기 (1)
개요 안녕하세요! 이번 시리즈에서는 제목에서와 같이 Github Actions 와 CodeDeploy, 그리고 Nginx 를 사용하여 하나의 서버에서 최소 규모의 무중단 배포를 진행하는 방법에 대해 정리해보려고 합니다.
wbluke.tistory.com
2. Github Action & AWS Beanstalk 배포하기 - profile=local로 배포하기
지난 시간에 만들어둔 Github Action을 통해 profile=local로 Beanstalk에 배포를 진행해보겠습니다. profile=local, 즉, 운영 DB와 구글&네이버 OAuth 를 사용하지 않는 간단한 테스트 용도로만 배포할 예정입니
jojoldu.tistory.com
728x90