├── .gitignore
├── src
├── main
│ ├── resources
│ │ ├── application.properties
│ │ └── static
│ │ │ ├── index.html
│ │ │ └── images
│ │ │ ├── kubernetes.svg
│ │ │ ├── docker.svg
│ │ │ ├── tekton.svg
│ │ │ ├── jenkins.svg
│ │ │ └── jenkinsx.svg
│ └── java
│ │ └── com
│ │ └── example
│ │ └── demo
│ │ └── DemoApplication.java
└── test
│ └── java
│ └── com
│ └── example
│ └── demo
│ └── DemoApplicationTests.java
├── Dockerfile
├── application-demo.yaml
├── deployment.yaml
├── Jenkinsfile
└── pom.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea/
2 | target/
3 |
--------------------------------------------------------------------------------
/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/main/java/com/example/demo/DemoApplication.java:
--------------------------------------------------------------------------------
1 | package com.example.demo;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class DemoApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(DemoApplication.class, args);
11 | }
12 |
13 | }
14 |
15 |
--------------------------------------------------------------------------------
/src/test/java/com/example/demo/DemoApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.example.demo;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class DemoApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/main/resources/static/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Spring Demo
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | |
13 |
14 | Spring Demo
15 | |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM registry.cn-beijing.aliyuncs.com/haoshuwei24/openjdk:8-jdk-slim
2 | ENV PORT 8080
3 | ENV CLASSPATH /opt/lib
4 | EXPOSE 8080
5 |
6 | # copy pom.xml and wildcards to avoid this command failing if there's no target/lib directory
7 | COPY pom.xml target/lib* /opt/lib/
8 |
9 | # NOTE we assume there's only 1 jar in the target dir
10 | # but at least this means we don't have to guess the name
11 | # we could do with a better way to know the name - or to always create an app.jar or something
12 | COPY target/*.jar /opt/app.jar
13 | WORKDIR /opt
14 | CMD ["java", "-jar", "app.jar"]
15 |
--------------------------------------------------------------------------------
/application-demo.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: apps/v1
2 | kind: Deployment
3 | metadata:
4 | name: application-demo
5 | spec:
6 | replicas: 1
7 | selector:
8 | matchLabels:
9 | app: application-demo
10 | template:
11 | metadata:
12 | labels:
13 | app: application-demo
14 | spec:
15 | containers:
16 | - name: application-demo
17 | image: IMAGE
18 | ports:
19 | - containerPort: 8080
20 |
21 | ---
22 | apiVersion: v1
23 | kind: Service
24 | metadata:
25 | name: application-demo
26 | spec:
27 | ports:
28 | - port: 80
29 | targetPort: 8080
30 | name: application-demo
31 | selector:
32 | app: application-demo
33 | type: ClusterIP
34 |
--------------------------------------------------------------------------------
/deployment.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: apps/v1
2 | kind: Deployment
3 | metadata:
4 | name: jenkins-java-demo
5 | spec:
6 | replicas: 1
7 | selector:
8 | matchLabels:
9 | app: jenkins-java-demo
10 | template:
11 | metadata:
12 | labels:
13 | app: jenkins-java-demo
14 | spec:
15 | containers:
16 | - name: jenkins-java-demo
17 | image: IMAGE
18 | imagePullPolicy: Always
19 | ports:
20 | - containerPort: 8080
21 |
22 | ---
23 | apiVersion: v1
24 | kind: Service
25 | metadata:
26 | name: jenkins-java-demo
27 | spec:
28 | ports:
29 | - port: 80
30 | targetPort: 8080
31 | name: jenkins-java-demo
32 | selector:
33 | app: jenkins-java-demo
34 | type: ClusterIP
35 |
--------------------------------------------------------------------------------
/Jenkinsfile:
--------------------------------------------------------------------------------
1 | pipeline{
2 | // 定义groovy脚本中使用的环境变量
3 | environment{
4 | // 将构建任务中的构建参数转换为环境变量
5 | IMAGE = sh(returnStdout: true,script: 'echo registry.$image_region.aliyuncs.com/$image_namespace/$image_reponame:$image_tag').trim()
6 | BRANCH = sh(returnStdout: true,script: 'echo $branch').trim()
7 | }
8 |
9 | // 定义本次构建使用哪个标签的构建环境,本示例中为 “slave-pipeline”
10 | agent{
11 | node{
12 | label 'slave-pipeline'
13 | }
14 | }
15 |
16 | // "stages"定义项目构建的多个模块,可以添加多个 “stage”, 可以多个 “stage” 串行或者并行执行
17 | stages{
18 | // 定义第一个stage, 完成克隆源码的任务
19 | stage('Git'){
20 | steps{
21 | git branch: '${BRANCH}', credentialsId: '', url: 'https://github.com/haoshuwei/jenkins-demo.git'
22 | }
23 | }
24 |
25 | // 添加第二个stage, 运行源码打包命令
26 | // stage('Package'){
27 | // steps{
28 | // container("maven") {
29 | // sh "mvn package -B -DskipTests"
30 | // }
31 | // }
32 | // }
33 |
34 |
35 | // 添加第三个stage, 运行容器镜像构建和推送命令, 用到了environment中定义的groovy环境变量
36 | // stage('Image Build And Publish'){
37 | // steps{
38 | // container("kaniko") {
39 | // sh "kaniko -f `pwd`/Dockerfile -c `pwd` --destination=${IMAGE} --skip-tls-verify"
40 | // }
41 | // }
42 | // }
43 |
44 | // 添加第四个stage, 部署应用到指定k8s集群
45 | stage('Deploy to Kubernetes') {
46 | steps {
47 | container('kubectl') {
48 | sh "sed -i 's/IMAGE/${IMAGE}/g' application-demo.yaml"
49 | sh "kubectl apply -f application-demo.yaml"
50 | }
51 | }
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.2.RELEASE
9 |
10 |
11 | com.example
12 | demo
13 | 0.0.1-SNAPSHOT
14 | demo
15 | Demo project for Spring Boot
16 |
17 |
18 | 1.8
19 |
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter-actuator
25 |
26 |
27 | org.springframework.boot
28 | spring-boot-starter-web
29 |
30 |
31 |
32 | org.springframework.boot
33 | spring-boot-starter-test
34 | test
35 |
36 |
37 |
38 |
39 |
40 |
41 | org.springframework.boot
42 | spring-boot-maven-plugin
43 |
44 |
45 |
46 | org.apache.maven.plugins
47 | maven-deploy-plugin
48 | 2.8.2
49 |
50 |
51 | org.apache.maven.plugins
52 | maven-surefire-plugin
53 | 3.0.0-M1
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/src/main/resources/static/images/kubernetes.svg:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/src/main/resources/static/images/docker.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/main/resources/static/images/tekton.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/main/resources/static/images/jenkins.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/main/resources/static/images/jenkinsx.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------