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

[chore #173] 운영 서버 / 개발 서버 분리 #174

Merged
merged 11 commits into from
Dec 17, 2024
42 changes: 17 additions & 25 deletions .github/workflows/cd.yml → .github/workflows/cd_dev.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: CD Backend
name: 개발 서버 자동 배포

on:
push:
branches: [ "main", "dev" ]
branches: ["dev"]

permissions:
contents: read
Expand All @@ -14,26 +14,22 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3

# 자바 버전 설정
- name: Set up JDK 17
- name: 자바 버전 설정
uses: actions/setup-java@v3
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

단순 궁금해서 그런데, 이전 영문 네이밍에서 한글 네이밍으로 변경한 이유가 무엇인가요?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

한글로 보는게 가독성도 좋고 주석 추가할 필요도 없는 것 같아서 변경했습니다!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

설정에 이상이 있어서 그런건 아닌거군요. 답변 감사합니다~

with:
java-version: '17'
distribution: 'temurin'

# main 경로 application.yml 파일 생성
- name: Generate application.yml
- name: main 경로 application.yml 파일 생성
run: |
mkdir -p ./src/main/resources
echo "${{ secrets.MAIN_APPLICATION_YML }}" | base64 -d > ./src/main/resources/application.yml

# gradle 권한 부여
- name: Grant execute permission for gradlew
- name: gradle 권한 부여
run: chmod +x ./gradlew
shell: bash

# 빌드 시 캐시 적용
- name: Gradle Caching
- name: 빌드 시 캐시 적용
uses: actions/cache@v3
with:
path: |
Expand All @@ -43,38 +39,34 @@ jobs:
restore-keys: |
${{ runner.os }}-gradle-

# 빌드
- name: Build with Gradle
- name: 빌드
run: ./gradlew build -x test

# 도커 허브 로그인
- name: Docker Hub Login
- name: 도커 허브 로그인
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
username: ${{ secrets.DOCKERHUB_USERNAME_DEV }}
password: ${{ secrets.DOCKERHUB_TOKEN_DEV }}

# 도커 이미지 빌드 및 푸시
- name: docker image build and push
- name: 도커 이미지 빌드 및 푸시
run: |
docker build -f Dockerfile -t ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_APP_NAME }} .
docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_APP_NAME }}
docker build -f Dockerfile -t ${{ secrets.DOCKERHUB_USERNAME_DEV }}/${{ secrets.DOCKERHUB_APP_NAME }} .
docker push ${{ secrets.DOCKERHUB_USERNAME_DEV }}/${{ secrets.DOCKERHUB_APP_NAME }}

deploy:
needs: build-and-push-image
runs-on: ubuntu-latest
steps:
# 서버 백그라운드 실행
- name: pull image and run container
- name: 이미지 pull 받아서 백그라운드 실행
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
host: ${{ secrets.EC2_HOST_DEV }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_KEY }}
key: ${{ secrets.EC2_KEY_DEV }}
port: ${{ secrets.EC2_PORT }}
script: |
cd compose
docker rm -f $(docker ps -qa)
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_APP_NAME }}
docker pull ${{ secrets.DOCKERHUB_USERNAME_DEV }}/${{ secrets.DOCKERHUB_APP_NAME }}
docker-compose up -d
docker system prune -f
72 changes: 72 additions & 0 deletions .github/workflows/cd_prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: 운영 서버 자동 배포

on:
push:
branches: ["prod"]

permissions:
contents: read

jobs:
build-and-push-image:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: 자바 버전 설정
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- name: main 경로 application.yml 파일 생성
run: |
mkdir -p ./src/main/resources
echo "${{ secrets.PROD_APPLICATION_YML }}" | base64 -d > ./src/main/resources/application.yml

- name: gradle 권한 부여
run: chmod +x ./gradlew
shell: bash

- name: 빌드 시 캐시 적용
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: 빌드
run: ./gradlew build -x test

- name: 도커 허브 로그인
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME_PROD }}
password: ${{ secrets.DOCKERHUB_TOKEN_PROD }}

- name: 도커 이미지 빌드 및 푸시
run: |
docker build -f Dockerfile -t ${{ secrets.DOCKERHUB_USERNAME_PROD }}/${{ secrets.DOCKERHUB_APP_NAME }} .
docker push ${{ secrets.DOCKERHUB_USERNAME_PROD }}/${{ secrets.DOCKERHUB_APP_NAME }}

deploy:
needs: build-and-push-image
runs-on: ubuntu-latest
steps:
- name: 이미지 pull 받아서 백그라운드 실행
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST_PROD }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_KEY_PROD }}
port: ${{ secrets.EC2_PORT }}
script: |
cd compose
docker rm -f $(docker ps -qa)
docker pull ${{ secrets.DOCKERHUB_USERNAME_PROD }}/${{ secrets.DOCKERHUB_APP_NAME }}
docker-compose up -d
docker system prune -f
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ out/
/src/main/generated/
/src/main/resources/application-local.yml
/src/main/resources/application-prod.yml
/src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
description = "공무인 API 명세서",
version = "v.1.0"),
servers = {
@Server(url = "https://gongmuin.site", description = "Deploy Server URL"),
@Server(url = "https://gongmuin.site", description = "개발 서버"),
@Server(url = "https://gongmuin.shop", description = "운영 서버"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

개발/운영 서버 도메인을 나눔으로써 소셜 로그인도 변경해야겠네요..!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

application.yml에 있는 redirect_uri 말씀하시는걸까요?!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yml도 그렇고 Open API 페이지에서도요!
천천히 해보겠슴당

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yml 내 redirct_url 수정해서 배포하고 notion에도 반영했습니다!

@Server(url = "http://localhost:8080", description = "Local Host URL")
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();

configuration.setAllowedOrigins(Arrays.asList("http://localhost:3000", "https://gongmuin.netlify.app",
"https://gongmuin.site/", "http://localhost:8080", "/ws/**"));
"https://gongmuin.site", "https://gongmuin.shop", "http://localhost:8080", "/ws/**"));
configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"));
configuration.setAllowedHeaders(Arrays.asList("*"));
configuration.setExposedHeaders(Arrays.asList("Set-Cookie", "Authorization"));
Expand Down
Loading