-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from lotteon2/develop
release
- Loading branch information
Showing
31 changed files
with
1,020 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/dailyon/auctionservice/AuctionServiceApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/dailyon/auctionservice/common/feign/client/ProductFeignClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/dailyon/auctionservice/common/feign/response/CreateProductResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.