Skip to content

Commit

Permalink
Merge pull request #19 from sw-maestro-kumofactory/feature/#17-blueprint
Browse files Browse the repository at this point in the history
Feature/#17 blueprint
  • Loading branch information
nookcoder authored Jul 17, 2023
2 parents c217a78 + 9f42d0b commit 0e6fd95
Show file tree
Hide file tree
Showing 45 changed files with 1,326 additions and 116 deletions.
136 changes: 136 additions & 0 deletions .github/workflows/Build-Deploy-dev.yaml
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
18 changes: 10 additions & 8 deletions .github/workflows/Build-Test.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: KUMO-SERVER-Build-Test-on-Push CI/CD
name: Build Test CI/CD

on:
pull_request:
branches: ['main', 'dev']
push:
branches-ignore: [ 'main', 'dev']

jobs:
build:
Expand All @@ -11,14 +11,16 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Set up JDK 17
- name: Setup JDK 17
uses: actions/setup-java@v2
with:
java-version: 17
distribution: 'adopt'

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Setup Gradle 7.6
uses: gradle/gradle-build-action@v2
with:
gradle-version: 7.6

- name: Build Project
run: ./gradlew build
run: gradle build
9 changes: 9 additions & 0 deletions Dockerfile
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"]
35 changes: 22 additions & 13 deletions build.gradle
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()
}
6 changes: 5 additions & 1 deletion src/main/java/com/kumofactory/cloud/CloudApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

@SpringBootApplication
public class CloudApplication {

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

}
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;
}
}
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;
}

}
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;
}
}
Loading

0 comments on commit 0e6fd95

Please sign in to comment.