Skip to content

Commit

Permalink
Merge branch 'dev' into fe/dev/feat_profile_layout
Browse files Browse the repository at this point in the history
  • Loading branch information
seong-hui authored Oct 13, 2023
2 parents d0b2b52 + b7b60c5 commit 90ea7c7
Show file tree
Hide file tree
Showing 37 changed files with 2,475 additions and 283 deletions.
21 changes: 11 additions & 10 deletions .github/workflows/back-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,24 @@ jobs:
backend-CI:
runs-on: ubuntu-latest
steps:
- name: Make ssh file
run: |
mkdir -p ~/.ssh
echo '${{ secrets.SSH_CONFIG }}' | base64 -d > ~/.ssh/id_rsa
chmod 400 ~/.ssh/id_rsa
- name: 체크아웃
uses: actions/checkout@v3

with:
submodule: true
- name: 서브모듈 업데이트
run: |
git submodule update --init config
- name: JDK 11 설정
uses: actions/setup-java@v3
with:
java-version: "11"
distribution: "corretto"

- name: Application YML 생성
run: |
mkdir -p backend/src/main/resources
echo "${{ secrets.APPLICATION_PROD_YML }}" | base64 --decode > backend/src/main/resources/application-prod.yml
echo "${{ secrets.APPLICATION_DEV_YML }}" | base64 --decode > backend/src/main/resources/application-dev.yml
echo "${{ secrets.APPLICATION_AUTH_YML }}" | base64 --decode > backend/src/main/resources/application-auth.yml
echo "${{ secrets.APPLICATION_MAIL_YML }}" | base64 --decode > backend/src/main/resources/application-mail.yml
- name: Cache Gradle packages
uses: actions/cache@v3
with:
Expand All @@ -41,7 +42,7 @@ jobs:
cd backend
mkdir -p build/generated-snippets/
chmod +x gradlew
./gradlew build
./gradlew build -x test
shell: bash

- name: Configure AWS credentials
Expand Down
17 changes: 14 additions & 3 deletions .github/workflows/front-cicd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,19 @@ jobs:
frontend-CI:
runs-on: ubuntu-latest
steps:
- name: Make ssh file
run: |
mkdir -p ~/.ssh
echo '${{ secrets.SSH_CONFIG }}' | base64 -d > ~/.ssh/id_rsa
chmod 400 ~/.ssh/id_rsa
- name: 체크아웃
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
submodule: true
- name: 서브모듈 업데이트
run: |
git submodule update --init config
- name: Node.js 16.x Version
uses: actions/setup-node@v1
with:
Expand All @@ -28,10 +39,10 @@ jobs:
# run: npm run lint --prefix frontend
- name: Dev env 파일 생성
if: ${{ github.ref == 'refs/heads/dev' }}
run: echo "${{ secrets.FRONTEND_DEV_ENV }}" | base64 --decode > frontend/.env
run: cat ./config/frontend/dev.env > ./frontend/.env
- name: Main env 파일 생성
if: ${{ github.ref == 'refs/heads/main' }}
run: echo "${{ secrets.FRONTEND_MAIN_ENV }}" | base64 --decode > frontend/.env
run: cat ./config/frontend/main.env > ./frontend/.env
- name: 빌드 체크
run: npm run build --prefix frontend
# - name: 단위 테스트 체크
Expand Down
6 changes: 3 additions & 3 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,7 @@ out/
application*.yml
!application.yml

**/static/docs
**/static/docs

### Firebase ###
*firebase*.json
29 changes: 28 additions & 1 deletion backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,20 @@ dependencies {
implementation 'org.modelmapper:modelmapper:3.1.1'
implementation 'org.springframework.boot:spring-boot-starter-mail'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-data-redis'

// querydsl
implementation "com.querydsl:querydsl-jpa:${queryDslVersion}"
annotationProcessor "com.querydsl:querydsl-apt:${queryDslVersion}"

// Monitoring
// Monitoring
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'io.micrometer:micrometer-core:1.11.2'
implementation 'io.micrometer:micrometer-registry-prometheus'

// Firebase
implementation 'com.google.firebase:firebase-admin:9.2.0'

// jwt
implementation 'io.jsonwebtoken:jjwt-api:0.11.2'
implementation 'io.jsonwebtoken:jjwt-impl:0.11.2'
Expand Down Expand Up @@ -92,6 +96,29 @@ dependencies {
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'
}

tasks.register('copyMainConfig', Copy) {
from '../config/backend/src/main/resources'
into 'src/main/resources'
}

tasks.register('copyTestConfig', Copy) {
from '../config/backend/src/main/resources/test/resources'
into 'src/test/resources'
}

tasks.named('processResources') {
dependsOn 'copyMainConfig'
}

tasks.named('processTestResources') {
dependsOn 'copyTestConfig'
}

tasks.named('compileJava') {
dependsOn 'compileQuerydsl'
}


test {
outputs.dir snippetsDir
useJUnitPlatform()
Expand Down
9 changes: 9 additions & 0 deletions backend/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,12 @@ services:
- '80:80'
volumes:
- ../dev/:/etc/nginx/conf.d/
redis:
image: redis:latest
restart: always
ports:
- "6379:6379"
healthcheck:
test: [ "CMD", "redis-cli", "ping" ]
timeout: 20s
retries: 10
Original file line number Diff line number Diff line change
Expand Up @@ -22,69 +22,71 @@
@Log4j2
public class FtApiManager {

private final FtApiProperties ftApiProperties;
private String accessToken;
private final ObjectMapper objectMapper;
private static final Integer MAX_RETRY = 3;
private static final Integer MAX_RETRY = 3;
private final FtApiProperties ftApiProperties;
private final ObjectMapper objectMapper;
private String accessToken;

/**
* 42 토큰을 발급받는다.
*/
public void issueAccessToken() {
log.info("called issueAccessToken");
accessToken =
WebClient.create().post()
.uri(ftApiProperties.getTokenUri())
.body(BodyInserters.fromFormData(
ApiRequestManager.of(ftApiProperties)
.getAccessTokenRequestBodyMapWithClientSecret(
"client_credentials")))
.retrieve()
.bodyToMono(String.class)
.map(response -> {
try {
return objectMapper.readTree(response)
.get(ftApiProperties.getAccessTokenName()).asText();
} catch (Exception e) {
throw new RuntimeException();
}
})
.onErrorResume(e -> {
throw new ServiceException(ExceptionStatus.OAUTH_BAD_GATEWAY);
})
.block();
}
/**
* 42 토큰을 발급받는다.
*/
public void issueAccessToken() {
log.info("called issueAccessToken");
accessToken =
WebClient.create().post()
.uri(ftApiProperties.getTokenUri())
.body(BodyInserters.fromFormData(
ApiRequestManager.of(ftApiProperties)
.getAccessTokenRequestBodyMapWithClientSecret(
"client_credentials")))
.retrieve()
.bodyToMono(String.class)
.map(response -> {
try {
return objectMapper.readTree(response)
.get(ftApiProperties.getAccessTokenName()).asText();
} catch (Exception e) {
log.error(e.getMessage());
throw new RuntimeException();
}
})
.onErrorResume(e -> {
log.error(e.getMessage());
throw new ServiceException(ExceptionStatus.OAUTH_BAD_GATEWAY);
})
.block();
}

/**
* 유저의 이름으로 42API를 통해 특정 유저의 정보를 가져온다.
*
* @param name 유저의 이름
* @return JsonNode 형태의 유저 정보
*/
public JsonNode getFtUsersInfoByName(String name) {
log.info("called getFtUsersInfoByName {}", name);
Integer tryCount = 0;
while (tryCount < MAX_RETRY) {
try {
JsonNode results = WebClient.create().get()
.uri(ftApiProperties.getUsersInfoUri() + '/' + name)
.accept(MediaType.APPLICATION_JSON)
.headers(h -> h.setBearerAuth(accessToken))
.retrieve()
.bodyToMono(JsonNode.class)
.block();
return results;
} catch (Exception e) {
tryCount++;
log.info(e.getMessage());
log.info("요청에 실패했습니다. 최대 3번 재시도합니다. 현재 시도 횟수: {}", tryCount);
this.issueAccessToken();
if (tryCount == MAX_RETRY) {
log.error("요청에 실패했습니다. 최대 재시도 횟수를 초과했습니다. {}", e.getMessage());
throw new ServiceException(ExceptionStatus.OAUTH_BAD_GATEWAY);
}
}
}
return null;
}
/**
* 유저의 이름으로 42API를 통해 특정 유저의 정보를 가져온다.
*
* @param name 유저의 이름
* @return JsonNode 형태의 유저 정보
*/
public JsonNode getFtUsersInfoByName(String name) {
log.info("called getFtUsersInfoByName {}", name);
Integer tryCount = 0;
while (tryCount < MAX_RETRY) {
try {
JsonNode results = WebClient.create().get()
.uri(ftApiProperties.getUsersInfoUri() + '/' + name)
.accept(MediaType.APPLICATION_JSON)
.headers(h -> h.setBearerAuth(accessToken))
.retrieve()
.bodyToMono(JsonNode.class)
.block();
return results;
} catch (Exception e) {
tryCount++;
log.info(e.getMessage());
log.info("요청에 실패했습니다. 최대 3번 재시도합니다. 현재 시도 횟수: {}", tryCount);
this.issueAccessToken();
if (tryCount == MAX_RETRY) {
log.error("요청에 실패했습니다. 최대 재시도 횟수를 초과했습니다. {}", e.getMessage());
throw new ServiceException(ExceptionStatus.OAUTH_BAD_GATEWAY);
}
}
}
return null;
}
}
Loading

0 comments on commit 90ea7c7

Please sign in to comment.