π κΈμ μ μ ν ν΄μ (#106) #81
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 |