Skip to content

Merge pull request #144 from 9oormthon-univ/feature/#143 #152

Merge pull request #144 from 9oormthon-univ/feature/#143

Merge pull request #144 from 9oormthon-univ/feature/#143 #152

Workflow file for this run

name: CD with Gradle
# push 이벤트와 pull request가 close될 때 워크플로우 실행
on:
push: # push 이벤트 설정
branches:
- main # main 브랜치에 push될 때만 실행
pull_request: # pull request 이벤트 설정
types:
- closed # pull request가 closed될 때만 실행
# github action이 읽을 수 있도록 수정
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# 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