Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Lei Xu committed Jun 23, 2021
1 parent 4877535 commit 13cbf98
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 12 deletions.
31 changes: 22 additions & 9 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ pipeline {
}
}

stage('SonarQube Check') {
stage('CI - SonarQube Check') {
steps {
sh 'docker run --rm -e SONAR_HOST_URL="${SONAR_HOST_URL}" -e SONAR_LOGIN="${SONAR_LOGIN}" -v "${PWD}:/usr/src" sonarsource/sonar-scanner-cli'
}
}

stage('Unit Tests & Publish Result') {
stage('CI - Unit Tests & Publish Result') {
steps {
sh 'docker-compose -f docker-compose-build.yaml -p boathouse-calculator-testrun up'
sh 'docker-compose -f docker-compose-build.yaml -p boathouse-calculator-testrundown -v --rmi all --remove-orphans'
Expand All @@ -47,7 +47,7 @@ pipeline {
}
}

stage('Docker Build & Push') {
stage('CI - Docker Build & Push') {
steps {
echo "Docker Build ... "
sh 'docker build -f Dockerfile -t ${REGISTRY_URL}/${REGISTRY_NS}/boathouse-calculator:latest .'
Expand All @@ -65,7 +65,7 @@ pipeline {
}

// dev 环境
stage('Deploy - DEV') {
stage('CD - DEV') {
steps {
sh "sed -i 's/#{REGISTRY_URL}#/${REGISTRY_URL}/g' docker-compose-template.yaml"
sh "sed -i 's/#{REGISTRY_NS}#/${REGISTRY_NS}/g' docker-compose-template.yaml"
Expand All @@ -91,15 +91,28 @@ pipeline {
}

// 测试环境部署
stage('Deploy - K8S TEST') {
stage('CD - K8S TEST') {
steps {
timeout(5) {
input message: '是否部署到测试环境?', ok: '', submitter: 'admin'
}
sh "sed -i 's/#{REGISTRY_URL}#/${REGISTRY_URL}/g' kube-deploy.yaml"
sh "sed -i 's/#{REGISTRY_NS}#/${REGISTRY_NS}/g' kube-deploy.yaml"
sh "sed -i 's/#{K8S_NAMESPACE_TEST}#/${K8S_NAMESPACE_TEST}/g' kube-deploy.yaml"
kubernetesDeploy configs: 'kube-deploy.yaml', deleteResource: false, kubeconfigId: 'minikube', secretName: 'regcred', secretNamespace: 'boathouse-test'
sh "sed -i 's/#{REGISTRY_URL}#/${REGISTRY_URL}/g' kube-deploy-test.yaml"
sh "sed -i 's/#{REGISTRY_NS}#/${REGISTRY_NS}/g' kube-deploy-test.yaml"
sh "sed -i 's/#{K8S_NAMESPACE}#/${K8S_NAMESPACE_TEST}/g' kube-deploy-test.yaml"
kubernetesDeploy configs: 'kube-deploy-test.yaml', deleteResource: false, kubeconfigId: 'minikube', secretName: 'regcred', secretNamespace: 'boathouse-test'
}
}

// 测试环境部署
stage('CD - K8S Prod') {
steps {
timeout(5) {
input message: '是否部署到生产环境?', ok: '', submitter: 'admin'
}
sh "sed -i 's/#{REGISTRY_URL}#/${REGISTRY_URL}/g' kube-deploy-prod.yaml"
sh "sed -i 's/#{REGISTRY_NS}#/${REGISTRY_NS}/g' kube-deploy-prod.yaml"
sh "sed -i 's/#{K8S_NAMESPACE}#/${K8S_NAMESPACE_PROD}/g' kube-deploy-prod.yaml"
kubernetesDeploy configs: 'kube-deploy-prod.yaml', deleteResource: false, kubeconfigId: 'minikube', secretName: 'regcred', secretNamespace: 'boathouse-test'
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,7 @@ docker run \
sonarsource/sonar-scanner-cli
```

kubectl create secret docker-registry regcred --docker-server=registry.cn-hangzhou.aliyuncs.com --docker-username=boathouse216 --docker-password=devops@2021 --docker-email=info@idcf.io -n boathouse-test
kubectl create secret docker-registry regcred --docker-server=registry.cn-hangzhou.aliyuncs.com --docker-username=boathouse216 --docker-password=devops@2021 --docker-email=info@idcf.io -n boathouse-test


kubectl create secret docker-registry regcred --docker-server=registry.cn-hangzhou.aliyuncs.com --docker-username=boathouse216 --docker-password=devops@2021 --docker-email=info@idcf.io -n boathouse-prod
4 changes: 2 additions & 2 deletions kube-deploy.yaml → kube-deploy-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: boathouse-calculator
namespace: #{K8S_NAMESPACE_TEST}#
namespace: #{K8S_NAMESPACE}#
spec:
replicas: 1
selector:
Expand Down Expand Up @@ -38,7 +38,7 @@ apiVersion: v1
kind: Service
metadata:
name: boathouse-calculator
namespace: #{K8S_NAMESPACE_TEST}#
namespace: #{K8S_NAMESPACE}#
spec:
type: LoadBalancer
ports:
Expand Down
48 changes: 48 additions & 0 deletions kube-deploy-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: boathouse-calculator
namespace: #{K8S_NAMESPACE}#
spec:
replicas: 1
selector:
matchLabels:
app: boathouse-calculator
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
minReadySeconds: 5
template:
metadata:
labels:
app: boathouse-calculator
spec:
nodeSelector:
"beta.kubernetes.io/os": linux
containers:
- name: boathouse-calculator
image: #{REGISTRY_URL}#/#{REGISTRY_NS}#/boathouse-calculator:latest
ports:
- containerPort: 3000
resources:
requests:
cpu: 250m
limits:
cpu: 500m
imagePullSecrets:
- name: regcred
restartPolicy: Always
---
apiVersion: v1
kind: Service
metadata:
name: boathouse-calculator
namespace: #{K8S_NAMESPACE}#
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 3000
selector:
app: boathouse-calculator

0 comments on commit 13cbf98

Please sign in to comment.