Skip to content

πŸ› [FIX] μ‹œκ°„ μ—λŸ¬ ν•΄κ²° #203

πŸ› [FIX] μ‹œκ°„ μ—λŸ¬ ν•΄κ²°

πŸ› [FIX] μ‹œκ°„ μ—λŸ¬ ν•΄κ²° #203

Workflow file for this run

name: CD with Gradle
on:
push:
branches:
- main
pull_request:
types:
- closed
permissions:
contents: read
jobs:
handle-events:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# pull_requestκ°€ λ‹«νžŒ κ²½μš°μ—λ§Œ μ‹€ν–‰
- name: Handle Pull Request Closed
if: github.event_name == 'pull_request' && github.event.action == 'closed'
run: echo "Pull request closed! Handling pull_request event."
# push 이벀트인 κ²½μš°μ—λ§Œ μ‹€ν–‰
- name: Handle Push Event
if: github.event_name == 'push'
run: echo "Code pushed to main! Handling push event."
# jdk 17 버전 ν™˜κ²½μ„ μ„ΈνŒ…
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: "adopt"
# 깃에 μ—†λŠ” application.yml 파일 생성
- name: Make application.yml
run: |
cd ./src/main
mkdir resources
cd resources
touch ./application.yml
echo "${{ secrets.YML }}" > ./application.yml
shell: bash
# μ†ŒμŠ€ λΉŒλ“œ
- name: Build with Gradle
run: |
chmod +x ./gradlew
./gradlew clean build -x test
# dockerfile을 톡해 이미지λ₯Ό λΉŒλ“œν•˜κ³ , 이λ₯Ό docker repo둜 push
- name: Docker build & push to docker repo
run: |
docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }}
docker build -f Dockerfile -t ${{ secrets.DOCKER_REPO }}/carely .
docker push ${{ secrets.DOCKER_REPO }}/carely
# 기쑴에 μ‹€ν–‰λ˜λŠ” μ»¨ν…Œμ΄λ„ˆ λͺ¨λ‘ 멈좀
# μ„œλ²„μ— μ ‘μ†ν•˜μ—¬ pull ν•œ ν›„ μ‹€ν–‰
# docker-comppose에 μž‘μ„±ν•΄λ‘” μ»¨ν…Œμ΄λ„ˆ λ°±κ·ΈλΌμš΄λ“œλ‘œ μ‹€ν–‰
- name: Deploy to server
uses: appleboy/ssh-action@master
id: deploy
with:
host: ${{ secrets.HOST }}
username: ubuntu
key: ${{ secrets.KEY }}
envs: GITHUB_SHA
script: |
sudo docker rm -f $(docker ps -qa)
sudo docker stop $(docker ps -a -q)
sudo docker pull ${{ secrets.DOCKER_REPO }}/carely
sudo docker-compose up --build -d
sudo docker image prune -f