-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feature/#17 blueprint
- Loading branch information
Showing
45 changed files
with
1,326 additions
and
116 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
name: Build-and-Deploy CI/CD | ||
|
||
on: | ||
push: | ||
branches: [ 'main', 'dev' ] | ||
|
||
workflow_dispatch: | ||
|
||
env: | ||
AWS_REGION: ap-northeast-2 | ||
ECR_REGISTRY: ${{ secrets.ECR_REGISTRY }} | ||
ECR_REPOSITORY: kumo-server | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Setup JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: 17 | ||
distribution: 'oracle' | ||
|
||
- name: Setup Gradle 7.6 | ||
uses: gradle/gradle-build-action@v2 | ||
with: | ||
gradle-version: 7.6 | ||
|
||
- name: make application.yml | ||
run: | | ||
mkdir ./src/main/resources | ||
cd ./src/main/resources | ||
touch ./application.yml | ||
echo "${{ secrets.YML }}" > ./application.yml | ||
shell: bash | ||
|
||
- name: make application-dev.yml | ||
run: | | ||
cd ./src/main/resources | ||
touch ./application-dev.yml | ||
echo "${{ secrets.YML_DEV }}" > ./application-dev.yml | ||
shell: bash | ||
|
||
- name: Build Project | ||
run: gradle build | ||
|
||
############################################ | ||
### Start Pushing container image on ECR ### | ||
############################################ | ||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: ${{ env.AWS_REGION }} | ||
|
||
- name: Login to Amazon ECR | ||
id: login-ecr | ||
uses: aws-actions/amazon-ecr-login@v1 | ||
|
||
####################################################### | ||
# DEV # DEV # DEV # DEV # DEV # DEV # DEV # DEV # DEV # | ||
####################################################### | ||
- name: Build, tag, and push server-dev image to Amazon ECR | ||
if: contains(github.ref, 'dev') | ||
id: build-image-dev | ||
env: | ||
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | ||
run: | | ||
DATE=$(date "+%y.%m.%d") | ||
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:dev-$DATE ./ | ||
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:dev-latest ./ | ||
docker push $ECR_REGISTRY/$ECR_REPOSITORY:dev-$DATE | ||
docker push $ECR_REGISTRY/$ECR_REPOSITORY:dev-latest | ||
######################################################### | ||
# MAIN # MAIN # MAIN # MAIN # MAIN # MAIN # MAIN # MAIN # | ||
######################################################### | ||
- name: Build, tag, and push server-main image to Amazon ECR | ||
if: contains(github.ref, 'main') | ||
id: build-image-main | ||
env: | ||
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | ||
run: | | ||
DATE=$(date "+%y.%m.%d") | ||
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:main-$DATE ./ | ||
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:main-latest ./ | ||
docker push $ECR_REGISTRY/$ECR_REPOSITORY:main-$DATE | ||
docker push $ECR_REGISTRY/$ECR_REPOSITORY:main-latest | ||
|
||
deploy: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
####################################################### | ||
# DEV # DEV # DEV # DEV # DEV # DEV # DEV # DEV # DEV # | ||
####################################################### | ||
- name: Deploy on Dev Server | ||
if: contains(github.ref, 'dev') | ||
uses: appleboy/ssh-action@v0.1.10 | ||
with: | ||
host: ${{ secrets.AWS_HOST_DEV }} | ||
username: ${{ secrets.AWS_SSH_USERNAME }} | ||
key: ${{ secrets.AWS_SSH_KEY }} | ||
script_stop: true | ||
script: | | ||
password=$(aws ecr get-login-password --region ${{ env.AWS_REGION }}) | ||
docker login --username AWS --password $password ${{ env.ECR_REGISTRY }} | ||
docker pull ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:dev-latest | ||
docker stop ${{ env.ECR_REPOSITORY }}-dev | ||
docker run --rm -d -p 8081:8080 --name kumo-server-dev ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:dev-latest | ||
######################################################### | ||
# MAIN # MAIN # MAIN # MAIN # MAIN # MAIN # MAIN # MAIN # | ||
######################################################### | ||
- name: Deploy on Product Server | ||
if: contains(github.ref, 'main') | ||
uses: appleboy/ssh-action@v0.1.10 | ||
with: | ||
host: ${{ secrets.AWS_HOST_DEV }} | ||
username: ${{ secrets.AWS_SSH_USERNAME }} | ||
key: ${{ secrets.AWS_SSH_KEY }} | ||
script_stop: true | ||
script: | | ||
password=$(aws ecr get-login-password --region ${{ env.AWS_REGION }}) | ||
docker login --username AWS --password $password ${{ env.ECR_REGISTRY }} | ||
docker pull ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:main-latest | ||
docker stop ${{ env.ECR_REPOSITORY }}-main | ||
docker run --rm -d -p 8080:8080 --name kumo-server-main ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:main-latest |
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,9 @@ | ||
FROM openjdk:17-alpine | ||
|
||
WORKDIR /app/ | ||
|
||
COPY ./build/libs/cloud-0.0.1-SNAPSHOT.jar ./kumo-backend.jar | ||
|
||
EXPOSE 8080 | ||
|
||
ENTRYPOINT ["java","-jar","./kumo-backend.jar"] |
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,31 +1,40 @@ | ||
plugins { | ||
id 'java' | ||
id 'org.springframework.boot' version '2.7.12' | ||
id 'io.spring.dependency-management' version '1.0.15.RELEASE' | ||
id 'java' | ||
id 'org.springframework.boot' version '2.7.12' | ||
id 'io.spring.dependency-management' version '1.0.15.RELEASE' | ||
} | ||
|
||
group = 'com.kumofactory' | ||
version = '0.0.1-SNAPSHOT' | ||
sourceCompatibility = '17' | ||
|
||
configurations { | ||
compileOnly { | ||
extendsFrom annotationProcessor | ||
} | ||
compileOnly { | ||
extendsFrom annotationProcessor | ||
} | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation 'org.springframework.boot:spring-boot-starter-web' | ||
compileOnly 'org.projectlombok:lombok' | ||
developmentOnly 'org.springframework.boot:spring-boot-devtools' | ||
annotationProcessor 'org.projectlombok:lombok' | ||
testImplementation 'org.springframework.boot:spring-boot-starter-test' | ||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa' | ||
developmentOnly 'org.springframework.boot:spring-boot-devtools' | ||
implementation 'org.springframework.boot:spring-boot-starter-web' | ||
testImplementation 'org.springframework.boot:spring-boot-starter-test' | ||
implementation 'mysql:mysql-connector-java:8.0.33' | ||
implementation 'org.springframework.boot:spring-boot-starter-validation' | ||
compileOnly 'org.projectlombok:lombok:1.18.24' | ||
implementation 'io.jsonwebtoken:jjwt-api:0.11.5' | ||
|
||
annotationProcessor 'org.projectlombok:lombok:1.18.24' | ||
|
||
implementation group: 'io.jsonwebtoken', name: 'jjwt-api', version: '0.11.2' | ||
implementation group: 'io.jsonwebtoken', name: 'jjwt-impl', version: '0.11.2' | ||
implementation group: 'io.jsonwebtoken', name: 'jjwt-jackson', version: '0.11.2' | ||
} | ||
|
||
tasks.named('test') { | ||
useJUnitPlatform() | ||
useJUnitPlatform() | ||
} |
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
57 changes: 57 additions & 0 deletions
57
src/main/java/com/kumofactory/cloud/blueprint/BlueprintController.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,57 @@ | ||
package com.kumofactory.cloud.blueprint; | ||
|
||
import com.kumofactory.cloud.blueprint.domain.aws.AwsBluePrint; | ||
import com.kumofactory.cloud.blueprint.dto.aws.AwsBluePrintDto; | ||
import com.kumofactory.cloud.blueprint.dto.aws.AwsBluePrintListDto; | ||
import com.kumofactory.cloud.blueprint.service.AwsBlueprintService; | ||
import com.kumofactory.cloud.global.middleware.auth.AuthorizationFromToken; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/blueprint") | ||
@Slf4j | ||
public class BlueprintController { | ||
private final Logger logger = LoggerFactory.getLogger(BlueprintController.class); | ||
private final AwsBlueprintService awsBlueprintService; | ||
|
||
@GetMapping("/aws/{id}") | ||
@AuthorizationFromToken | ||
public AwsBluePrintDto getAwsBlueprint(@PathVariable("id") Long id, String userId) { | ||
try { | ||
logger.info("aws blue print id: {}", id); | ||
AwsBluePrintDto awsBlueprint = awsBlueprintService.getAwsBlueprint(id); | ||
return awsBlueprint; | ||
} catch (RuntimeException e) { | ||
return null; | ||
} | ||
} | ||
|
||
@GetMapping("/aws/list") | ||
@AuthorizationFromToken | ||
public List<AwsBluePrintListDto> getAwsBlueprintList(String userId) { | ||
logger.info("userId: {}", userId); | ||
return awsBlueprintService.getMyAwsBlueprints(userId); | ||
} | ||
|
||
@PostMapping("/aws") | ||
@AuthorizationFromToken | ||
public String createAwsBlueprint(@RequestBody AwsBluePrintDto awsBluePrintDto, String userId) { | ||
logger.info(userId); | ||
awsBlueprintService.store(awsBluePrintDto, userId); | ||
return "hello-world"; | ||
} | ||
|
||
@GetMapping("/test") | ||
@AuthorizationFromToken | ||
public String testMiddleware(String userId) { | ||
System.out.printf("userId: %s\n", userId); | ||
return userId; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/com/kumofactory/cloud/blueprint/domain/ComponentDot.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,40 @@ | ||
package com.kumofactory.cloud.blueprint.domain; | ||
|
||
import com.kumofactory.cloud.blueprint.dto.ComponentDotDto; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import org.hibernate.annotations.CreationTimestamp; | ||
import org.hibernate.annotations.UpdateTimestamp; | ||
|
||
import javax.persistence.*; | ||
import java.util.Date; | ||
|
||
@Entity | ||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ComponentDot { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
@CreationTimestamp | ||
private Date created_at; | ||
@UpdateTimestamp | ||
private Date updated_at; | ||
|
||
private Integer x; // 점의 x 좌표 | ||
private Integer y; // 점의 y 좌표 | ||
private String componentId; // 점이 속한 컴포넌트의 id | ||
|
||
public static ComponentDot createComponentDot(ComponentDotDto componentDotDto) { | ||
ComponentDot componentDot = new ComponentDot(); | ||
componentDot.setComponentId(componentDotDto.getComponentId()); | ||
componentDot.setX(componentDotDto.getX()); | ||
componentDot.setY(componentDotDto.getY()); | ||
return componentDot; | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/com/kumofactory/cloud/blueprint/domain/ComponentLine.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,45 @@ | ||
package com.kumofactory.cloud.blueprint.domain; | ||
|
||
import com.kumofactory.cloud.blueprint.domain.aws.AwsBluePrint; | ||
import com.kumofactory.cloud.blueprint.dto.ComponentLineDto; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import org.hibernate.annotations.CreationTimestamp; | ||
import org.hibernate.annotations.UpdateTimestamp; | ||
|
||
import javax.persistence.*; | ||
import java.util.Date; | ||
|
||
@Entity | ||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ComponentLine { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
@CreationTimestamp | ||
private Date created_at; | ||
@UpdateTimestamp | ||
private Date updated_at; | ||
|
||
private String ui_id; // Client 에서 생성하는 uuid | ||
@OneToOne(cascade = CascadeType.ALL) | ||
private ComponentDot source; | ||
@OneToOne(cascade = CascadeType.ALL) | ||
private ComponentDot destination; | ||
@ManyToOne | ||
private AwsBluePrint bluePrint; | ||
|
||
public static ComponentLine createComponentLink(ComponentLineDto lineDto, AwsBluePrint bluePrint) { | ||
ComponentLine componentLink = new ComponentLine(); | ||
componentLink.setUi_id(lineDto.getId()); | ||
componentLink.setSource(ComponentDot.createComponentDot(lineDto.getSrc())); | ||
componentLink.setDestination(ComponentDot.createComponentDot(lineDto.getDst())); | ||
componentLink.setBluePrint(bluePrint); | ||
return componentLink; | ||
} | ||
} |
Oops, something went wrong.