Skip to content

Commit

Permalink
modiy NAMESPACE & add readiness & add deploy-online (kubesphere#2)
Browse files Browse the repository at this point in the history
* update Jenkinsfile & add readiness
  • Loading branch information
soulseen authored Apr 12, 2019
1 parent dfeac3c commit b15ee46
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 22 deletions.
18 changes: 9 additions & 9 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ pipeline {
GITLAB_CREDENTIAL_ID = 'gitlab-id'
KUBECONFIG_CREDENTIAL_ID = 'demo-kubeconfig'
REDISTRY = 'harbor.devops.kubesphere.local:30280'
NAMESPACE = 'library'
HARBOR_NAMESPACE = 'library'
GITLAB_ACCOUNT = 'admin1'
APP_NAME = 'devops-sample-s2i'
APP_NAME = 'devops-java-sample'
SONAR_CREDENTIAL_ID= 'sonar-token'
}

Expand Down Expand Up @@ -54,10 +54,10 @@ pipeline {
steps {
container ('maven') {
sh 'mvn -o -Dmaven.test.skip=true -gs `pwd`/configuration/settings.xml clean package'
sh 'docker build -t $REDISTRY/$NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER .'
sh 'docker build -t $REDISTRY/$HARBOR_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'
sh 'docker push $REDISTRY/$HARBOR_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER'
}
}
}
Expand All @@ -69,8 +69,8 @@ pipeline {
}
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 '
sh 'docker tag $REDISTRY/$HARBOR_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REDISTRY/$HARBOR_NAMESPACE/$APP_NAME:latest '
sh 'docker push $REDISTRY/$HARBOR_NAMESPACE/$APP_NAME:latest '
}
}
}
Expand All @@ -97,10 +97,10 @@ pipeline {
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/devops-sample-s2i.git --tags'
sh 'git push http://$GIT_USERNAME:$GIT_PASSWORD@gitlab.devops.kubesphere.local:30080/$GITLAB_ACCOUNT/devops-java-sample.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 '
sh 'docker tag $REDISTRY/$HARBOR_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REDISTRY/$HARBOR_NAMESPACE/$APP_NAME:$TAG_NAME '
sh 'docker push $REDISTRY/$HARBOR_NAMESPACE/$APP_NAME:$TAG_NAME '
}
}
}
Expand Down
22 changes: 11 additions & 11 deletions Jenkinsfile-online
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ pipeline {
GITHUB_CREDENTIAL_ID = 'github-id'
KUBECONFIG_CREDENTIAL_ID = 'demo-kubeconfig'
REDISTRY = 'docker.io'
NAMESPACE = 'docker_username'
DOCKERHUB_NAMESPACE = 'docker_username'
GITHUB_ACCOUNT = 'kubesphere'
APP_NAME = 'devops-sample-s2i'
APP_NAME = 'devops-java-sample'
SONAR_CREDENTIAL_ID= 'sonar-token'
}

Expand Down Expand Up @@ -54,10 +54,10 @@ pipeline {
steps {
container ('maven') {
sh 'mvn -o -Dmaven.test.skip=true -gs `pwd`/configuration/settings.xml clean package'
sh 'docker build -f Dockerfile-online -t $REDISTRY/$NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER .'
sh 'docker build -f Dockerfile-online -t $REDISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER .'
withCredentials([usernamePassword(passwordVariable : 'DOCKER_PASSWORD' ,usernameVariable : 'DOCKER_USERNAME' ,credentialsId : "$DOCKER_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'
sh 'docker push $REDISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER'
}
}
}
Expand All @@ -69,8 +69,8 @@ pipeline {
}
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 '
sh 'docker tag $REDISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REDISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:latest '
sh 'docker push $REDISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:latest '
}
}
}
Expand All @@ -81,7 +81,7 @@ pipeline {
}
steps {
input(id: 'deploy-to-dev', message: 'deploy to dev?')
kubernetesDeploy(configs: 'deploy/dev/**', enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID")
kubernetesDeploy(configs: 'deploy/dev-ol/**', enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID")
}
}
stage('push with tag'){
Expand All @@ -97,10 +97,10 @@ pipeline {
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@github.com/$GITHUB_ACCOUNT/devops-sample-s2i.git --tags'
sh 'git push http://$GIT_USERNAME:$GIT_PASSWORD@github.com/$GITHUB_ACCOUNT/devops-java-sample.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 '
sh 'docker tag $REDISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REDISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:$TAG_NAME '
sh 'docker push $REDISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:$TAG_NAME '
}
}
}
Expand All @@ -112,7 +112,7 @@ pipeline {
}
steps {
input(id: 'deploy-to-production', message: 'deploy to production?')
kubernetesDeploy(configs: 'deploy/prod/**', enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID")
kubernetesDeploy(configs: 'deploy/prod-ol/**', enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID")
}
}
}
Expand Down
21 changes: 21 additions & 0 deletions deploy/dev-ol/devops-sample-svc.yaml
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-sample-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
52 changes: 52 additions & 0 deletions deploy/dev-ol/devops-sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
labels:
app: kubesphere
component: ks-sample-dev
tier: backend
name: ks-sample-dev
namespace: kubesphere-sample-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/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER
readinessProbe:
httpGet:
path: /
port: 8080
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
6 changes: 5 additions & 1 deletion deploy/dev/devops-sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ spec:
value: js|html
- name: CACHE_PUBLIC_EXPIRATION
value: 3d
image: $REDISTRY/$NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER
image: $REDISTRY/$HARBOR_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER
readinessProbe:
httpGet:
path: /
port: 8080
imagePullPolicy: Always
name: ks-sample
ports:
Expand Down
21 changes: 21 additions & 0 deletions deploy/prod-ol/devops-sample-svc.yaml
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-sample-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
57 changes: 57 additions & 0 deletions deploy/prod-ol/devops-sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
labels:
app: kubesphere
component: ks-sample
tier: backend
name: ks-sample
namespace: kubesphere-sample-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/$DOCKERHUB_NAMESPACE/$APP_NAME:$TAG_NAME
readinessProbe:
httpGet:
path: /
port: 8080
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
6 changes: 5 additions & 1 deletion deploy/prod/devops-sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ spec:
value: js|html
- name: CACHE_PUBLIC_EXPIRATION
value: 3d
image: $REDISTRY/$NAMESPACE/$APP_NAME:$TAG_NAME
image: $REDISTRY/$HARBOR_NAMESPACE/$APP_NAME:$TAG_NAME
readinessProbe:
httpGet:
path: /
port: 8080
imagePullPolicy: Always
name: ks
ports:
Expand Down

0 comments on commit b15ee46

Please sign in to comment.