Skip to content

[FIX] CD 플로우 수정 (#23) #23

[FIX] CD 플로우 수정 (#23)

[FIX] CD 플로우 수정 (#23) #23

Workflow file for this run

name: CD
on:
pull_request:
branches: ["develop"]
workflow_dispatch:
permissions:
contents: write
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'adopt'
- name: Cache Gradle packages
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Set environment variables
env:
KAKAO_ADMIN_KEY: ${{ secrets.KAKAO_ADMIN_KEY }}
JWT_ACCESS_TOKEN_SECRET: ${{ secrets.JWT_ACCESS_TOKEN_SECRET }}
JWT_REFRESH_TOKEN_SECRET: ${{ secrets.JWT_REFRESH_TOKEN_SECRET }}
STORAGE_DATABASE_CORE_DB_URL: ${{ secrets.STORAGE_DATABASE_CORE_DB_URL }}
STORAGE_DATABASE_CORE_DB_USERNAME: ${{ secrets.STORAGE_DATABASE_CORE_DB_USERNAME }}
STORAGE_DATABASE_CORE_DB_PASSWORD: ${{ secrets.STORAGE_DATABASE_CORE_DB_PASSWORD }}
AWS_IOT_ENDPOINT: ${{ secrets.AWS_IOT_ENDPOINT }}
AWS_IOT_CLIENTID: ${{ secrets.AWS_IOT_CLIENTID }}
AWS_IOT_CERTIFICATE: ${{ secrets.AWS_IOT_CERTIFICATE }}
AWS_IOT_PRIVATE_KEY: ${{ secrets.AWS_IOT_PRIVATE_KEY }}
run: echo "Environment variables are set"
- name: Build with Gradle
uses: gradle/gradle-build-action@v3
with:
arguments: build
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/dev:latest
- name: Add SSH key
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Deploy to server
run: |
ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} << 'EOF'
docker pull ${{ secrets.DOCKER_USERNAME }}/dev:latest
docker stop app || true
docker rm app || true
docker run -d --name app -p 80:80 ${{ secrets.DOCKER_USERNAME }}/dev:latest
EOF