Skip to content

Commit

Permalink
Merge pull request #4 from lotteon2/develop
Browse files Browse the repository at this point in the history
release
  • Loading branch information
wakkpu authored Jan 5, 2024
2 parents 14e9c6c + 66f0f3e commit 6a27e56
Show file tree
Hide file tree
Showing 31 changed files with 1,020 additions and 26 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ jobs:
java-version: '11'
distribution: 'corretto'
cache: gradle
- name: Grant execute permission to gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build
shell: bash
Expand All @@ -45,6 +47,8 @@ jobs:
java-version: '11'
distribution: 'corretto'
cache: gradle
- name: Grant execute permission to gradlew
run: chmod +x gradlew
- name: Test with Gradle
run: ./gradlew test
shell: bash
4 changes: 4 additions & 0 deletions .github/workflows/build-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ jobs:
java-version: '11'
distribution: 'corretto'
cache: gradle
- name: Grant execute permission to gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build
shell: bash
Expand All @@ -45,6 +47,8 @@ jobs:
java-version: '11'
distribution: 'corretto'
cache: gradle
- name: Grant execute permission to gradlew
run: chmod +x gradlew
- name: Test with Gradle
run: ./gradlew test
shell: bash
6 changes: 6 additions & 0 deletions .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ jobs:
java-version: '11'
distribution: 'corretto'
cache: gradle
- name: Grant execute permission to gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build
shell: bash
Expand All @@ -49,6 +51,8 @@ jobs:
java-version: '11'
distribution: 'corretto'
cache: gradle
- name: Grant execute permission to gradlew
run: chmod +x gradlew
- name: Test with Gradle
run: ./gradlew test
shell: bash
Expand All @@ -65,6 +69,8 @@ jobs:
java-version: '11'
distribution: 'corretto'
cache: gradle
- name: Grant execute permission to gradlew
run: chmod +x gradlew
- name: build with Gradle without test
run: ./gradlew build -x test
shell: bash
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy development profile about lotdiz
name: Deploy development profile about dailyon
on:
workflow_dispatch:
push:
Expand Down Expand Up @@ -35,6 +35,8 @@ jobs:
java-version: '11'
distribution: 'corretto'
cache: gradle
- name: Grant execute permission to gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build
shell: bash
Expand All @@ -51,6 +53,8 @@ jobs:
java-version: '11'
distribution: 'corretto'
cache: gradle
- name: Grant execute permission to gradlew
run: chmod +x gradlew
- name: Test with Gradle
run: ./gradlew test
shell: bash
Expand All @@ -67,6 +71,8 @@ jobs:
java-version: '11'
distribution: 'corretto'
cache: gradle
- name: Grant execute permission to gradlew
run: chmod +x gradlew
- name: build with Gradle without test
run: ./gradlew build -x test
shell: bash
Expand Down
12 changes: 8 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ configurations {

repositories {
mavenCentral()
maven { url 'https://s3-us-west-2.amazonaws.com/dynamodb-local/release' } // for DynamoDBLocal Lib
}

ext {
Expand All @@ -28,27 +29,30 @@ ext {
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'

implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb-reactive'
// implementation 'org.springframework.boot:spring-boot-starter-data-redis'
// implementation 'org.springframework.boot:spring-boot-starter-data-redis-reactive'
implementation 'io.github.boostchicken:spring-data-dynamodb:5.2.3'
implementation 'software.amazon.awssdk:dynamodb:2.1.0'

implementation 'org.springframework.boot:spring-boot-starter-rsocket'
implementation 'org.springframework.boot:spring-boot-starter-validation'

implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-webflux'

implementation 'org.springframework.cloud:spring-cloud-starter-circuitbreaker-reactor-resilience4j'
implementation 'org.springframework.cloud:spring-cloud-starter-config'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
implementation 'org.springframework.cloud:spring-cloud-starter-bus-amqp'
implementation platform('org.testcontainers:testcontainers-bom:1.19.3') //import bom

compileOnly 'org.projectlombok:lombok'

developmentOnly 'org.springframework.boot:spring-boot-devtools'

annotationProcessor 'org.projectlombok:lombok'

testImplementation 'org.testcontainers:testcontainers:1.19.3'
testImplementation 'org.testcontainers:junit-jupiter:1.19.3'
testImplementation 'org.springframework.amqp:spring-rabbit-test'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'
Expand Down
51 changes: 51 additions & 0 deletions deploy-prod.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

export ECR_REGISTRY=${ECR_REGISTRY}
export AWS_ECR_REPOSITORY=${AWS_ECR_REPOSITORY}
export IMAGE_TAG=${IMAGE_TAG}

deployment_name="auction-deployment"
service_name="auction-service"
namespace="prod"

# Update AWS EKS user config
aws eks update-kubeconfig --region ap-northeast-2 --name $AWS_EKS_CLUSTER_NAME

# Deploy kubernetes deployment resource
echo "Apply new kubernetes deployment resources..."
envsubst < ./deployment-prod.yml | kubectl apply -f - -n ${namespace}

# Wait for the deployment to be available
echo "Check new kubernetes deployment resources status..."
kubectl rollout status deployment/${deployment_name} -n ${namespace}

if [ $? -eq 0 ]; then
echo "Successful deploy new kubernetes deployment resources..."

if kubectl get service "${service_name}" -n "${namespace}" &> /dev/null; then
echo "Service is already available"
echo "Update new service resource..."
kubectl apply -f ./service-prod.yml -n ${namespace}
else
echo "Service is not founded"
echo "Create new service resource..."
kubectl create -f ./service-prod.yml -n ${namespace}

echo "Success to create new service resource..."
fi
else
echo "Deployment failed. Rolling back to the previous version..."
kubectl rollout undo deployment/${deployment_name} -n ${namespace}

# Wait for the rollback to be available
kubectl rollout status deployment/${deployment_name} -n ${namespace}

# Check if the rollback was successful
if [ $? -eq 0 ]; then
echo "Rollback successful."
exit 0
else
echo "Rollback failed. Manual intervention required."
exit 1
fi
fi
74 changes: 74 additions & 0 deletions deployment-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: auction-deployment
namespace: prod
labels:
app: auction-service
spec:
selector:
matchLabels:
app: auction-service
# 앱이 Ready 상태가 될 때까지 기다리는 시간
minReadySeconds: 10
# 롤링 업데이트:
strategy:
type: RollingUpdate
rollingUpdate:
# 롤링 업데이트시 스케일아웃할 최대 pod 수
maxSurge: 1
maxUnavailable: 0
replicas: 1
template:
metadata:
name: auction-pod
labels:
app: auction-service
spec:
containers:
- name: auction-service
image: ${ECR_REGISTRY}/${AWS_ECR_REPOSITORY}:${IMAGE_TAG}
resources:
requests:
memory: "768Mi"
cpu: "250m"
limits:
memory: "1Gi"
cpu: "300m"
ports:
- containerPort: 8083
imagePullPolicy: IfNotPresent
# 애플리케이션이 시작된 뒤 초기화 작업이 마무리되어 준비되었는지 검사
readinessProbe:
httpGet:
path: /actuator/health/readiness
port: 8083
initialDelaySeconds: 240
periodSeconds: 30
timeoutSeconds: 2
# 애플리케이션이 정상 상태를 유지하고 있는지 지속해서 검사
livenessProbe:
httpGet:
path: /actuator/health/liveness
port: 8083
initialDelaySeconds: 240
periodSeconds: 30
timeoutSeconds: 2
# SIGTERM을 받아도 바로 종료되지 않고 일정 시간 뒤에 종료
terminationGracePeriodSeconds: 360
restartPolicy: Always
affinity:
nodeAffinity:
# Pod이 존재하지 않다가 처음으로 만들어지는 상태, 이미 실행중인데 nodeSelector가 node에서 제거된다면 계속 실행
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: type
operator: In
values:
- App
- key: size
operator: In
values:
- Large
- Medium
12 changes: 12 additions & 0 deletions service-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Service
metadata:
name: auction-service
namespace: prod
spec:
type: ClusterIP
ports:
- targetPort: 8083
port: 8083
selector:
app: auction-service
Original file line number Diff line number Diff line change
@@ -1,15 +1,48 @@
package com.dailyon.auctionservice;

import com.amazonaws.services.dynamodbv2.AmazonDynamoDBAsync;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper;
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest;
import com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput;
import com.amazonaws.services.dynamodbv2.util.TableUtils;
import com.dailyon.auctionservice.document.Auction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;

import javax.annotation.PostConstruct;
import java.util.TimeZone;

@EnableFeignClients
@EnableDiscoveryClient
@SpringBootApplication
public class AuctionServiceApplication {
@Autowired
AmazonDynamoDBAsync dynamoDB;

@Autowired
DynamoDBMapper dynamoDBMapper;

public static void main(String[] args) {
SpringApplication.run(AuctionServiceApplication.class, args);
}

@PostConstruct
public void setTimezoneToSeoul() {
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Seoul"));
}

// TODO : document FIX 후 삭제
@PostConstruct
public void setDynamoDB() {
TableUtils.deleteTableIfExists(dynamoDB, dynamoDBMapper.generateDeleteTableRequest(Auction.class));

CreateTableRequest createTableRequest = dynamoDBMapper
.generateCreateTableRequest(Auction.class)
.withProvisionedThroughput(new ProvisionedThroughput(1L, 1L));

TableUtils.createTableIfNotExists(dynamoDB, createTableRequest);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.dailyon.auctionservice.common.feign.client;

import com.dailyon.auctionservice.common.feign.response.CreateProductResponse;
import com.dailyon.auctionservice.config.FeignClientConfig;
import com.dailyon.auctionservice.dto.request.CreateAuctionRequest;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@FeignClient(
name = "productFeignClient",
url = "${endpoint.product-service}",
configuration = FeignClientConfig.class
)
public interface ProductFeignClient {
@PostMapping(value = "/clients/products/auction")
ResponseEntity<CreateProductResponse> createAuctionProduct(@RequestBody CreateAuctionRequest.CreateProductRequest createProductRequest);

@DeleteMapping(value = "/clients/products/auction")
ResponseEntity<Void> deleteAuctionProduct(@RequestParam List<Long> ids);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.dailyon.auctionservice.common.feign.response;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.Map;

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CreateProductResponse {
private Long productId;
private String imgPresignedUrl;
private Map<String, String> describeImgPresignedUrl;
}
Loading

0 comments on commit 6a27e56

Please sign in to comment.