Skip to content

Merge pull request #84 from dnd-side-project/feat/#83 #51

Merge pull request #84 from dnd-side-project/feat/#83

Merge pull request #84 from dnd-side-project/feat/#83 #51

Workflow file for this run

name: CI/CD Pipeline
on:
push:
branches: [ dev ]
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set JDK 21 (Temurin)
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 21
cache: gradle
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Build Spring Boot application
run: |
./gradlew clean bootJar -Pprofile=dev
- name: Docker Login (Docker Hub)
run: echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u "${{ secrets.DOCKERHUB_USER }}" --password-stdin
- name: Build & Push Docker image
run: |
docker buildx build --platform linux/arm64 -t ${{ secrets.DOCKERHUB_USER }}/dnd-13th-7-backend:latest --push .
deploy:
needs: build-and-push
runs-on: ubuntu-latest
steps:
- name: Deploy to EC2
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_HOST }}
port: 2222
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_SSH_KEY }}
script: |
set -euo pipefail
APP_DIR=/home/ubuntu/13th-7-backend
mkdir -p "$APP_DIR"
cd "$APP_DIR"
DB_HOST="${{ secrets.DB_HOST }}"
DB_PORT="${{ secrets.DB_PORT }}"
DB_DATABASE="${{ secrets.DB_DATABASE }}"
DB_URL="jdbc:mysql://${DB_HOST}:${DB_PORT}/${DB_DATABASE}"
DB_USERNAME="${{ secrets.DB_USERNAME }}"
DB_PASSWORD="${{ secrets.DB_PASSWORD }}"
GOOGLE_CLIENT_ID="${{ secrets.GOOGLE_CLIENT_ID }}"
GOOGLE_CLIENT_SECRET="${{ secrets.GOOGLE_CLIENT_SECRET }}"
KAKAO_CLIENT_ID="${{ secrets.KAKAO_CLIENT_ID }}"
KAKAO_CLIENT_SECRET="${{ secrets.KAKAO_CLIENT_SECRET }}"
JWT_SECRET_KEY="${{ secrets.JWT_SECRET_KEY }}"
S3_ACCESS_KEY="${{ secrets.S3_ACCESS_KEY }}"
S3_SECRET_KEY="${{ secrets.S3_SECRET_KEY }}"
S3_BUCKET_NAME="${{ secrets.S3_BUCKET_NAME }}"
S3_URL_BASE="${{ secrets.S3_URL_BASE }}"
export NEW_RELIC_LICENSE_KEY="${{ secrets.NEW_RELIC_LICENSE_KEY }}"
export NEW_RELIC_API_KEY="${{ secrets.NEW_RELIC_API_KEY }}"
export NEW_RELIC_ACCOUNT_ID="${{ secrets.NEW_RELIC_ACCOUNT_ID }}"
docker compose down
docker compose pull
docker compose up -d
docker image prune -af