Skip to content

Commit

Permalink
Merge pull request #351 from Team-Smeme/develop
Browse files Browse the repository at this point in the history
deploy: 실서버v4 배포 (임시)
  • Loading branch information
thguss authored Dec 3, 2024
2 parents 7eca1c3 + 2d4bcec commit 5754c9d
Show file tree
Hide file tree
Showing 72 changed files with 1,170 additions and 238 deletions.
20 changes: 6 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

jobs:
build:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest

steps:
- name: Checkout
Expand All @@ -16,30 +16,22 @@ jobs:
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'temurin'
distribution: 'corretto'
cache: gradle

- name: Create application-secret.yml
run: |
pwd
cd ./smeem-bootstrap/src/main/resources
touch ./application-secret.yml
echo "${{ secrets.APPLICATION_SECRET_YML }}" >> ./application-secret.yml
cat ./application-secret.yml
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_DEV }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY_DEV }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Set FCM_JSON_PATH
run: echo "FCM_JSON_PATH=smeem-output-notification/src/main/resources/firebase-config/smeem_fcm_dev.json" >> $GITHUB_ENV
run: |
echo "FCM_JSON_PATH=smeem-output-notification/src/main/resources/firebase-config/smeem_fcm_dev.json" >> $GITHUB_ENV
- name: Create FireBase JSON file From AWS
run: aws s3 cp --region ap-northeast-2 ${{ secrets.AWS_S3_FCM_JSON_URI_DEV }} ${{ env.FCM_JSON_PATH }}

- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
shell: bash
Expand Down
89 changes: 44 additions & 45 deletions .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
@@ -1,71 +1,75 @@
name: deploy-dev
name: CD-dev

on:
release:
types: [ published ]
types: [ "published" ]

jobs:
build:
runs-on: ubuntu-20.04
deploy-ci:
runs-on: ubuntu-latest

steps:
- name: Checkout
- name: Checkout Latest Repo
uses: actions/checkout@v3
# 최신 저장소에서 체크아웃

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'temurin'
cache: gradle
distribution: 'corretto'
java-version: '17'
# 자바 버전을 JDK 17로 설정

- name: Create application-secret.yml
run: |
pwd
cd ./smeem-bootstrap/src/main/resources
touch ./application-secret.yml
echo "${{ secrets.APPLICATION_SECRET_YML }}" >> ./application-secret.yml
cat ./application-secret.yml
- name: Configure AWS credentials
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_DEV }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY_DEV }}
aws-region: ap-northeast-2
# AWS 자격 증명 설정

- name: Set FCM_JSON_PATH
run: echo "FCM_JSON_PATH=smeem-output-notification/src/main/resources/firebase-config/smeem_fcm_dev.json" >> $GITHUB_ENV
- name: Set FCM JSON File Path
run: |
echo "FCM_JSON_PATH=smeem-output-notification/src/main/resources/firebase-config/smeem_fcm_dev.json" >> $GITHUB_ENV
# FCM JSON 파일 위치 경로 설정

- name: Create FireBase JSON file From AWS
- name: Create FCM JSON File from AWS
run: aws s3 cp --region ap-northeast-2 ${{ secrets.AWS_S3_FCM_JSON_URI_DEV }} ${{ env.FCM_JSON_PATH }}
# FCM JSON 파일 복사

- name: Grant execute permission for gradlew
run: chmod +x gradlew
shell: bash
# gradlew 파일에 실행 권한 부여

- name: Build with Gradle
run: |
chmod +x ./gradlew
./gradlew build -x test
run: ./gradlew clean build -x test
shell: bash
# 그래들로 빌드

- name: Set docker
- name: Set Docker
uses: docker/[email protected]
# 도커 설정

- name: Login docker
- name: Login Docker
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKERHUB_LOGIN_USERNAME_DEV }}
password: ${{ secrets.DOCKERHUB_LOGIN_ACCESSTOKEN_DEV }}
# 도커에 로그인

- name: Build docker image
- name: Docker Build
run: |
docker build --platform linux/amd64 -t smeemdev/smeem-dev:latest -f Dockerfile-dev .
docker push smeemdev/smeem-dev:latest
deploy-cd:
needs: build
runs-on: ubuntu-20.04
needs: deploy-ci
runs-on: ubuntu-latest
# deploy-ci 이후 작업 실행

steps:
- name: SSH로 서버 접속
- name: Connect to EC2 and Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.RELEASE_SERVER_IP_DEV }}
Expand All @@ -78,19 +82,14 @@ jobs:
wget https://raw.githubusercontent.com/Team-Smeme/Smeme-server-renewal/develop/script/deploy.sh -O deploy.sh
chmod +x deploy.sh
# .env 파일 추가
if ! grep -q "REGISTRY_URL=" .env; then
echo "REGISTRY_URL=${{ secrets.REGISTRY_URL_DEV }}" >> .env
fi
if ! grep -q "IMAGE_NAME=" .env; then
echo "IMAGE_NAME=${{ secrets.IMAGE_NAME_DEV }}" >> .env
fi
if ! grep -q "SECRET_MANAGER_TOKEN=" .env; then
echo "SECRET_MANAGER_TOKEN=${{ secrets.SECRET_MANAGER_TOKEN }}" >> .env
fi
if ! grep -q "SECRET_MANAGER_WORKSPACE_ID=" .env; then
echo "SECRET_MANAGER_WORKSPACE_ID=${{ secrets.SECRET_MANAGER_WORKSPACE_ID }}" >> .env
fi
# 기존 .env 파일 삭제 및 새로 생성
rm -f .env # 기존 .env 파일을 삭제합니다.
# .env 파일 새로 생성
echo "REGISTRY_URL=${{ secrets.REGISTRY_URL_DEV }}" >> .env
echo "IMAGE_NAME=${{ secrets.IMAGE_NAME_DEV }}" >> .env
echo "SECRET_MANAGER_TOKEN=${{ secrets.SECRET_MANAGER_TOKEN }}" >> .env
echo "SECRET_MANAGER_WORKSPACE_ID=${{ secrets.SECRET_MANAGER_WORKSPACE_ID }}" >> .env
# 배포 스크립트 실행
sudo ./deploy.sh
83 changes: 41 additions & 42 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
@@ -1,71 +1,75 @@
name: deploy-prod
name: CD-prod

on:
push:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-20.04
deploy-ci:
runs-on: ubuntu-latest

steps:
- name: Checkout
- name: Checkout Latest Repo
uses: actions/checkout@v3
# 최신 저장소에서 체크아웃

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'temurin'
cache: gradle
distribution: 'corretto'
java-version: '17'
# 자바 버전을 JDK 17로 설정

- name: Create application-secret.yml
run: |
pwd
cd ./smeem-bootstrap/src/main/resources
touch ./application-secret.yml
echo "${{ secrets.APPLICATION_SECRET_YML }}" >> ./application-secret.yml
cat ./application-secret.yml
- name: Configure AWS credentials
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_PROD_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_PROD_SECRET_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
aws-region: ap-northeast-2
# AWS 자격 증명 설정

- name: Set FCM_JSON_PATH
run: echo "FCM_JSON_PATH=smeem-output-notification/src/main/resources/firebase-config/smeem_fcm_prod.json" >> $GITHUB_ENV
- name: Set FCM JSON File Path
run: |
echo "FCM_JSON_PATH=smeem-output-notification/src/main/resources/firebase-config/smeem_fcm_prod.json" >> $GITHUB_ENV
# FCM JSON 파일 위치 경로 설정

- name: Create FireBase JSON file From AWS
- name: Create FCM JSON File from AWS
run: aws s3 cp --region ap-northeast-2 ${{ secrets.AWS_S3_FCM_JSON_URI_PROD }} ${{ env.FCM_JSON_PATH }}
# FCM JSON 파일 복사

- name: Grant execute permission for gradlew
run: chmod +x gradlew
shell: bash
# gradlew 파일에 실행 권한 부여

- name: Build with Gradle
run: |
chmod +x ./gradlew
./gradlew build -x test
run: ./gradlew clean build -x test
shell: bash
# 그래들로 빌드

- name: Set docker
- name: Set Docker
uses: docker/[email protected]
# 도커 설정

- name: Login docker
- name: Login Docker
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKERHUB_LOGIN_USERNAME_PROD }}
password: ${{ secrets.DOCKERHUB_LOGIN_ACCESSTOKEN_PROD }}
# 도커에 로그인

- name: Build docker image
- name: Docker Build
run: |
docker build --platform linux/amd64 -t smeemprod/smeem-prod:latest -f Dockerfile-prod .
docker push smeemprod/smeem-prod:latest
deploy-cd:
needs: build
runs-on: ubuntu-20.04
needs: deploy-ci
runs-on: ubuntu-latest
# deploy-ci 이후 작업 실행

steps:
- name: SSH로 서버 접속
- name: Connect to EC2 and Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.RELEASE_SERVER_IP_PROD }}
Expand All @@ -78,19 +82,14 @@ jobs:
wget https://raw.githubusercontent.com/Team-Smeme/Smeme-server-renewal/main/script/deploy.sh -O deploy.sh
chmod +x deploy.sh
# .env 파일 추가
if ! grep -q "REGISTRY_URL=" .env; then
echo "REGISTRY_URL=${{ secrets.REGISTRY_URL_PROD }}" >> .env
fi
if ! grep -q "IMAGE_NAME=" .env; then
echo "IMAGE_NAME=${{ secrets.IMAGE_NAME_PROD }}" >> .env
fi
if ! grep -q "SECRET_MANAGER_TOKEN=" .env; then
echo "SECRET_MANAGER_TOKEN=${{ secrets.SECRET_MANAGER_TOKEN }}" >> .env
fi
if ! grep -q "SECRET_MANAGER_WORKSPACE_ID=" .env; then
echo "SECRET_MANAGER_WORKSPACE_ID=${{ secrets.SECRET_MANAGER_WORKSPACE_ID }}" >> .env
fi
# 기존 .env 파일 삭제 및 새로 생성
rm -f .env # 기존 .env 파일을 삭제합니다.
# .env 파일 새로 생성
echo "REGISTRY_URL=${{ secrets.REGISTRY_URL_PROD }}" >> .env
echo "IMAGE_NAME=${{ secrets.IMAGE_NAME_PROD }}" >> .env
echo "SECRET_MANAGER_TOKEN=${{ secrets.SECRET_MANAGER_TOKEN }}" >> .env
echo "SECRET_MANAGER_WORKSPACE_ID=${{ secrets.SECRET_MANAGER_WORKSPACE_ID }}" >> .env
# 배포 스크립트 실행
sudo ./deploy.sh
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

## Architecture
### Server Architecture
<img alt="image" width="600" src="https://github.com/user-attachments/assets/fb290cc9-1f98-4536-b4cb-c7fb5b421580"/>
<img width="900" alt="image" src="https://github.com/user-attachments/assets/11e56163-abaa-47c6-af1c-e677897e12cd">

<br/>

Expand Down
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.2.1'
id 'org.springframework.boot' version '3.3.4'
id 'io.spring.dependency-management' version '1.1.4'
id 'application'
}
Expand All @@ -12,6 +12,8 @@ allprojects {

repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }
}
}

Expand Down
26 changes: 26 additions & 0 deletions docker/monitoring/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: '3.8'

services:
prometheus:
image: prom/prometheus:latest
container_name: prometheus
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
command:
- --config.file=/etc/prometheus/prometheus.yml
ports:
- "9090:9090"
networks:
- monitoring-network

grafana:
image: grafana/grafana:latest
container_name: grafana
ports:
- "3000:3000"
networks:
- monitoring-network

networks:
monitoring-network:
driver: bridge
8 changes: 8 additions & 0 deletions docker/monitoring/prometheus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
global:
scrape_interval: 15s

scrape_configs:
- job_name: prometheus
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['host.docker.internal:8080']
Loading

0 comments on commit 5754c9d

Please sign in to comment.