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

Git Submodule을 사용하여 AWS EC2에 위치한 설정을 관리하도록 변경 #805

Open
wants to merge 26 commits into
base: dev/be
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
01108c3
chore: add submodule
zeus6768 Oct 6, 2024
5b794fb
chore: refactor cd script
zeus6768 Oct 6, 2024
917e0a0
chore: 개발 서버 snapshot
zeus6768 Oct 14, 2024
d2fddf8
chore: cd test를 위한 브랜치 추가
zeus6768 Oct 14, 2024
769d2a2
chore: 불필요한 포트 설정 삭제
zeus6768 Oct 15, 2024
a7c18b5
chore: update cd script
zeus6768 Oct 15, 2024
70b31db
chore: fix runner nickname
zeus6768 Oct 15, 2024
ce964ab
chore: fix variable injecting script
zeus6768 Oct 15, 2024
cf496bb
chore: update cd script
zeus6768 Oct 15, 2024
2bfdb00
chore: update submodule
zeus6768 Oct 16, 2024
261d489
refactor(rds): modify profile on DataSourceConfig
zeus6768 Oct 16, 2024
82773f8
chore: update submodule spring db config
zeus6768 Oct 16, 2024
01e1cad
chore: update submodule compose container timezone
zeus6768 Oct 16, 2024
e94800d
fix: promtail config filename typo
zeus6768 Oct 16, 2024
06ca5ba
chore: update submodule
zeus6768 Oct 16, 2024
a6f262f
chore: update cors configs
zeus6768 Oct 17, 2024
bec1b1c
refactor(logger): http body 출력하지 않도록 변경
zeus6768 Oct 17, 2024
ff7ad95
chore: application db yml on-profile 옵션 삭제
zeus6768 Oct 17, 2024
e6289e1
chore: jar 실행 시 profile active 옵션 추가
zeus6768 Oct 17, 2024
40c39e6
chore: fix build failure
zeus6768 Oct 17, 2024
600fb3b
chore: fix build failure
zeus6768 Oct 17, 2024
eb11f7c
chore: fix cd failure
zeus6768 Oct 17, 2024
eaeea10
chore: fix cd failure
zeus6768 Oct 17, 2024
8ae02a3
chore: apply each branch
zeus6768 Oct 17, 2024
79af652
chore: actuator 관련 로그 남기지 않도록 변경
zeus6768 Oct 17, 2024
5db4b48
chore: flatten indent
zeus6768 Oct 17, 2024
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
71 changes: 47 additions & 24 deletions .github/workflows/backend_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ on:

jobs:
build:
runs-on:
- ubuntu-latest
runs-on: ubuntu-latest
steps:
- name: 체크아웃
uses: actions/checkout@v4
Expand All @@ -30,46 +29,70 @@ jobs:
- name: Artifact 업로드
uses: actions/upload-artifact@v4
with:
name: code-zap-jar
name: code-zap
path: backend/build/libs/*.jar

deploy_develop:
needs: build
if: ${{ github.ref == 'refs/heads/dev/be' }}
needs: build
environment: Develop
runs-on:
- self-hosted
- spring
- develop
- spring
steps:
- name: 체크아웃
uses: actions/checkout@v4
with:
submodules: true
token: ${{ secrets.PRIVATE_REPO_ACCESS }}

- name: Compose 설정 복사
run: ${{ secrets.RUN_COPY_COMPOSE }}

- name: Compose 환경변수 주입
working-directory: ${{ secrets.PROJECT_PATH }}
run: ${{ secrets.ENV_VARIABLES }}

- name: Artifact 다운로드
uses: actions/download-artifact@v4
with:
name: code-zap-jar
path: ${{ secrets.SPRING_DIRECTORY }}
- name: 배포 스크립트 실행
run: |
cd ${{ secrets.SPRING_DIRECTORY }}
mv code-zap*.jar ${{ secrets.JAR_NAME }}
docker compose restart
name: code-zap
path: ${{ secrets.SPRING_PATH }}

- name: 배포
working-directory: ${{ secrets.PROJECT_PATH }}
run: ${{ secrets.RUN_SERVER }}

deploy_production:
needs: build
if: ${{ github.ref == 'refs/heads/main' }}
needs: build
environment: Production
strategy:
matrix:
environment: [prod_a, prod_b]
runners: [ prod_a, prod_b ]
runs-on:
- self-hosted
- spring
- ${{ matrix.environment }}
- ${{ matrix.runners }}
steps:
- name: 체크아웃
uses: actions/checkout@v4
with:
submodules: true
token: ${{ secrets.PRIVATE_REPO_ACCESS }}

- name: Compose 설정 복사
run: ${{ secrets.RUN_COPY_COMPOSE }}

- name: Compose 환경변수 주입
working-directory: ${{ secrets.PROJECT_PATH }}
run: ${{ secrets.ENV_VARIABLES }}

- name: Artifact 다운로드
uses: actions/download-artifact@v4
with:
name: code-zap-jar
path: ${{ secrets.SPRING_DIRECTORY }}
- name: 배포 스크립트 실행
run: |
cd ${{ secrets.SPRING_DIRECTORY }}
mv code-zap*.jar ${{ secrets.JAR_NAME }}
docker compose restart
name: code-zap
path: ${{ secrets.SPRING_PATH }}

- name: 배포
working-directory: ${{ secrets.PROJECT_PATH }}
run: ${{ secrets.RUN_SERVER }}
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "backend/submodules/private"]
path = backend/submodules/private
url = https://github.com/codezap2024/2024-code-zap-private.git
branch = main
Copy link
Contributor Author

Choose a reason for hiding this comment

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

이 부분은 로그 설정도 겸사겸사 같이 했습니당 작업하면서 로그가 너무 지저분해서요

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package codezap.global.logger;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.stream.Collectors;

import jakarta.servlet.FilterChain;
Expand Down Expand Up @@ -32,18 +31,14 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
filterChain.doFilter(requestWrapper, responseWrapper);
long duration = System.currentTimeMillis() - startTime;

log.info("[Request] {} {}, 헤더 값: {} \n 요청 바디: {}", request.getMethod(), request.getRequestURI(),
getHeaderAndValue(requestWrapper), getBodyAsUtf8String(requestWrapper.getContentAsByteArray()));
log.info("[Response] Status: {}, Duration: {}ms, 헤더 값: {} \n 응답 바디: {}", response.getStatus(), duration,
getHeaderAndValue(responseWrapper), getBodyAsUtf8String(responseWrapper.getContentAsByteArray()));
log.info("[Request] {} {}, 헤더 값: {} \n", request.getMethod(), request.getRequestURI(),
getHeaderAndValue(requestWrapper));
log.info("[Response] Status: {}, Duration: {}ms, 헤더 값: {} \n", response.getStatus(), duration,
getHeaderAndValue(responseWrapper));

responseWrapper.copyBodyToResponse();
}

private String getBodyAsUtf8String(byte[] bytes) {
return new String(bytes, StandardCharsets.UTF_8);
}

private String getHeaderAndValue(ContentCachingRequestWrapper requestWrapper) {
StringBuilder headerAndValue = new StringBuilder();
requestWrapper.getHeaderNames().asIterator().forEachRemaining(headerName -> {
Expand All @@ -64,6 +59,6 @@ private String getHeaderAndValue(ContentCachingResponseWrapper requestWrapper) {
@Override
protected boolean shouldNotFilter(HttpServletRequest request) {
String path = request.getRequestURI();
return path.contains("/swagger") || path.contains("/v3/api-docs") || path.contains("/actuator/prometheus");
return path.contains("/swagger") || path.contains("/v3/api-docs") || path.contains("/actuator");
}
}
13 changes: 13 additions & 0 deletions backend/src/main/resources/application-actuator.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
spring:
config:
activate:
on-profile: actuator

management:
endpoints:
web:
exposure:
include: health,info,metrics,prometheus
endpoint:
health:
show-details: always
3 changes: 3 additions & 0 deletions backend/src/main/resources/application-cors.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cors:
allowed-origins: ${ALLOWED_ORIGINS}
allowed-origins-patterns: ${ALLOWED_ORIGINS_PATTERNS}
31 changes: 31 additions & 0 deletions backend/src/main/resources/application-db.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
spring:
config:
activate:
on-profile: db
datasource:
write:
jdbc-url: ${MYSQL_WRITER_URL}
username: ${MYSQL_USER}
password: ${MYSQL_PASSWORD}
driver-class-name: com.mysql.cj.jdbc.Driver
read:
jdbc-url: ${MYSQL_READER_URL}
username: ${MYSQL_USER}
password: ${MYSQL_PASSWORD}
driver-class-name: com.mysql.cj.jdbc.Driver
flyway:
enabled: true
baseline-on-migrate: true
baseline-version: 2
locations: classpath:db/migration
url: ${MYSQL_WRITER_URL}
username: ${MYSQL_USER}
password: ${MYSQL_PASSWORD}
jpa:
# open-in-view: false
hibernate:
ddl-auto: validate
properties:
hibernate:
dialect: codezap.template.repository.FullTextSearchMySQLDialect
data.web.pageable.one-indexed-parameters: true
3 changes: 3 additions & 0 deletions backend/src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
spring:
config:
activate:
on-profile: local
output:
ansi:
enabled: always
Expand Down
8 changes: 8 additions & 0 deletions backend/src/main/resources/application-swagger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
springdoc:
default-consumes-media-type: application/json
default-produces-media-type: application/json
swagger-ui:
path: /swagger-ui.html
enabled: true
supportedSubmitMethods: get
display-request-duration: false
6 changes: 4 additions & 2 deletions backend/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
spring:
profiles:
active:
- local
group:
default: local
dev: db, actautor, swagger, cors
prod: db, actautor, swagger, cors
1 change: 1 addition & 0 deletions backend/submodules/private
Submodule private added at c39be7