From e27646866e6100a4caf8677c2e93fb33b33977aa Mon Sep 17 00:00:00 2001 From: dldmsql Date: Sun, 8 Oct 2023 15:42:44 +0900 Subject: [PATCH] =?UTF-8?q?hotfix:=20#13=20Dev=20=EC=84=9C=EB=B2=84=20?= =?UTF-8?q?=EB=B0=B0=ED=8F=AC=20=EC=8B=9C,=20application-dev=20=ED=94=84?= =?UTF-8?q?=EB=A1=9C=ED=8D=BC=ED=8B=B0=20=EC=A3=BC=EC=9E=85=20=EB=AA=85?= =?UTF-8?q?=EB=A0=B9=EC=96=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 기존 cd_prod 파일 내에 prod 서버로 배포되도록 타겟 브랜치 develop -> main 으로 변경 및 프로퍼티 주입 명령어 추가 --- .github/workflows/cd_dev.yml | 83 +++++++++++++++++++++++++++++++++++ .github/workflows/cd_prod.yml | 6 +-- 2 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/cd_dev.yml diff --git a/.github/workflows/cd_dev.yml b/.github/workflows/cd_dev.yml new file mode 100644 index 0000000..084e1de --- /dev/null +++ b/.github/workflows/cd_dev.yml @@ -0,0 +1,83 @@ +name: CD for Dev + +on: + push: + branches: [ "develop" ] + +permissions: write-all + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + # 1) 워크플로우 실행 전 기본적으로 체크아웃 필요 + - uses: actions/checkout@v3 + + # 2) JDK 17 버전 설치 + - name: Set up JDK 17 + uses: actions/setup-java@v2 + with: + java-version: 17 + distribution: 'zulu' + + # 3) Gradle Caching + - name: Gradle Cashing + uses: actions/cache@v3 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- + + # 4) Gradle 권한 부여 + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + # 5) Set for application-secret.yml + - name: Make application-secret.yml + run: | + cd ./src/main/resources + touch ./application-secret.yml + echo "${{ secrets.PROPERTIES_SECRET }}" > ./application-secret.yml + shell: bash + - name: Make application-dev.yml + run: | + cd ./src/main/resources + touch ./application-dev.yml + echo "${{ secrets.PROPERTIES_SECRET_DEV }}" > ./application-dev.yml + shell: bash + - name: Make application-prod.yml + run: | + cd ./src/main/resources + touch ./application-prod.yml + echo "${{ secrets.PROPERTIES_SECRET_PROD }}" > ./application-prod.yml + shell: bash + + # 6) 빌드 + - name: Build with gradle + run: ./gradlew bootJar + + # 7) Docker 빌드 & 푸쉬 + - name: docker build and push + run: | + docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} + docker build -f Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY}} . + docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY}} + + # 9) Deploy (DEV-Server) + - name: Deploy (DEV) + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.EC2_HOST }} + username: ${{ secrets.EC2_USERNAME }} + key: ${{ secrets.EC2_KEY }} + script: | + docker stop dev + docker rm dev + sudo docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY}} + sudo docker run -d --name dev -v /var/log/app:/var/log/app -v /etc/localtime:/etc/localtime:ro -e TZ=Asia/Seoul -e ENVIRONMENT_VALUE=-Dspring.profiles.active=dev -p 8085:8080 ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY}}:latest + docker rmi -f $(docker images -f "dangling=true" -q) \ No newline at end of file diff --git a/.github/workflows/cd_prod.yml b/.github/workflows/cd_prod.yml index 939c05d..5582f8b 100644 --- a/.github/workflows/cd_prod.yml +++ b/.github/workflows/cd_prod.yml @@ -1,8 +1,8 @@ -name: CD for Dev +name: CD for Prod on: push: - branches: [ "develop" ] + branches: [ "main" ] permissions: write-all @@ -79,5 +79,5 @@ jobs: docker stop dev docker rm dev sudo docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY}} - sudo docker run -d --name dev -v /var/log/app:/var/log/app -v /etc/localtime:/etc/localtime:ro -e TZ=Asia/Seoul -p 8085:8080 ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY}}:latest + sudo docker run -d --name dev -v /var/log/app:/var/log/app -v /etc/localtime:/etc/localtime:ro -e TZ=Asia/Seoul -e ENVIRONMENT_VALUE=-Dspring.profiles.active=prod -p 8085:8080 ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY}}:latest docker rmi -f $(docker images -f "dangling=true" -q) \ No newline at end of file