🔊 로그 추가 #30
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: Java CI with Gradle(deploy) | |
on: | |
push: | |
branches: [ "main" ] | |
permissions: | |
contents: read | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: checkout | |
uses: actions/checkout@v3 | |
# JDK를 17 버전으로 세팅 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
# Gradle 캐싱-> 빌드 속도 UP | |
- name: Gradle caching | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.gradle/caches | |
~/.gradle/wrapper | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
restore-keys: | | |
${{ runner.os }}-gradle- | |
# application-prod.yml 파일 생성 | |
- name: make application-prod.yml | |
run: | | |
cd ./src/main/resources | |
touch ./application-prod.yml | |
echo "${{ secrets.APPLICATION }}" >> ./application-prod.yml | |
shell: bash | |
# Gradle로 빌드 실행 | |
- name: Build with Gradle | |
run: | | |
chmod +x ./gradlew | |
./gradlew bootJar | |
# AWS에 연결 | |
- name: Connect to 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 }} | |
# 빌드 파일을 ZIP 파일로 생성 | |
- name: Make zip file | |
run: | | |
mkdir deploy | |
cp ./appspec.yml ./deploy/ | |
#cp ./dockerfile ./deploy/ | |
cp ./deploy.sh ./deploy/ | |
cp ./build/libs/*.jar ./deploy/ | |
zip -r -qq -j ./kidari-build.zip ./deploy | |
# S3에 zip 파일 업로드 | |
- name: Upload to S3 | |
run: | | |
aws s3 cp \ | |
--region ap-northeast-2 \ | |
./kidari-build.zip s3://kidari | |
# CodeDeploy에 배포 요청 | |
- name: Code Deploy Deployment Request | |
run: | | |
aws deploy create-deployment --application-name rekidari \ | |
--deployment-config-name CodeDeployDefault.OneAtATime \ | |
--deployment-group-name rekidari \ | |
--s3-location bucket=kidari,bundleType=zip,key=kidari-build.zip | |
# 배포 결과 Slack 알람 전송 | |
- name: Send Slack Alarms | |
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() |