[fix] : gradle.yml 수정 #31
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
# Workflow 이름 | |
name: Spring Boot & Gradle CI/CD | |
# 어떤 이벤트가 발생하면 workflow 실행할 지 명시 | |
on: | |
# main 브랜치에 push나 pull request 발생 시 | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
# 위 이벤트 발생 시 실행될 작업들 | |
jobs: | |
build: | |
# VM의실행 환경 지정 => 우분투 최신 버전 | |
runs-on: ubuntu-latest | |
# 실행될 jobs를 순서대로 명시 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
# JDK 11 설치 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
# Gradle Build를 위한 권한 부여 | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
# Gradle Build (test 제외) | |
- name: Build with Gradle | |
run: ./gradlew clean build --exclude-task test | |
# DockerHub 로그인 | |
- name: DockerHub Login | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
# Docker 이미지 빌드 | |
- name: Docker Image Build | |
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }} . | |
# DockerHub Push | |
- name: DockerHub Push | |
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }} | |
# EC2 인스턴스 접속 및 애플리케이션 실행 | |
- name: Application Run | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USERNAME }} | |
key: ${{ secrets.EC2_KEY }} | |
script: | | |
sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }} | |
sudo docker run -p ${{ secrets.PORT }}:${{ secrets.PORT }} --env-file zip.env ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }} |