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

feat: 성능 튜닝 및 무중단 배포 적용 #651

Merged
merged 2 commits into from
Oct 24, 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
2 changes: 1 addition & 1 deletion .github/workflows/backend-dev-ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- ".github/workflows/backend-dev-ci-cd.yml"
- "Dockerfile"
# pull_request:
# branches: [ "develop" ]
# branches: [ "chongdae" ]
# paths:
# - "backend/**"
# - ".github/workflows/backend-dev-ci-cd.yml"
Expand Down
43 changes: 21 additions & 22 deletions .github/workflows/backend-prod-ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,30 +61,29 @@ jobs:
docker tag ${{ secrets.BE_DOCKER_IMAGE_NAME_PROD }} ${{ secrets.BE_DOCKERHUB_USERNAME }}/${{ secrets.BE_DOCKER_IMAGE_NAME_PROD }}:${GITHUB_SHA::7}
docker push ${{ secrets.BE_DOCKERHUB_USERNAME }}/${{ secrets.BE_DOCKER_IMAGE_NAME_PROD }}:${GITHUB_SHA::7}

deploy-a:
needs: build-and-test
runs-on: prod-a

deploy-new-container:
needs: build-and-test
strategy:
matrix:
runner: [prod-a, prod-b]
runs-on: [ self-hosted, ${{ matrix.runner }} ]
steps:
- name: Pull Image And Restart Container on Production A
run: |
docker login -u ${{ secrets.BE_DOCKERHUB_USERNAME }} -p ${{ secrets.BE_DOCKERHUB_PASSWORD }}
docker stop ${{ secrets.BE_DOCKER_CONTAINER_NAME }} | true
docker rm ${{ secrets.BE_DOCKER_CONTAINER_NAME }} | true
docker image prune -a -f
docker pull ${{ secrets.BE_DOCKERHUB_USERNAME }}/${{ secrets.BE_DOCKER_IMAGE_NAME_PROD }}:${GITHUB_SHA::7}
docker run --name ${{ secrets.BE_DOCKER_CONTAINER_NAME }} -d -v /logs:/logs -p 80:8080 -e SPRING_PROFILES_ACTIVE=prod ${{ secrets.BE_DOCKERHUB_USERNAME }}/${{ secrets.BE_DOCKER_IMAGE_NAME_PROD }}:${GITHUB_SHA::7}
- name: Checkout repository
uses: actions/checkout@v4

deploy-b:
needs: deploy-a
runs-on: prod-b
- name: Deploy new container on ${{ matrix.runner }}
run: |
bash launch_next_container.sh ${GITHUB_SHA::7} prod ${{ secrets.BE_DOCKERHUB_USERNAME }} ${{ secrets.BE_DOCKER_IMAGE_NAME_PROD }}
working-directory: backend/deploy

switch-new-container:
needs: deploy-new-container
strategy:
matrix:
runner: [prod-a, prod-b]
runs-on: [ self-hosted, ${{ matrix.runner }} ]
steps:
- name: Pull Image And Restart Container on Production B
- name: Switch from old to new container on ${{ matrix.runner }}
run: |
docker login -u ${{ secrets.BE_DOCKERHUB_USERNAME }} -p ${{ secrets.BE_DOCKERHUB_PASSWORD }}
docker stop ${{ secrets.BE_DOCKER_CONTAINER_NAME }} | true
docker rm ${{ secrets.BE_DOCKER_CONTAINER_NAME }} | true
docker image prune -a -f
docker pull ${{ secrets.BE_DOCKERHUB_USERNAME }}/${{ secrets.BE_DOCKER_IMAGE_NAME_PROD }}:${GITHUB_SHA::7}
docker run --name ${{ secrets.BE_DOCKER_CONTAINER_NAME }} -d -v /logs:/logs -p 80:8080 -e SPRING_PROFILES_ACTIVE=prod ${{ secrets.BE_DOCKERHUB_USERNAME }}/${{ secrets.BE_DOCKER_IMAGE_NAME_PROD }}:${GITHUB_SHA::7}
bash switch_blue_green_container.sh
working-directory: backend/deploy
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
Expand Down Expand Up @@ -48,7 +49,7 @@ public class OfferingEntity extends BaseTimeEntity {
private Long id;

@NotNull
@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
private MemberEntity member;

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class OfferingService {
private final OfferingFetcher offeringFetcher;
private final Clock clock;

@Transactional(readOnly = true)
public OfferingDetailResponse getOfferingDetail(Long offeringId, MemberEntity member) {
OfferingEntity offering = offeringRepository.findById(offeringId)
.orElseThrow(() -> new MarketException(OfferingErrorCode.NOT_FOUND));
Expand All @@ -72,6 +73,7 @@ public OfferingAllResponseItem getOffering(Long offeringId) {
return new OfferingAllResponseItem(offering, offeringPrice);
}

@Transactional(readOnly = true)
public OfferingAllResponse getAllOffering(String filterName, String searchKeyword, Long lastId, Integer pageSize) {
Pageable pageable = PageRequest.ofSize(pageSize);
OfferingFilter filter = OfferingFilter.findByName(filterName);
Expand Down Expand Up @@ -186,6 +188,7 @@ private void updateStatus(OfferingEntity offering) { // TODO : 도메인 분리
}

@WriterDatabase
@Transactional
public void deleteOffering(Long offeringId, MemberEntity member) {
OfferingEntity offering = offeringRepository.findById(offeringId)
.orElseThrow(() -> new MarketException(OfferingErrorCode.NOT_FOUND));
Expand Down
9 changes: 9 additions & 0 deletions backend/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
server:
tomcat:
threads:
max: 35
max-connections: 1024
accept-count: 242

spring:
application:
name: chongdae
datasource:
url: jdbc:h2:mem:database
hikari:
maximum-pool-size: 8
jpa:
show-sql: true
defer-datasource-initialization: true
Expand Down