Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE/feat] AI 서버 분리로 인한 MariaDB 서버 구축 및 EC2 사양 변경 #384

Merged
merged 3 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
109 changes: 109 additions & 0 deletions .github/workflows/prodWorkflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: testAndDeploy

on:
pull_request:
branches:
- release
- main
types:
- closed

defaults:
run:
working-directory: ./BE/exceed

jobs:
build:
runs-on: ubuntu-22.04
permissions:
contents: read
pull-requests: write

steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Cache Gradle
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-

- name: Build with Gradle Wrapper
run: ./gradlew build

- name: Jacoco Report to PR
id: jacoco
uses: madrapps/[email protected]
with:
paths: ${{ github.workspace }}/**/build/reports/jacoco/test/jacocoTestReport.xml
token: ${{ secrets.GITHUB_TOKEN }}

- name: Send docker-compose.yml
uses: appleboy/scp-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
source: ./BE/exceed/docker-compose-prod.yml
target: /home/ubuntu/backend-deploy

- name: Send resources-develop-environment
uses: appleboy/scp-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
source: ./BE/exceed/resources/gaebaljip-prod-environment
target: /home/ubuntu/backend-deploy

- name: Create .env.prod file
run: |
echo "${{ secrets.ENV_PROD_VARS }}" > .env.prod

- name: Send env file
uses: appleboy/scp-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
source: ./BE/exceed/.env.prod
target: /home/ubuntu/backend-deploy

- name: Docker Image Build
run: docker build -f Dockerfile-prod -t ${{ secrets.DOCKER_HUB_USER_NAME }}/gaebaljip-prod:latest .

- name: Docker Hub Login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USER_NAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}

- name: docker Hub Push
run: docker push ${{ secrets.DOCKER_HUB_USER_NAME }}/gaebaljip-prod:latest

- name: SSH Deploy
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
script: |
cd backend-deploy/BE/exceed
sudo docker-compose down
sudo docker pull ${{ secrets.DOCKER_HUB_USER_NAME }}/gaebaljip-prod:latest
sudo docker-compose up --build -d
sudo docker image prune -a -f


3 changes: 1 addition & 2 deletions BE/exceed/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ src/main/resources/static/docs/api-doc.html

### env
.env
env-dev

.env.prod

### jmh

Expand Down
2 changes: 1 addition & 1 deletion BE/exceed/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ COPY ./food_data.csv ./food_data.csv
EXPOSE 8080

# CMD 명령어에서 CSV 파일의 위치를 절대 경로로 지정
CMD ["java", "-jar", "-Dspring.profiles.active=dev", "eatceed.jar", "./food_data.csv"]
CMD ["java", "-jar", "-Dspring.profiles.active=dev", "eatceed.jar", "./food_data.csv"]
18 changes: 18 additions & 0 deletions BE/exceed/Dockerfile-prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM openjdk:17-oracle

ENV TZ=Asia/Seoul

# 앱을 위한 작업 디렉토리 설정
WORKDIR /app

# JAR 파일 복사
ARG JAR_FILE="./build/libs/*.jar"
COPY ${JAR_FILE} eatceed.jar

# CSV 파일 복사
COPY ./food_data.csv ./food_data.csv

EXPOSE 8080

# CMD 명령어에서 CSV 파일의 위치를 절대 경로로 지정
CMD ["java", "-jar", "-Dspring.profiles.active=prod", "eatceed.jar", "./food_data.csv"]
2 changes: 1 addition & 1 deletion BE/exceed/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ plugins {
}

group = 'com.gaebaljip'
version = '0.0.1-SNAPSHOT'
version = '1.0.0'

java {
sourceCompatibility = '17'
Expand Down
76 changes: 76 additions & 0 deletions BE/exceed/docker-compose-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
version: '3'
services:
eatceed-redis:
image: redis:alpine
container_name: gaebaljip-redis
command: redis-server --port 6379
expose:
- "6379"
networks:
- gaebaljip-network

eatceed-backend:
image: hwangdaesun/gaebaljip-prod:latest
container_name: gaebaljip-spring
ports:
- 8080:8080
depends_on:
- eatceed-redis
environment:
- RDS_DATABASE_ENDPOINT=${RDS_DATABASE_ENDPOINT}
- RDS_PORT=${RDS_PORT}
- RDS_DB_NAME=${RDS_DB_NAME}
- RDS_DATABASE_USERNAME=${RDS_DATABASE_USERNAME}
- RDS_DATABASE_PASSWORD=${RDS_DATABASE_PASSWORD}
- S3_BUCKET_NAME=${S3_BUCKET_NAME}
- CLOUD_AWS_ACCESS_KEY=${CLOUD_AWS_ACCESS_KEY}
- CLOUD_AWS_SECRET_KEY=${CLOUD_AWS_SECRET_KEY}
- JWT_SECRET=${JWT_SECRET}
- SES_MAIL_ADDRESS=${SES_MAIL_ADDRESS}
- ENCRYPTION_SPEC=${ENCRYPTION_SPEC}
- ENCRYPTION_SECRET=${ENCRYPTION_SECRET}
- ENCRYPTION_ALGORITHM=${ENCRYPTION_ALGORITHM}
- SPRING_REDIS_HOST=gaebaljip-redis
- SPRING_REDIS_PORT=6379
networks:
- gaebaljip-network
restart: "always"

grafana:
image: grafana/grafana:latest
container_name: grafana
restart: "always"
ports:
- "3000:3000"
volumes:
- grafana-data:/var/lib/grafana
- ./resources/gaebaljip-prod-environment/grafana/provisioning/:/etc/grafana/provisioning/
environment:
- GF_SERVER_ROOT_URL=localhost:3000
- GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_PASSWORD}
depends_on:
- prometheus
networks:
- gaebaljip-network

prometheus:
image: prom/prometheus:latest
container_name: prometheus
restart: "always"
ports:
- "9090:9090"
volumes:
- ./resources/gaebaljip-prod-environment/prometheus/config:/etc/prometheus/
- prometheus-data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
networks:
- gaebaljip-network

volumes:
grafana-data:
prometheus-data:

networks:
gaebaljip-network:
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
global:
scrape_interval: 15s
evaluation_interval: 15s
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
rule_files:
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
#추가
- job_name: "spring-actuator"
metrics_path: '/actuator/prometheus'
scrape_interval: 1s
static_configs:
- targets: ['3.37.117.77:8080']
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

import com.gaebaljip.exceed.adapter.out.jpa.food.FoodEntity;
Expand All @@ -22,6 +23,7 @@
@Log4j2
@RequiredArgsConstructor
@ConditionalOnExpression("${ableAutoComplete:true}")
@Profile("!prod")
public class MariaDBAutoComplete implements ApplicationRunner {

private final FoodPort foodPort;
Expand Down
73 changes: 69 additions & 4 deletions BE/exceed/src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@ spring:
driver-class-name: org.mariadb.jdbc.Driver
username: ${RDS_DATABASE_USERNAME}
password: ${RDS_DATABASE_PASSWORD}
redis:
host: ${SPRING_REDIS_HOST}
port: ${SPRING_REDIS_PORT}
jpa:
hibernate:
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
dialect: org.hibernate.dialect.MariaDBDialect
ddl-auto: none
show-sql: true
defer-datasource-initialization: true
ddl-auto: validate
properties:
hibernate:
show_sql: true
format_sql: true
use_sql_comments: true
cloud:
aws:
credentials:
Expand All @@ -32,12 +38,71 @@ encryption:
jwt:
secret: ${JWT_SECRET}

exceed:
url : https://eatceed.net

springdoc:
api-docs:
path: /api-docs # API 문서 생성 경로
groups:
enabled: true
swagger-ui:
path: /index.html # Swagger-ui 경로
enabled: true
groups-order: asc
tags-sorter: alpha
operations-sorter: alpha
display-request-duration: true
doc-expansion: none
cache:
disabled: true
override-with-generic-response: false
model-and-view-allowed: true
default-consumes-media-type: application/json
default-produces-media-type: application/json

ableAutoComplete: true

management:
endpoints:
web:
exposure:
include: "*"
exclude: "env, beans"

logging:
level:
org:
hibernate:
type:
descriptor:
sql: trace
sql: trace

org:
quartz:
scheduler:
instanceName: gaebaljip
instanceId: AUTO
rmi:
export: false
proxy: false
threadPool:
class: org.quartz.simpl.SimpleThreadPool
threadCount: 5
context:
key:
QuartzTopic: QuartzPorperties
jobStore:
class: org.quartz.impl.jdbcjobstore.JobStoreTX
driverDelegateClass: org.quartz.impl.jdbcjobstore.StdJDBCDelegate
tablePrefix: QRTZ_
isClustered: true
dataSource: gaebaljip
dataSource:
gaebaljip:
provider: hikaricp
driver: org.mariadb.jdbc.Driver
URL: jdbc:mariadb://${RDS_DATABASE_ENDPOINT}:${RDS_PORT}/${RDS_DB_NAME}?serverTimezone=Asia/Seoul
user: ${RDS_DATABASE_USERNAME}
password: ${RDS_DATABASE_PASSWORD}
maxConnections: 30
Loading