Deploy Spring Boot App #76
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: | |
workflow_run: | |
workflows: [Backend CI] | |
types: | |
- completed | |
jobs: | |
deploy: | |
# 실행 환경 설정 | |
runs-on: ubuntu-latest | |
environment: envs | |
# 이전 워크 플로우 성공시 | |
if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
steps: | |
# 저장공간 설정 | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
# artifact 다운로드 | |
- name: Download Artifact | |
uses: actions/download-artifact@v4 | |
with: | |
run-id: ${{ github.event.workflow_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 | |
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 | |
# - name: Build Docker Image | |
# run: | | |
# docker build -t your-docker-username/your-image-name:latest . | |
# docker login -u your-docker-username -p ${{ secrets.DOCKER_PASSWORD }} | |
# docker push your-docker-username/your-image-name:latest | |
# | |
# - name: Deploy to Server | |
# run: | | |
# scp build/libs/*.jar username@server_ip:/path/to/deployment/directory | |
# ssh username@server_ip "sudo systemctl restart your-spring-boot-service" | |
# env: | |
# SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} | |
# | |
# - name: Deploy Docker Compose | |
# run: | | |
# ssh username@server_ip "cd /path/to/docker-compose-directory && docker-compose up -d" | |
# env: | |
# SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} |