-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
name: CD | ||
|
||
on: | ||
push: | ||
branches: [ "develop" ] | ||
pull_request: | ||
branches: [ "develop" ] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
|
||
build: | ||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
# 지정한 저장소(현재 REPO)에서 코드를 워크플로우 환경으로 가져오도록 하는 github action | ||
- uses: actions/checkout@v4 | ||
|
||
# open jdk 21 버전 환경 세팅 | ||
- name: Set up JDK 21 | ||
uses: action/setup-java@v3 | ||
with: | ||
java-version: '21' | ||
distribution: 'corretto' | ||
|
||
# Gradle 빌드 | ||
- name: Build with Gradle | ||
run: | | ||
chmod +x ./gradlew | ||
./gradlew clean build -x test | ||
# dockerfile을 통해 이미지 빌드, 이를 docker repo로 push | ||
- name: Build the Docker image | ||
run: | | ||
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | ||
docker build -f Dockerfile -t ${{ secrets.DOCKER_REPO }} . | ||
docker push ${{ secrets.DOCKER_REPO }} | ||
# appleboy/ssh-action@master 액션으로 EC2 컨테이너 ssh 접속, 스크립트 실행 | ||
- name: Deploy to server | ||
uses: appleboy/ssh-action@master | ||
id: deploy | ||
with: | ||
host: ${{ secrets.HOST }} | ||
username: ${{ secrets.USERNAME }} | ||
key: ${{ secrets.KEY }} | ||
envs: GITHUB_SHA | ||
script: | | ||
sudo docker rm -f ${docker ps -qa} | ||
sudo docker pull ${{ secrets.DOCKER_REPO }} | ||
docker-compose up -d | ||
docker image prune -f |