Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
robberphex committed Mar 10, 2022
0 parents commit e95d18b
Show file tree
Hide file tree
Showing 13 changed files with 238 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM eclipse-temurin:11-jdk-alpine

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories
RUN apk add curl vim iproute2 tcpdump

# copy arthas
COPY --from=hengyunabc/arthas:latest /opt/arthas /opt/arthas

WORKDIR /app
COPY /target/spring-boot-complete-0.0.1-SNAPSHOT.jar /app/opensergo-sca.jar
COPY /start.sh /app

EXPOSE 20002
CMD ["/app/start.sh"]

4 changes: 4 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

mvn clean package -DskipTests
docker build . -t registry.cn-huhehaote.aliyuncs.com/luyanbo-msc/opensergo-sca:0.0.1-SNAPSHOT
24 changes: 24 additions & 0 deletions deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: apps/v1 # for versions before 1.8.0 use apps/v1beta1
kind: Deployment
metadata:
name: luyanbo-opensergo-sca
labels:
app: luyanbo-opensergo-sca
spec:
replicas: 2
selector:
matchLabels:
app: luyanbo-opensergo-sca
template:
metadata:
labels:
app: luyanbo-opensergo-sca
spec:
containers:
- name: luyanbo-opensergo-sca
image: registry.cn-huhehaote.aliyuncs.com/luyanbo-msc/opensergo-sca:0.0.1-SNAPSHOT
ports:
- containerPort: 9991
resources:
limits:
cpu: "500m"
64 changes: 64 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>spring-boot-complete</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spring-boot-complete</name>
<description>Demo project for Spring Boot</description>

<properties>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-okhttp</artifactId>
<version>1.44.1</version>
</dependency>

<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-opensergo</artifactId>
<version>2021.0.1.1-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!-- tag::actuator[] -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- end::actuator[] -->

<!-- tag::tests[] -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- end::tests[] -->
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
19 changes: 19 additions & 0 deletions src/main/java/com/example/springboot/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.example.springboot;

import java.util.Arrays;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class Application {

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


}
19 changes: 19 additions & 0 deletions src/main/java/com/example/springboot/HelloController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.example.springboot;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

@GetMapping("/index")
public String index() {
return "Greetings from Spring Boot!\n";
}

@GetMapping("/hello")
public String hello() {
return "Hello from Spring Boot!\n";
}

}
21 changes: 21 additions & 0 deletions src/main/java/com/example/springboot/WebConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.example.springboot;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

private final Logger logger = LoggerFactory.getLogger(WebConfig.class);

@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("forward:/build/index.html");
}
}
15 changes: 15 additions & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
server:
port: 9991


spring:
application:
name: "luyanbo-opensergo"

management:
endpoint:
info:
enabled: true
web:
exposure:
include: "*"
1 change: 1 addition & 0 deletions src/main/resources/static/build/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello!
23 changes: 23 additions & 0 deletions src/test/java/com/example/springboot/HelloControllerIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example.springboot;

import org.junit.jupiter.api.Test;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.ResponseEntity;

import static org.assertj.core.api.Assertions.assertThat;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class HelloControllerIT {

@Autowired
private TestRestTemplate template;

@Test
public void getHello() throws Exception {
ResponseEntity<String> response = template.getForEntity("/", String.class);
assertThat(response.getBody()).isEqualTo("Greetings from Spring Boot!");
}
}
29 changes: 29 additions & 0 deletions src/test/java/com/example/springboot/HelloControllerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.example.springboot;

import static org.hamcrest.Matchers.equalTo;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import org.junit.jupiter.api.Test;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;

@SpringBootTest
@AutoConfigureMockMvc
public class HelloControllerTest {

@Autowired
private MockMvc mvc;

@Test
public void getHello() throws Exception {
mvc.perform(MockMvcRequestBuilders.get("/").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().string(equalTo("Greetings from Spring Boot!")));
}
}
3 changes: 3 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

java -jar /app/opensergo-sca.jar

0 comments on commit e95d18b

Please sign in to comment.