Skip to content

yml 수정

yml 수정 #32

Workflow file for this run

name: Java CI with Gradle
on:
push:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
# Gradle caching - 빌드 시간 향상
- name: Gradle Caching
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Run chmod to make gradlew executable
run: chmod +x ./gradlew
- name: Build with Gradle
run: ./gradlew build -x test
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Build Docker Image
run: |
docker build -t ${{ secrets.IMAGE_NAME }}:latest .
- name: Push Docker Image to Docker Hub
run: |
docker push ${{ secrets.IMAGE_NAME }}:latest
- name: Deploy
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_SSH_KEY }}
port: 22
script: |
docker stop gratitude-container || true
docker rm -f gratitude-container || true
docker pull ${{ secrets.IMAGE_NAME }}:latest
docker run -d --name gratitude-container -p 8080:8080 -e DB_URL=${{ secrets.DB_URL }} -e DB_USERNAME=${{ secrets.DB_USERNAME }} -e DB_PASSWORD=${{ secrets.DB_PASSWORD }} -e JWT_SECRET=${{ secrets.JWT_SECRET }} ${{ secrets.IMAGE_NAME }}:latest
docker image prune -f