Jwt Setting(#3) #19
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
name: cd with Gradle | |
on: | |
push: | |
branches: | |
- main # main 브랜치에 push될 때 | |
permissions: write-all # 테스트 결과 작성을 위해 쓰기권한 추가 | |
jobs: | |
build: | |
if: github.event.pull_request.merged == true || github.event_name == 'push' # PR merge 또는 push일 때 실행 | |
runs-on: ubuntu-latest # 환경 | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 # 코드 체크아웃 = 가상환경 복사 | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v3 #jdk 컴파일러 | |
with: | |
java-version: '21' | |
distribution: 'temurin' # 자바 개발 키트 배포판 | |
- 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- | |
- name: Grant execute permission for Gradlew | |
run: chmod +x gradlew | |
- name: Build with Gradle | |
run: ./gradlew build -x test #빌드 | |
- name: Ensure target directory exists | |
uses: appleboy/ssh-action@master # SSH를 통해 대상 디렉토리 생성 | |
with: | |
username: ubuntu | |
host: ${{ secrets.SSH_HOST }} | |
key: ${{ secrets.SSH_KEY }} | |
script: | | |
mkdir -p /home/ubuntu/gather_back_end | |
- name: List build directory | |
run: ls -la build/libs | |
- name: Transfer Build File using SCP | |
uses: appleboy/scp-action@master # .jar 파일 원격 서버로 복사 | |
with: | |
username: ubuntu | |
host: ${{ secrets.SSH_HOST }} | |
key: ${{ secrets.SSH_KEY }} | |
source: | | |
build/libs/gather_back_end-0.0.1-SNAPSHOT.jar | |
target: "/home/ubuntu/gather_back_end" | |
- name: Deploy using Docker Compose via SSH(Prod) | |
if: github.ref == 'refs/heads/main' | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.SSH_HOST }} | |
username: ubuntu | |
key: ${{ secrets.SSH_KEY }} | |
script_stop: true | |
script: | | |
cd /home/ubuntu/gather_back_end || exit 1 # 경로 변경 실패 시 종료 | |
sudo docker compose down | |
sudo docker compose up --build -d |