-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
186 additions
and
8 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
name: ShowPot-Dev-CD | ||
|
||
on: | ||
push: | ||
branches: | ||
- develop | ||
|
||
jobs: | ||
build-and-deploy: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: '17' | ||
distribution: 'liberica' | ||
cache: gradle | ||
|
||
- name: Setup Gradle | ||
uses: gradle/actions/setup-gradle@v3 | ||
|
||
- name: Copy Secrets | ||
env: | ||
ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY }} | ||
SECRET_KEY: ${{ secrets.AWS_SECRET_KEY }} | ||
run: | ||
echo $ACCESS_KEY > ./app/src/main/resources/application-dev.yml | ||
echo $SECRET_KEY > ./app/src/main/resources/application-dev.yml | ||
|
||
- name: Build with Gradle Wrapper | ||
run: ./gradlew clean build | ||
|
||
- name: Prepare File for Deployment | ||
run: | | ||
mkdir -p deployment | ||
cp Dockerfile docker-compose.yml deployment/ | ||
cp -r ./app/build/libs deployment/ | ||
- name: Get Github Actions IP | ||
id: ip | ||
uses: haythem/[email protected] | ||
|
||
- name: Configure AWS Credentials | ||
uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }} | ||
aws-region: ap-northeast-2 | ||
|
||
- name: Add Github Actions IP on Security Group | ||
run: | | ||
aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_DEV_SECURITY_GROUP_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32 | ||
- name: Upload files to EC2 | ||
uses: appleboy/[email protected] | ||
with: | ||
host: ${{ secrets.EC2_DEV_HOST }} | ||
username: ec2-user | ||
key: ${{ secrets.EC2_DEV_SSH_PRIVATE_KEY }} | ||
source: "deployment/*" | ||
target: "/home/ec2-user/" | ||
|
||
- name: Deploy using Docker Compose | ||
uses: appleboy/[email protected] | ||
with: | ||
host: ${{ secrets.EC2_DEV_HOST }} | ||
username: ec2-user | ||
key: ${{ secrets.EC2_DEV_SSH_PRIVATE_KEY }} | ||
script: | | ||
cd /home/ec2-user/deployment/ | ||
docker-compose down | ||
docker-compose up -d --build | ||
- name: Remove Github Actions IP from Security Group | ||
if: always() | ||
run: | | ||
aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_DEV_SECURITY_GROUP_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32 | ||
- name: Backend CD for Dev Server Discord Notification | ||
uses: sarisia/actions-status-discord@v1 | ||
if: success() | ||
with: | ||
title: ✅ 개발 서버 배포 프로세스가 완료되었습니다! ✅ | ||
webhook: ${{ secrets.DISCORD_WEBHOOK_URL }} | ||
content: "<@1084774841460215839> <@281597829636423682> 배포가 정상적으로 이뤄졌는지 확인해주세요!" | ||
color: 00FF00 | ||
username: showPot-Bot | ||
avatar_url: ${{ secrets.DISCORD_NOTIFICATION_SUCCESS_AVATAR_URL }} | ||
|
||
- name: Backend CD for Dev Server Discord Notification | ||
uses: sarisia/actions-status-discord@v1 | ||
if: failure() | ||
with: | ||
title: ❗️개발 서버 배포 프로세스가 실패했습니다! ❗️ | ||
webhook: ${{ secrets.DISCORD_WEBHOOK_URL }} | ||
color: FF0000 | ||
username: showPot-Bot | ||
avatar_url: ${{ secrets.DISCORD_NOTIFICATION_FAILED_AVATAR_URL }} |
File renamed without changes.
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
FROM openjdk:21-jdk-slim | ||
ARG JAR_FILE_PATH=libs/*.jar | ||
COPY ${JAR_FILE_PATH} app.jar | ||
ENTRYPOINT ["java", "-jar", "app.jar"] |
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
17 changes: 17 additions & 0 deletions
17
app/api/src/main/java/org/example/health/HealthController.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.example.health; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@Tag(name = "서버 상태") | ||
public class HealthController { | ||
|
||
@GetMapping("/health") | ||
@Operation(summary = "서버 상태 체크") | ||
public String health() { | ||
return "OK"; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
spring: | ||
jpa: | ||
hibernate: | ||
ddl-auto: create | ||
show-sql: true | ||
open-in-view: false | ||
generate-ddl: true |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,43 @@ | ||
version: '3' | ||
|
||
services: | ||
postgresql: | ||
container_name: yapp_postgresql | ||
image: postgres:14 | ||
environment: | ||
- 'POSTGRES_DATABASE=yapp' | ||
- 'POSTGRES_USER=local' | ||
- 'POSTGRES_PASSWORD=local' | ||
POSTGRES_DB: yapp | ||
POSTGRES_USER: yapp | ||
POSTGRES_PASSWORD: yapp | ||
ports: | ||
- '5432' | ||
- '5432:5432' | ||
restart: always | ||
networks: | ||
- app-network | ||
|
||
redis: | ||
container_name: yapp_redis | ||
image: redis:alpine | ||
ports: | ||
- '6379:6379' | ||
- '6379:6379' | ||
networks: | ||
- app-network | ||
|
||
app: | ||
image: yapp | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
environment: | ||
SPRING_DATASOURCE_URL: jdbc:postgresql://postgresql:5432/yapp | ||
SPRING_DATASOURCE_USERNAME: yapp | ||
SPRING_DATASOURCE_PASSWORD: yapp | ||
SPRING_REDIS_HOST: redis | ||
SPRING_REDIS_PORT: 6379 | ||
ports: | ||
- '8080:8080' | ||
depends_on: | ||
- postgresql | ||
- redis | ||
networks: | ||
- app-network | ||
|
||
networks: | ||
app-network: |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
|
||
# Git 리포지토리에서 최신 코드를 가져옵니다. | ||
git pull origin develop | ||
|
||
# 애플리케이션 빌드 | ||
./gradlew app:build | ||
|
||
# Docker Compose를 사용하여 컨테이너 실행 | ||
docker-compose down | ||
docker-compose up -d --build |