Skip to content

GachTaxi-BE dev CI/CD #53

GachTaxi-BE dev CI/CD

GachTaxi-BE dev CI/CD #53

Workflow file for this run

name: GachTaxi-BE dev CI/CD
on:
push:
branches: [ "dev" ] # develop 브랜치에 push 시 트리거
pull_request:
branches: [ "dev" ] # develop 브랜치에 대한 PR 시 트리거
types: [opened, synchronize, reopened]
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 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: Build with Gradle Wrapper
run: ./gradlew build -x test
# 빌드된 JAR 파일 확인
- name: List JAR files
run: ls build/libs
# Docker 이미지 빌드 및 푸시
- name: Docker build & push
run: |
docker login -u ${{ secrets.DEV_DOCKER_USER_NAME }} -p ${{ secrets.DEV_DOCKER_USER_TOKEN }}
docker buildx create --use
docker buildx build --platform linux/amd64,linux/arm64 -f Dockerfile-dev -t ${{ secrets.DEV_DOCKER_USER_NAME }}/gachtaxi:latest --push .
deploy:
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'push'
steps:
# SSH를 사용하여 원격 서버에 배포
- name: Deploy to server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.DEV_SSH_SECRET_HOST }}
username: ${{ secrets.DEV_SSH_SECRET_USER }}
port: 30922
key: ${{ secrets.DEV_SSH_SECRET_PRIVATE_KEY }}
script: |
docker pull ${{ secrets.DEV_DOCKER_USER_NAME }}/gachtaxi:latest
docker compose up -d --no-deps gachtaxi
# 사용하지 않는 이미지 정리
echo "** 사용하지 않는 Docker 이미지 정리"
sudo docker image prune -f