commit
9feab11fd0
11 changed files with 344 additions and 0 deletions
Unified View
Diff Options
-
2.gitignore
-
6Dockerfile
-
59Jenkinsfile
-
46k8s.yaml
-
100pom.xml
-
84spring-boot-docker.iml
-
4src/main/docker/Dockerfile
-
12src/main/java/com/neo/DockerApplication.java
-
13src/main/java/com/neo/controller/DockerController.java
-
0src/main/resources/application.properties
-
18src/test/java/com/neo/DockerApplicationTests.java
@ -0,0 +1,2 @@ |
|||||
|
target |
||||
|
.idea |
||||
@ -0,0 +1,6 @@ |
|||||
|
FROM openjdk:8u191-jre-alpine3.9 |
||||
|
ENTRYPOINT ["/usr/bin/java", "-jar", "/app.jar"] |
||||
|
#ARG JAR_FILE |
||||
|
#ADD ${JAR_FILE} /app.jar |
||||
|
ADD target/spring-boot-docker-1.0.jar /app.jar |
||||
|
EXPOSE 8080 |
||||
@ -0,0 +1,59 @@ |
|||||
|
node('backend-jnlp') { |
||||
|
stage('Clone') { |
||||
|
echo "1.Clone Stage" |
||||
|
checkout scm |
||||
|
script { |
||||
|
build_tag = sh(returnStdout: true, script: 'git rev-parse --short HEAD').trim() |
||||
|
|
||||
|
// if (env.BRANCH_NAME != 'master') { |
||||
|
// build_tag = "${env.BRANCH_NAME}-${build_tag}" |
||||
|
// } |
||||
|
} |
||||
|
} |
||||
|
stage('Test') { |
||||
|
echo "2.Test Stage" |
||||
|
} |
||||
|
stage('Build docker image') { |
||||
|
echo "3.Build Docker Image Stage" |
||||
|
sh "pwd" |
||||
|
sh "ls -l" |
||||
|
sh "/mnt/nfses/mavenDatas/bin/mvn clean package" |
||||
|
sh "docker build -t 120.78.76.88/test/backend-demo:${build_tag} ." |
||||
|
} |
||||
|
stage('Push') { |
||||
|
echo "4.Push Docker Image Stage" |
||||
|
withCredentials([usernamePassword(credentialsId: 'harbor', passwordVariable: 'harborPassword', usernameVariable: 'harborUser')]) { |
||||
|
sh "docker login -u ${harborUser} -p ${harborPassword} 120.78.76.88" |
||||
|
sh "docker push 120.78.76.88/test/backend-demo:${build_tag}" |
||||
|
} |
||||
|
} |
||||
|
stage('YAML') { |
||||
|
echo "5. Change YAML File Stage" |
||||
|
//def userInput = input( |
||||
|
// id: 'userInput', |
||||
|
// message: 'Choose a deploy environment', |
||||
|
// parameters: [ |
||||
|
// [ |
||||
|
// $class: 'ChoiceParameterDefinition', |
||||
|
// choices: "Dev\nQA\nProd", |
||||
|
// name: 'Env' |
||||
|
// ] |
||||
|
// ] |
||||
|
//) |
||||
|
//echo "This is a deploy step to ${userInput.Env}" |
||||
|
sh "sed -i 's/<BUILD_TAG>/${build_tag}/' k8s.yaml" |
||||
|
//sh "sed -i 's/<BRANCH_NAME>/${env.BRANCH_NAME}/' k8s.yaml" |
||||
|
} |
||||
|
stage('Deploy') { |
||||
|
echo "6. Deploy Stage" |
||||
|
//if (userInput.Env == "Dev") { |
||||
|
// deploy dev stuff |
||||
|
//} else if (userInput.Env == "QA"){ |
||||
|
// deploy qa stuff |
||||
|
//} else { |
||||
|
// deploy prod stuff |
||||
|
// input "确认要部署线上环境吗?" |
||||
|
//} |
||||
|
sh "kubectl apply -f k8s.yaml" |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,46 @@ |
|||||
|
apiVersion: apps/v1 |
||||
|
kind: Deployment |
||||
|
metadata: |
||||
|
labels: |
||||
|
env: dev |
||||
|
type: backend |
||||
|
name: jenkins-backend-demo |
||||
|
namespace: backend |
||||
|
spec: |
||||
|
selector: |
||||
|
matchLabels: |
||||
|
app: jenkins-backend-demo |
||||
|
template: |
||||
|
metadata: |
||||
|
labels: |
||||
|
app: jenkins-backend-demo |
||||
|
spec: |
||||
|
containers: |
||||
|
- image: 120.78.76.88/test/backend-demo:<BUILD_TAG> |
||||
|
imagePullPolicy: IfNotPresent |
||||
|
name: jenkins-backend-demo |
||||
|
env: |
||||
|
- name: branch |
||||
|
value: <BRANCH_NAME> |
||||
|
ports: |
||||
|
- containerPort: 8080 |
||||
|
name: web |
||||
|
protocol: TCP |
||||
|
|
||||
|
--- |
||||
|
apiVersion: v1 |
||||
|
kind: Service |
||||
|
metadata: |
||||
|
name: jenkins-backend-demo-svc |
||||
|
namespace: backend |
||||
|
labels: |
||||
|
app: jenkins-backend-demo |
||||
|
spec: |
||||
|
selector: |
||||
|
app: jenkins-backend-demo |
||||
|
type: NodePort |
||||
|
ports: |
||||
|
- name: web |
||||
|
port: 8080 |
||||
|
targetPort: web |
||||
|
nodePort: 30011 |
||||
@ -0,0 +1,100 @@ |
|||||
|
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
|
<modelVersion>4.0.0</modelVersion> |
||||
|
|
||||
|
<groupId>com.neo</groupId> |
||||
|
<artifactId>spring-boot-docker</artifactId> |
||||
|
<version>1.0</version> |
||||
|
<packaging>jar</packaging> |
||||
|
|
||||
|
<name>spring-boot-docker</name> |
||||
|
<description>Demo project for Spring Boot</description> |
||||
|
|
||||
|
<parent> |
||||
|
<groupId>org.springframework.boot</groupId> |
||||
|
<artifactId>spring-boot-starter-parent</artifactId> |
||||
|
<version>2.0.0.RELEASE</version> |
||||
|
</parent> |
||||
|
|
||||
|
<properties> |
||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
||||
|
<java.version>1.8</java.version> |
||||
|
<docker.image.prefix>springboot</docker.image.prefix> |
||||
|
<!--<docker.repostory>120.78.76.88:80</docker.repostory>--> |
||||
|
</properties> |
||||
|
|
||||
|
<dependencies> |
||||
|
<dependency> |
||||
|
<groupId>org.springframework.boot</groupId> |
||||
|
<artifactId>spring-boot-starter-web</artifactId> |
||||
|
</dependency> |
||||
|
<dependency> |
||||
|
<groupId>org.springframework.boot</groupId> |
||||
|
<artifactId>spring-boot-starter-test</artifactId> |
||||
|
<scope>test</scope> |
||||
|
</dependency> |
||||
|
</dependencies> |
||||
|
|
||||
|
<build> |
||||
|
<plugins> |
||||
|
<plugin> |
||||
|
<groupId>org.springframework.boot</groupId> |
||||
|
<artifactId>spring-boot-maven-plugin</artifactId> |
||||
|
</plugin> |
||||
|
<plugin> |
||||
|
<groupId>org.apache.maven.plugins</groupId> |
||||
|
<artifactId>maven-deploy-plugin</artifactId> |
||||
|
<configuration> |
||||
|
<skip>true</skip> |
||||
|
</configuration> |
||||
|
</plugin> |
||||
|
|
||||
|
<!--<plugin>--> |
||||
|
<!--<groupId>com.spotify</groupId>--> |
||||
|
<!--<artifactId>dockerfile-maven-plugin</artifactId>--> |
||||
|
<!--<executions>--> |
||||
|
<!--<execution>--> |
||||
|
<!--<id>default</id>--> |
||||
|
<!--<goals>--> |
||||
|
<!--<!–如果package时不想用docker打包,就注释掉这个goal–>--> |
||||
|
<!--<goal>build</goal>--> |
||||
|
<!--<goal>push</goal>--> |
||||
|
<!--</goals>--> |
||||
|
<!--</execution>--> |
||||
|
<!--</executions>--> |
||||
|
<!--<configuration>--> |
||||
|
<!--<username>admin</username>--> |
||||
|
<!--<password>Harbor12345</password>--> |
||||
|
<!--<repository>${docker.repostory}/test/${project.artifactId}</repository>--> |
||||
|
<!--<tag>${project.version}</tag>--> |
||||
|
<!--<buildArgs>--> |
||||
|
<!--<!–提供参数向Dockerfile传递–>--> |
||||
|
<!--<JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>--> |
||||
|
<!--</buildArgs>--> |
||||
|
<!--</configuration>--> |
||||
|
<!--</plugin>--> |
||||
|
|
||||
|
<!-- Docker maven plugin --> |
||||
|
<!--<plugin>--> |
||||
|
<!--<groupId>com.spotify</groupId>--> |
||||
|
<!--<artifactId>docker-maven-plugin</artifactId>--> |
||||
|
<!--<version>1.0.0</version>--> |
||||
|
<!--<configuration>--> |
||||
|
<!--<imageName>${docker.image.prefix}/${project.artifactId}</imageName>--> |
||||
|
<!--<dockerDirectory>src/main/docker</dockerDirectory>--> |
||||
|
<!--<resources>--> |
||||
|
<!--<resource>--> |
||||
|
<!--<targetPath>/</targetPath>--> |
||||
|
<!--<directory>${project.build.directory}</directory>--> |
||||
|
<!--<include>${project.build.finalName}.jar</include>--> |
||||
|
<!--</resource>--> |
||||
|
<!--</resources>--> |
||||
|
<!--</configuration>--> |
||||
|
<!--</plugin>--> |
||||
|
<!-- Docker maven plugin --> |
||||
|
</plugins> |
||||
|
</build> |
||||
|
|
||||
|
|
||||
|
</project> |
||||
@ -0,0 +1,84 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> |
||||
|
<component name="FacetManager"> |
||||
|
<facet type="Spring" name="Spring"> |
||||
|
<configuration /> |
||||
|
</facet> |
||||
|
<facet type="web" name="Web"> |
||||
|
<configuration> |
||||
|
<webroots /> |
||||
|
<sourceRoots> |
||||
|
<root url="file://$MODULE_DIR$/src/main/java" /> |
||||
|
<root url="file://$MODULE_DIR$/src/main/resources" /> |
||||
|
</sourceRoots> |
||||
|
</configuration> |
||||
|
</facet> |
||||
|
</component> |
||||
|
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8"> |
||||
|
<output url="file://$MODULE_DIR$/target/classes" /> |
||||
|
<output-test url="file://$MODULE_DIR$/target/test-classes" /> |
||||
|
<content url="file://$MODULE_DIR$"> |
||||
|
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> |
||||
|
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" /> |
||||
|
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" /> |
||||
|
<excludeFolder url="file://$MODULE_DIR$/target" /> |
||||
|
</content> |
||||
|
<orderEntry type="inheritedJdk" /> |
||||
|
<orderEntry type="sourceFolder" forTests="false" /> |
||||
|
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-web:2.0.0.RELEASE" level="project" /> |
||||
|
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter:2.0.0.RELEASE" level="project" /> |
||||
|
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot:2.0.0.RELEASE" level="project" /> |
||||
|
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-autoconfigure:2.0.0.RELEASE" level="project" /> |
||||
|
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-logging:2.0.0.RELEASE" level="project" /> |
||||
|
<orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.2.3" level="project" /> |
||||
|
<orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.2.3" level="project" /> |
||||
|
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-to-slf4j:2.10.0" level="project" /> |
||||
|
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.10.0" level="project" /> |
||||
|
<orderEntry type="library" name="Maven: org.slf4j:jul-to-slf4j:1.7.25" level="project" /> |
||||
|
<orderEntry type="library" name="Maven: javax.annotation:javax.annotation-api:1.3.2" level="project" /> |
||||
|
<orderEntry type="library" scope="RUNTIME" name="Maven: org.yaml:snakeyaml:1.19" level="project" /> |
||||
|
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-json:2.0.0.RELEASE" level="project" /> |
||||
|
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.9.4" level="project" /> |
||||
|
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.9.0" level="project" /> |
||||
|
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.9.4" level="project" /> |
||||
|
<orderEntry type="library" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.9.4" level="project" /> |
||||
|
<orderEntry type="library" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.9.4" level="project" /> |
||||
|
<orderEntry type="library" name="Maven: com.fasterxml.jackson.module:jackson-module-parameter-names:2.9.4" level="project" /> |
||||
|
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-tomcat:2.0.0.RELEASE" level="project" /> |
||||
|
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-core:8.5.28" level="project" /> |
||||
|
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-el:8.5.28" level="project" /> |
||||
|
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-websocket:8.5.28" level="project" /> |
||||
|
<orderEntry type="library" name="Maven: org.hibernate.validator:hibernate-validator:6.0.7.Final" level="project" /> |
||||
|
<orderEntry type="library" name="Maven: javax.validation:validation-api:2.0.1.Final" level="project" /> |
||||
|
<orderEntry type="library" name="Maven: org.jboss.logging:jboss-logging:3.3.2.Final" level="project" /> |
||||
|
<orderEntry type="library" name="Maven: com.fasterxml:classmate:1.3.4" level="project" /> |
||||
|
<orderEntry type="library" name="Maven: org.springframework:spring-web:5.0.4.RELEASE" level="project" /> |
||||
|
<orderEntry type="library" name="Maven: org.springframework:spring-beans:5.0.4.RELEASE" level="project" /> |
||||
|
<orderEntry type="library" name="Maven: org.springframework:spring-webmvc:5.0.4.RELEASE" level="project" /> |
||||
|
<orderEntry type="library" name="Maven: org.springframework:spring-aop:5.0.4.RELEASE" level="project" /> |
||||
|
<orderEntry type="library" name="Maven: org.springframework:spring-context:5.0.4.RELEASE" level="project" /> |
||||
|
<orderEntry type="library" name="Maven: org.springframework:spring-expression:5.0.4.RELEASE" level="project" /> |
||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-starter-test:2.0.0.RELEASE" level="project" /> |
||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-test:2.0.0.RELEASE" level="project" /> |
||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-test-autoconfigure:2.0.0.RELEASE" level="project" /> |
||||
|
<orderEntry type="library" scope="TEST" name="Maven: com.jayway.jsonpath:json-path:2.4.0" level="project" /> |
||||
|
<orderEntry type="library" scope="TEST" name="Maven: net.minidev:json-smart:2.3" level="project" /> |
||||
|
<orderEntry type="library" scope="TEST" name="Maven: net.minidev:accessors-smart:1.2" level="project" /> |
||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.ow2.asm:asm:5.0.4" level="project" /> |
||||
|
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" /> |
||||
|
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" /> |
||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.assertj:assertj-core:3.9.1" level="project" /> |
||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.mockito:mockito-core:2.15.0" level="project" /> |
||||
|
<orderEntry type="library" scope="TEST" name="Maven: net.bytebuddy:byte-buddy:1.7.10" level="project" /> |
||||
|
<orderEntry type="library" scope="TEST" name="Maven: net.bytebuddy:byte-buddy-agent:1.7.10" level="project" /> |
||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.objenesis:objenesis:2.6" level="project" /> |
||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" /> |
||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-library:1.3" level="project" /> |
||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.skyscreamer:jsonassert:1.5.0" level="project" /> |
||||
|
<orderEntry type="library" scope="TEST" name="Maven: com.vaadin.external.google:android-json:0.0.20131108.vaadin1" level="project" /> |
||||
|
<orderEntry type="library" name="Maven: org.springframework:spring-core:5.0.4.RELEASE" level="project" /> |
||||
|
<orderEntry type="library" name="Maven: org.springframework:spring-jcl:5.0.4.RELEASE" level="project" /> |
||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.springframework:spring-test:5.0.4.RELEASE" level="project" /> |
||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.xmlunit:xmlunit-core:2.5.1" level="project" /> |
||||
|
</component> |
||||
|
</module> |
||||
@ -0,0 +1,4 @@ |
|||||
|
FROM openjdk:8-jdk-alpine |
||||
|
VOLUME /tmp |
||||
|
ADD spring-boot-docker-1.0.jar app.jar |
||||
|
ENTRYPOINT ["java","-Duser.timezone=GMT+8 -Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"] |
||||
@ -0,0 +1,12 @@ |
|||||
|
package com.neo; |
||||
|
|
||||
|
import org.springframework.boot.SpringApplication; |
||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication; |
||||
|
|
||||
|
@SpringBootApplication |
||||
|
public class DockerApplication { |
||||
|
|
||||
|
public static void main(String[] args) { |
||||
|
SpringApplication.run(DockerApplication.class, args); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,13 @@ |
|||||
|
package com.neo.controller; |
||||
|
|
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RestController; |
||||
|
|
||||
|
@RestController |
||||
|
public class DockerController { |
||||
|
|
||||
|
@RequestMapping("/") |
||||
|
public String index() { |
||||
|
return "Hello Docker!"; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
package com.neo; |
||||
|
|
||||
|
import org.junit.Test; |
||||
|
import org.junit.runner.RunWith; |
||||
|
import org.springframework.boot.test.context.SpringBootTest; |
||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
||||
|
import org.springframework.test.context.junit4.SpringRunner; |
||||
|
|
||||
|
@RunWith(SpringRunner.class) |
||||
|
@SpringBootTest |
||||
|
public class DockerApplicationTests { |
||||
|
|
||||
|
@Test |
||||
|
public void contextLoads() { |
||||
|
System.out.println("hello docker"); |
||||
|
} |
||||
|
|
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save