Merge pull request #167 from 2024-startup/BE/fix/#166 #93
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
# 워크플로우 이름 설정 | |
name: Deploy Spring Boot App | |
on: | |
push: | |
branches: | |
- dev | |
jobs: | |
deploy: | |
# 실행 환경 설정 | |
runs-on: ubuntu-latest | |
environment: envs | |
steps: | |
# 저장공간 설정 | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
# 이전 workflow의 run ID를 가져오기 위한 설정 | |
- name: Get run ID of "Backend CI" workflow | |
id: get-run-id | |
run: | | |
OTHER_REPO="${{ github.repository }}" | |
WF_NAME="Backend CI" | |
RUN_ID=$(gh run --repo "${OTHER_REPO}" list --workflow "${WF_NAME}" --json databaseId --jq .[0].databaseId) | |
echo "Detected latest run id of ${RUN_ID} for workflow ${WF_NAME}" | |
echo "run-id=${RUN_ID}" >> "$GITHUB_OUTPUT" | |
env: | |
GH_TOKEN: ${{ github.token }} | |
# artifact 다운로드 | |
- name: Download Artifact | |
uses: actions/download-artifact@v4 | |
with: | |
run-id: ${{ steps.get-run-id.outputs.run-id }} | |
github-token: ${{ github.token }} | |
name: server-jar | |
path: ./app | |
# docker-compose.yml 파일 이동 | |
- name: Move docker-compose_for_action.yml | |
run: | | |
mv ./docker-compose_for_action.yml ./app/docker-compose_for_action.yml | |
# Docker 이미지를 서버로 전송 | |
- name: file to Server | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.REMOTE_SSH_HOST }} | |
username: ${{ secrets.REMOTE_SSH_USERNAME }} | |
key: ${{ secrets.REMOTE_SSH_KEY }} | |
source: ./app/* | |
target: ./ | |
# 서버에서 Docker 이미지 빌드 및 실행 | |
- name: Deploy to Server | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.REMOTE_SSH_HOST }} | |
username: ${{ secrets.REMOTE_SSH_USERNAME }} | |
key: ${{ secrets.REMOTE_SSH_KEY }} | |
script: | | |
cd ./app | |
docker-compose -f docker-compose_for_action.yml down | |
echo "SPRING_DATASOURCE_URL=${{ secrets.SPRING_DATASOURCE_URL }}" >> ./backend.env | |
echo "SPRING_DATASOURCE_USERNAME=${{ secrets.SPRING_DATASOURCE_USERNAME }}" >> ./backend.env | |
echo "SPRING_DATASOURCE_PASSWORD=${{ secrets.SPRING_DATASOURCE_PASSWORD }}" >> ./backend.env | |
echo "SPRING_DATASOURCE_DRIVER_CLASS_NAME=${{ secrets.SPRING_DATASOURCE_DRIVER_CLASS_NAME }}" >> ./backend.env | |
echo "SPRING_JPA_DATABASE=${{ secrets.SPRING_JPA_DATABASE }}" >> ./backend.env | |
echo "S3_BUCKET_URL=${{ secrets.S3_BUCKET_URL }}" >> ./backend.env | |
echo "S3_BUCKET_NAME=${{ secrets.S3_BUCKET_NAME }}" >> ./backend.env | |
echo "S3_ACCESS_KEY=${{ secrets.S3_ACCESS_KEY }}" >> ./backend.env | |
echo "S3_SECRET_KEY=${{ secrets.S3_SECRET_KEY }}" >> ./backend.env | |
docker-compose -f docker-compose_for_action.yml up -d |