Merge pull request #17 from Leets-Official/feat/#16/유저-프로필-수정-조회 #45
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: X-BE CICD | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main # main 브랜치로의 PR 시에도 실행되도록 설정 | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout the repository | |
uses: actions/checkout@v3 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Cache Gradle packages | |
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 (Skip Tests) | |
run: ./gradlew build -x test # '-x test' 옵션으로 테스트를 제외하고 빌드 | |
- name: Docker Hub Login | |
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USER_NAME }}" --password-stdin | |
- name: Build Docker image | |
run: docker build -t ${{ secrets.DOCKER_USER_NAME }}/x-be:latest . | |
- name: Push Docker image | |
run: docker push ${{ secrets.DOCKER_USER_NAME }}/x-be | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build # CI 파이프라인의 build 작업이 끝나야 deploy가 실행됨 | |
if: github.event_name == 'push' | |
steps: | |
# EC2 서버로 배포 | |
- name: Deploy to EC2 | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.EC2_USER }} | |
key: ${{ secrets.SSH_PRIVATE_KEY }} | |
port: 22 | |
script: | | |
# 이동 경로 | |
cd /home/ubuntu | |
# deploy.sh 실행 | |
sudo ./deploy.sh |