Skip to content

Secret Message Backend Prod Server CD #56

Secret Message Backend Prod Server CD

Secret Message Backend Prod Server CD #56

name: Secret Message Backend Prod Server CD
on:
workflow_dispatch:
jobs:
build:
name: 빌드
runs-on: ubuntu-22.04
steps:
- name: workflow_dispatch에서 지정한 branch로 checkout
uses: actions/checkout@v3
- name: JDK 17로 설정
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'corretto'
- name: Gradle에 실행 권한 부여
run: chmod +x gradlew
- name: gradle 빌드
run: ./gradlew build
- name: 도커 허브에 로그인
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: 도커 빌더 생성 및 부팅
uses: docker/setup-buildx-action@v2
- name: 도커 이미지 빌드 및 푸시
uses: docker/build-push-action@v4
with:
file: Dockerfile
context: .
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/uni-11th-team5:latest
deploy:
needs: build
name: 배포
runs-on: [ self-hosted, prod ]
steps:
- name: 실행중인 도커 제거
run:
sudo docker stop $(sudo docker ps -q --filter "publish=8080" 2>/dev/null) || true
- name: 도커 pull
run:
sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/uni-11th-team5
- name: 새로 빌드한 도커 실행
run:
sudo nohup docker run -p 8080:8080 ${{ secrets.DOCKERHUB_USERNAME }}/uni-11th-team5 --DB_HOSTNAME=${{ secrets.DB_HOSTNAME }} --DB_PORT=${{ secrets.DB_PORT }} --DB_DATABASE=${{ secrets.DB_DATABASE }} --DB_USERNAME=${{ secrets.DB_USERNAME }} --DB_PASSWORD=${{ secrets.DB_PASSWORD }} --JWT_SECRET=${{ secrets.JWT_SECRET}} > ~/logs/be-log.txt 2>&1 &