fix: 작업 디렉토리 수정 #3
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: CI/CD | |
on: | |
push: | |
branches: | |
- develop | |
jobs: | |
build-deploy: | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: GoodBuyUS | |
steps: | |
# 체크아웃 | |
- name: Checkout develop | |
uses: actions/checkout@v3 | |
# JDK 설정 | |
- name: Set Up JDK 17 | |
uses: actions/setup-java@v3 | |
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: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
# Gradle 빌드 | |
- name: Build with Gradle | |
env: | |
DB_URL: ${{ secrets.DB_URL }} | |
DB_USERNAME: ${{ secrets.DB_USERNAME }} | |
DB_PASSWORD: ${{ secrets.DB_PASSWORD }} | |
mail_username: ${{ secrets.MAIL_USERNAME }} | |
mail_password: ${{ secrets.MAIL_PASSWORD }} | |
run: ./gradlew build -x test | |
# 도커허브 로그인 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
# 도커 이미지 빌드 | |
- name: Build Docker Image | |
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }} . | |
# 도커 이미지 Push | |
- name: Push Docker Image | |
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }} | |
# ec2 배포 | |
- name: Deploy to EC2 | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USERNAME }} | |
key: ${{ secrets.EC2_SSH_KEY }} | |
script: | | |
sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }} | |
sudo docker stop backend || true | |
sudo docker rm backend || true | |
sudo docker run -d --name backend -p 8080:8080 -e TZ=Asia/Seoul ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }} |