Skip to content

chore: cicd 수정

chore: cicd 수정 #25

Workflow file for this run

name: MARU EGG CI-CD Workflow
on:
push:
branches: [ "main", "develop" ]
pull_request:
branches:
- develop
jobs:
CI:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
# Setup Java JDK
- name: Setup Java JDK
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'temurin'
# Grant execute permission for gradlew
- name: Grant execute permission for gradlew
run: chmod +x gradlew
# gradle caching - 빌드 시간 향상
- 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-
# 환경별 yml 파일 생성 - dev
- name: make application-dev.yml
if: contains(github.ref, 'develop')
run: |
cd ./src/main/resources
touch ./application-dev.yml
echo "${{ secrets.YML_DEV }}" > ./application-dev.yml
shell: bash
# gradle build
- name: Build with Gradle
run: ./gradlew build -x test
# Check if the JAR file exists
- name: Check JAR file exists
run: ls -al build/libs
CD:
runs-on: ubuntu-latest
needs: CI
steps:
# docker build & push to develop
- name: Docker build & push to dev
if: contains(github.ref, 'develop')
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -t maru-egg-dev .
docker tag maru-egg-dev ${{ secrets.DOCKER_USERNAME }}/maru-egg-dev
docker push ${{ secrets.DOCKER_USERNAME }}/maru-egg-dev
## deploy to develop
- name: Deploy to dev
uses: appleboy/ssh-action@master
id: deploy-dev
if: contains(github.ref, 'develop')
with:
host: ${{ secrets.PUBLIC_DNS }} # EC2 퍼블릭 IPv4 DNS
username: ${{ secrets.USERNAME }}
key: ${{ secrets.PEM_KEY }}
script: |
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/maru-egg-dev
sudo docker stop $(docker ps -a -q)
sudo docker run -d --log-driver=syslog -p 8080:8080 -e ${{ secrets.DOCKER_USERNAME }}/maru-egg-dev
sudo docker rm $(docker ps --filter 'status=exited' -a -q)
sudo docker image prune -f