forked from kubesphere/devops-maven-sample
-
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.
- Loading branch information
Showing
14 changed files
with
404 additions
and
0 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 @@ | ||
.idea/* |
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,2 @@ | ||
S2I_DESTINATION=/tmp/src | ||
MAVEN_ARGS_APPEND=-o |
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 harbor.devops.kubesphere.local:30280/library/java:openjdk-8-jre-alpine | ||
|
||
WORKDIR /home | ||
|
||
COPY ./devops-sample-s2i/src/target/*.jar /home | ||
|
||
ENTRYPOINT java -jar *.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 |
---|---|---|
@@ -0,0 +1,105 @@ | ||
pipeline { | ||
agent { | ||
node { | ||
label 'maven' | ||
} | ||
} | ||
|
||
parameters { | ||
string(name:'TAG_NAME',defaultValue: '',description:'') | ||
} | ||
|
||
environment { | ||
SOURCE_DIR_NAME = 'devops-sample-s2i' | ||
HARBOR_CREDENTIAL_ID = 'harbor-id' | ||
GITLAB_CREDENTIAL_ID = 'gitlab-id' | ||
KUBECONFIG_CREDENTIAL_ID = 'demo-kubeconfig' | ||
REDISTRY = 'harbor.devops.kubesphere.local:30280' | ||
NAMESPACE = 'library' | ||
GITLAB_ACCOUNT = 'admin1' | ||
APP_NAME = 'devops-sample' | ||
} | ||
|
||
stages { | ||
stage ('checkout scm') { | ||
steps { | ||
checkout(scm) | ||
} | ||
} | ||
|
||
stage ('unit test') { | ||
steps { | ||
container ('maven') { | ||
sh 'cd $SOURCE_DIR_NAME' | ||
sh 'mvn -o -f $SOURCE_DIR_NAME/src -gs `pwd`/$SOURCE_DIR_NAME/src/configuration/settings.xml test' | ||
} | ||
} | ||
} | ||
|
||
stage ('build & push') { | ||
steps { | ||
container ('maven') { | ||
sh 'mvn -o -Dmaven.test.skip=true -f $SOURCE_DIR_NAME/src -gs `pwd`/$SOURCE_DIR_NAME/src/configuration/settings.xml clean package' | ||
sh 'docker build -t $REDISTRY/$NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER .' | ||
withCredentials([usernamePassword(passwordVariable : 'DOCKER_PASSWORD' ,usernameVariable : 'DOCKER_USERNAME' ,credentialsId : "$HARBOR_CREDENTIAL_ID" ,)]) { | ||
sh 'echo "$DOCKER_PASSWORD" | docker login $REDISTRY -u "$DOCKER_USERNAME" --password-stdin' | ||
sh 'docker push $REDISTRY/$NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER' | ||
} | ||
} | ||
} | ||
} | ||
|
||
stage('push latest'){ | ||
when{ | ||
branch 'master' | ||
} | ||
steps{ | ||
container ('maven') { | ||
sh 'docker tag $REDISTRY/$NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REDISTRY/$NAMESPACE/$APP_NAME:latest ' | ||
sh 'docker push $REDISTRY/$NAMESPACE/$APP_NAME:latest ' | ||
} | ||
} | ||
} | ||
|
||
stage('deploy to dev') { | ||
when{ | ||
branch 'master' | ||
} | ||
steps { | ||
input(id: 'deploy-to-dev', message: 'deploy to dev?') | ||
kubernetesDeploy(configs: 'deploy/dev/**', enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID") | ||
} | ||
} | ||
stage('push with tag'){ | ||
when{ | ||
expression{ | ||
return params.TAG_NAME =~ /v.*/ | ||
} | ||
} | ||
steps { | ||
container ('maven') { | ||
input(id: 'release-image-with-tag', message: 'release image with tag?') | ||
withCredentials([usernamePassword(credentialsId: "$GITLAB_CREDENTIAL_ID", passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) { | ||
sh 'git config --global user.email "kubesphere@yunify.com" ' | ||
sh 'git config --global user.name "kubesphere" ' | ||
sh 'git tag -a $TAG_NAME -m "$TAG_NAME" ' | ||
sh 'git push http://$GIT_USERNAME:$GIT_PASSWORD@gitlab.devops.kubesphere.local:30080/$GITLAB_ACCOUNT/$APP_NAME.git --tags' | ||
} | ||
sh 'docker tag $REDISTRY/$NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REDISTRY/$NAMESPACE/$APP_NAME:$TAG_NAME ' | ||
sh 'docker push $REDISTRY/$NAMESPACE/$APP_NAME:$TAG_NAME ' | ||
} | ||
} | ||
} | ||
stage('deploy to production') { | ||
when{ | ||
expression{ | ||
return params.TAG_NAME =~ /v.*/ | ||
} | ||
} | ||
steps { | ||
input(id: 'deploy-to-production', message: 'deploy to production?') | ||
kubernetesDeploy(configs: 'deploy/prod/**', enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID") | ||
} | ||
} | ||
} | ||
} |
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,21 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
labels: | ||
app: kubesphere | ||
component: ks-sample-dev | ||
name: ks-sample-dev | ||
namespace: kubesphere-dev | ||
spec: | ||
ports: | ||
- name: http | ||
port: 8080 | ||
protocol: TCP | ||
targetPort: 8080 | ||
nodePort: 30861 | ||
selector: | ||
app: kubesphere | ||
component: ks-sample-dev | ||
tier: backend | ||
sessionAffinity: None | ||
type: NodePort |
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,48 @@ | ||
apiVersion: extensions/v1beta1 | ||
kind: Deployment | ||
metadata: | ||
labels: | ||
app: kubesphere | ||
component: ks-sample-dev | ||
tier: backend | ||
name: ks-sample-dev | ||
namespace: kubesphere-dev | ||
spec: | ||
progressDeadlineSeconds: 600 | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: kubesphere | ||
component: ks-sample-dev | ||
tier: backend | ||
template: | ||
metadata: | ||
labels: | ||
app: kubesphere | ||
component: ks-sample-dev | ||
tier: backend | ||
spec: | ||
containers: | ||
- env: | ||
- name: CACHE_IGNORE | ||
value: js|html | ||
- name: CACHE_PUBLIC_EXPIRATION | ||
value: 3d | ||
image: $REDISTRY/$NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER | ||
imagePullPolicy: Always | ||
name: ks-sample | ||
ports: | ||
- containerPort: 8080 | ||
protocol: TCP | ||
resources: | ||
limits: | ||
cpu: 200m | ||
memory: 500Mi | ||
requests: | ||
cpu: 100m | ||
memory: 100Mi | ||
terminationMessagePath: /dev/termination-log | ||
terminationMessagePolicy: File | ||
dnsPolicy: ClusterFirst | ||
restartPolicy: Always | ||
terminationGracePeriodSeconds: 30 |
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,21 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
labels: | ||
app: kubesphere | ||
component: ks-sample | ||
name: ks-sample | ||
namespace: kubesphere-prod | ||
spec: | ||
ports: | ||
- name: http | ||
port: 8080 | ||
protocol: TCP | ||
targetPort: 8080 | ||
nodePort: 30961 | ||
selector: | ||
app: kubesphere | ||
component: ks-sample | ||
tier: backend | ||
sessionAffinity: None | ||
type: NodePort |
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,53 @@ | ||
apiVersion: extensions/v1beta1 | ||
kind: Deployment | ||
metadata: | ||
labels: | ||
app: kubesphere | ||
component: ks-sample | ||
tier: backend | ||
name: ks-sample | ||
namespace: kubesphere-prod | ||
spec: | ||
progressDeadlineSeconds: 600 | ||
replicas: 2 | ||
selector: | ||
matchLabels: | ||
app: kubesphere | ||
component: ks-sample | ||
tier: backend | ||
strategy: | ||
rollingUpdate: | ||
maxSurge: 1 | ||
maxUnavailable: 1 | ||
type: RollingUpdate | ||
template: | ||
metadata: | ||
labels: | ||
app: kubesphere | ||
component: ks-sample | ||
tier: backend | ||
spec: | ||
containers: | ||
- env: | ||
- name: CACHE_IGNORE | ||
value: js|html | ||
- name: CACHE_PUBLIC_EXPIRATION | ||
value: 3d | ||
image: $REDISTRY/$NAMESPACE/$APP_NAME:$TAG_NAME | ||
imagePullPolicy: Always | ||
name: ks | ||
ports: | ||
- containerPort: 8080 | ||
protocol: TCP | ||
resources: | ||
limits: | ||
cpu: 200m | ||
memory: 500Mi | ||
requests: | ||
cpu: 100m | ||
memory: 100Mi | ||
terminationMessagePath: /dev/termination-log | ||
terminationMessagePolicy: File | ||
dnsPolicy: ClusterFirst | ||
restartPolicy: Always | ||
terminationGracePeriodSeconds: 30 |
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 @@ | ||
# devops-sample |
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,36 @@ | ||
<settings> | ||
<pluginGroups> | ||
<pluginGroup>org.jenkins-ci.tools</pluginGroup> | ||
</pluginGroups> | ||
|
||
<localRepository>${PWD}/devops-sample-s2i/artifacts/m2</localRepository> | ||
|
||
<profiles> | ||
<!-- Give access to Jenkins plugins --> | ||
<profile> | ||
<id>jenkins</id> | ||
<activation> | ||
<activeByDefault>true</activeByDefault> <!-- change this to false, if you don't like to have it on per default --> | ||
</activation> | ||
<repositories> | ||
<repository> | ||
<id>repo.jenkins-ci.org</id> | ||
<url>https://repo.jenkins-ci.org/public/</url> | ||
</repository> | ||
</repositories> | ||
<pluginRepositories> | ||
<pluginRepository> | ||
<id>repo.jenkins-ci.org</id> | ||
<url>https://repo.jenkins-ci.org/public/</url> | ||
</pluginRepository> | ||
</pluginRepositories> | ||
</profile> | ||
</profiles> | ||
<mirrors> | ||
<mirror> | ||
<id>repo.jenkins-ci.org</id> | ||
<url>https://repo.jenkins-ci.org/public/</url> | ||
<mirrorOf>m.g.o-public</mirrorOf> | ||
</mirror> | ||
</mirrors> | ||
</settings> |
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,63 @@ | ||
<?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>io.kubesphere.devops</groupId> | ||
<artifactId>devops-sample</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<name>devops-sample :: HelloWorld Demo</name> | ||
|
||
<!-- Spring Boot 启动父依赖 --> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>1.4.1.BUILD-SNAPSHOT</version> | ||
</parent> | ||
|
||
<repositories> | ||
<repository> | ||
<id>spring-snapshots</id> | ||
<url>http://repo.spring.io/snapshot</url> | ||
<snapshots><enabled>true</enabled></snapshots> | ||
</repository> | ||
<repository> | ||
<id>spring-milestones</id> | ||
<url>http://repo.spring.io/milestone</url> | ||
</repository> | ||
</repositories> | ||
<pluginRepositories> | ||
<pluginRepository> | ||
<id>spring-snapshots</id> | ||
<url>http://repo.spring.io/snapshot</url> | ||
</pluginRepository> | ||
<pluginRepository> | ||
<id>spring-milestones</id> | ||
<url>http://repo.spring.io/milestone</url> | ||
</pluginRepository> | ||
</pluginRepositories> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.12</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
<configuration> | ||
<fork>true</fork> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
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,12 @@ | ||
package io.kubesphere.devops; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class Application { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(Application.class,args); | ||
} | ||
} |
Oops, something went wrong.