Skip to content

Merge branch 'main' of https://github.com/9oormthon-univ/2024_DANPOON… #219

Merge branch 'main' of https://github.com/9oormthon-univ/2024_DANPOON…

Merge branch 'main' of https://github.com/9oormthon-univ/2024_DANPOON… #219

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