๐Deploy: ๋น๋ ์ต์ ํ ์ฝ๋ ์ถ๊ฐ #38
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๋ ๋ | |
- develop # develop ๋ธ๋์น์ 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 17 | |
uses: actions/setup-java@v3 #jdk ์ปดํ์ผ๋ฌ | |
with: | |
java-version: '17' | |
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/nuclear_server | |
- 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/back_end-0.0.1-SNAPSHOT.jar | |
target: "/home/ubuntu/nuclear_server" | |
- 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/nuclear_server || exit 1 # ๊ฒฝ๋ก ๋ณ๊ฒฝ ์คํจ ์ ์ข ๋ฃ | |
sudo docker compose --profile prod --env-file .env.prod down | |
sudo docker compose --profile prod --env-file .env.prod up --build -d | |
- name: Deploy using Docker Compose via SSH(Dev) | |
if: github.ref == 'refs/heads/develop' | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.SSH_HOST }} | |
username: ubuntu | |
key: ${{ secrets.SSH_KEY }} | |
script_stop: true | |
script: | | |
cd /home/ubuntu/nuclear_server || exit 1 # ๊ฒฝ๋ก ๋ณ๊ฒฝ ์คํจ ์ ์ข ๋ฃ | |
sudo docker compose --profile dev --env-file .env.dev down | |
sudo docker compose --profile dev --env-file .env.dev up --build -d |