Merge branch 'develop' #61
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This workflow uses actions that are not certified by GitHub. | |
# They are provided by a third-party and are governed by | |
# separate terms of service, privacy policy, and support | |
# documentation. | |
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time | |
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle | |
name: BackEnd - CI/CD | |
on: | |
push: | |
branches: [ "main" ] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
# Gradle을 캐싱해둡니다 -> 빌드 속도가 증가하는 효과가 있습니다. | |
- name: Gradle 캐싱 | |
run: | | |
cd todo-back | |
./gradlew clean build -x test | |
- name: Make application.yml | |
run: | | |
cd todo-back | |
cd ./src/main | |
cd ./resources | |
touch ./application.yml | |
touch ./application-runtime.yml | |
touch ./application-oauth.yml | |
touch ./application-jwt.yml | |
echo "$APPLICATION_OAUTH" > ./application-oauth.yml | |
echo "$APPLICATION_JWT" > ./application-jwt.yml | |
echo "$APPLICATION_RUNTIME" > ./application-runtime.yml | |
echo "$APPLICATION" > ./application.yml | |
env: | |
APPLICATION_OAUTH: ${{ secrets.APPLICATION_OAUTH }} | |
APPLICATION_JWT: ${{ secrets.APPLICATION_JWT }} | |
APPLICATION: ${{ secrets.APPLICATION }} | |
APPLICATION_RUNTIME: ${{ secrets.APPLICATION_RUNTIME }} | |
shell: bash | |
- name: Gradle 권한 부여 | |
run: | | |
cd todo-back | |
chmod +x gradlew | |
- name: Gradle로 빌드 실행 | |
run: | | |
cd todo-back | |
./gradlew bootjar | |
# 배포에 필요한 여러 설정 파일과 프로젝트 빌드파일을 zip 파일로 모아줍니다. | |
- name: zip file 생성 | |
run: | | |
cd todo-back | |
mkdir deploy | |
cp ./docker-compose.blue.yml ./deploy/ | |
cp ./docker-compose.green.yml ./deploy/ | |
cp ./appspec.yml ./deploy/ | |
cp ./Dockerfile ./deploy/ | |
cp ./scripts/*.sh ./deploy/ | |
cp ./build/libs/*.jar ./deploy/ | |
zip -r -qq -j ./spring-build.zip ./deploy | |
# AWS에 연결해줍니다. | |
- name: AWS 연결 | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ secrets.AWS_REGION }} | |
# S3에 프로젝트를 업로드 합니다. | |
- name: S3에 프로젝트 업로드 | |
run: | | |
aws s3 cp \ | |
--region ap-northeast-1 \ | |
./todo-back/spring-build.zip s3://todo-springboot-build | |
# CodeDelploy에 배포를 요청합니다. | |
- name: Code Deploy 배포 요청 | |
run: | | |
cd todo-back | |
aws deploy create-deployment \ | |
--application-name MyTodo \ | |
--deployment-config-name CodeDeployDefault.OneAtATime \ | |
--deployment-group-name MyTodo \ | |
--s3-location bucket=todo-springboot-build,bundleType=zip,key=spring-build.zip | |
# 빌드 성공 & 실패 여부를 Slack 알람으로 발송합니다. | |
- name: Slack 알람 발송 | |
uses: rtCamp/action-slack-notify@v2 | |
env: | |
SLACK_CHANNEL: general | |
SLACK_COLOR: ${{ job.status }} # or a specific color like 'good' or '#ff00ff' | |
SLACK_ICON: https://github.com/rtCamp.png?size=48 | |
SLACK_MESSAGE: 배포 결과 => ${{ job.status }} | |
SLACK_TITLE: 배포 결과 알람 | |
SLACK_USERNAME: Notification-Bot | |
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }} | |
# 이 구문을 추가해야 빌드 성공 실패와 상관없이 동작합니다. | |
if: always() |