Skip to content

Update CD.yml

Update CD.yml #23

Workflow file for this run

name: CD
on: # 트리거
push:
branches: [ "develop" ]
jobs:
deploy-ci: # job#1
runs-on: ubuntu-22.04
env:
working-directory: ./ # 프로젝트 디렉토리
steps: # 작업 단위
- name: 체크아웃
uses: actions/checkout@v3
- name: Java 실행 환경 - JDK 17 세팅
uses: actions/setup-java@v3
with:
distribution: 'corretto'
java-version: '17'
- name: application.yml 파일 생성
run: |
# yml을 생성할 디렉터리로 작업 디렉터리 이동
cd ./src/main/resources
echo "${{ secrets.APPLICATION }}" > ./application-deploy.yml
working-directory: ${{ env.working-directory }}
- name: 빌드
run: |
chmod +x gradlew
./gradlew build -x test
working-directory: ${{ env.working-directory }}
shell: bash
- name: Docker 빌드 환경 설정
uses: docker/[email protected]
- name: Docker Hub에 로그인
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKERHUB_LOGIN_USERNAME }}
password: ${{ secrets.DOCKERHUB_LOGIN_ACCESSTOKEN }}
- name: Docker Image 빌드 및 푸시
run: |
docker build --platform linux/amd64 -t yejunpark1/motivoo-server .
docker push yejunpark1/motivoo-server
- name: deploy.sh EC2 인스턴스로 전송
uses: appleboy/scp-action@master
with:
host: ${{ secrets.RELEASE_SERVER_IP }}
username: ${{ secrets.RELEASE_SERVER_USER }}
key: ${{ secrets.RELEASE_SERVER_KEY }}
source: "./scripts/deploy.sh"
target: "/home/ubuntu/"
- name: docker-compose.yml EC2 인스턴스로 전송
uses: appleboy/scp-action@master
with:
host: ${{ secrets.RELEASE_SERVER_IP }}
username: ${{ secrets.RELEASE_SERVER_USER }}
key: ${{ secrets.RELEASE_SERVER_KEY }}
source: "./docker-compose.yml"
target: "/home/ubuntu/"
deploy-cd: # job#2
needs: deploy-ci
runs-on: ubuntu-22.04
steps: # EC2 인스턴스 내부에서 이루어지는 작업
- name: 도커 컨테이너 실행 및 이미지 Pull
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.RELEASE_SERVER_IP }}
username: ${{ secrets.RELEASE_SERVER_USER }}
key: ${{ secrets.RELEASE_SERVER_KEY }}
script: |
cd ~
sudo docker pull yejunpark1/motivoo-server
sudo chmod 777 ./deploy.sh
cp ./scripts/deploy.sh ./deploy.sh
./deploy.sh
docker image prune -f