otto
2 years ago
12 changed files with 155 additions and 121 deletions
@ -1,64 +0,0 @@
|
||||
def buildService(serverName){ |
||||
docker.withRegistry('https://registry.internal.jumaiyx.cn', 'docker-registry-internal-backend') { |
||||
def img = docker.build("jm/$serverName:${env.BUILD_ID}",".") |
||||
img.push() |
||||
} |
||||
} |
||||
|
||||
pipeline { |
||||
agent any |
||||
|
||||
environment { |
||||
// 服务名 |
||||
SERVER_NAME = 'feedback' |
||||
// 镜像名称,对应K8S_FILE里面Deployment.containers的name |
||||
IMAGE_NAME = 'feedback' |
||||
// git路径 |
||||
GIT_URL = 'http://git.gz.internal.jumaiyx.cn/job/room-server-clear.git' |
||||
// 分支 |
||||
GIT_BRANCH = '*/master' |
||||
// kubectl执行文件 |
||||
K8S_FILE = 'feedback-dev.yaml' |
||||
// k8s deployment名称,对应K8S_FILE里面Deployment的name |
||||
K8S_DEPLOYMENT = 'feedback-deployment' |
||||
} |
||||
|
||||
stages { |
||||
stage('git代码拉取') { |
||||
steps { |
||||
checkout([$class: 'GitSCM', branches: [[name: "${env.GIT_BRANCH}"]], extensions: [], userRemoteConfigs: [[url: "${env.GIT_URL}"]]]) |
||||
echo 'git代码拉取 成功' |
||||
} |
||||
} |
||||
stage('docker镜像打包') { |
||||
steps { |
||||
echo "镜像版本:${env.BUILD_ID}" |
||||
buildService("${env.SERVER_NAME}") |
||||
echo 'docker镜像打包' |
||||
} |
||||
} |
||||
stage('传入k8s-master') { |
||||
steps { |
||||
//sshPublisher(publishers: [sshPublisherDesc(configName: 'k8s', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: '', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: '', sourceFiles: "${env.K8S_FILE}")], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)]) |
||||
echo '将yaml传入k8s-master' |
||||
} |
||||
} |
||||
stage('部署服务') { |
||||
steps { |
||||
//sh "ssh root@192.168.1.156 kubectl apply -f /usr/local/k8s/${env.K8S_FILE}" |
||||
echo '部署服务' |
||||
//sh '''if if (( ${env.BUILD_ID} == 1 )) |
||||
//then |
||||
// ssh root@192.168.1.156 kubectl apply -f /usr/local/k8s/${env.K8S_FILE} |
||||
// echo '部署服务' |
||||
//fi''' |
||||
} |
||||
} |
||||
stage('更新image') { |
||||
steps { |
||||
sh "ssh root@192.168.1.156 kubectl set image Deployment/${env.K8S_DEPLOYMENT} ${env.IMAGE_NAME}=registry.internal.jumaiyx.cn/jm/${env.SERVER_NAME}:${env.BUILD_ID} -n dev" |
||||
echo '部署服务' |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,44 +1,16 @@
|
||||
apiVersion: apps/v1 |
||||
kind: Deployment |
||||
apiVersion: batch/v1 |
||||
kind: Job |
||||
metadata: |
||||
name: feedback-deployment |
||||
name: room-hot-compute-job |
||||
namespace: dev |
||||
labels: |
||||
app: feedback |
||||
spec: |
||||
replicas: 2 # 节点资源 |
||||
selector: |
||||
matchLabels: |
||||
app: feedback |
||||
ttlSecondsAfterFinished: 10 |
||||
activeDeadlineSeconds: 10 |
||||
template: |
||||
metadata: # 资源的元数据/属性 |
||||
labels: # 设定资源的标签 |
||||
app: feedback |
||||
spec: |
||||
containers: |
||||
- image: registry.internal.jumaiyx.cn/jm/feedback:1 # 自动化版本往后配置 |
||||
name: feedback |
||||
imagePullPolicy: Always |
||||
ports: |
||||
- name: grpc |
||||
containerPort: 9000 |
||||
protocol: TCP |
||||
- name: room-hot-compute-job |
||||
image: registry.internal.jumaiyx.cn/job/room-hot-compute:v1.0.0 |
||||
restartPolicy: Never |
||||
imagePullSecrets: |
||||
- name: registry-harbor |
||||
--- |
||||
apiVersion: v1 |
||||
kind: Service |
||||
metadata: |
||||
name: feedback-service # 改名字对应服务发现serviceName |
||||
namespace: dev |
||||
labels: |
||||
name: feedback |
||||
spec: |
||||
type: ClusterIP |
||||
ports: |
||||
- name: grpc |
||||
port: 9000 |
||||
targetPort: grpc |
||||
protocol: TCP |
||||
selector: |
||||
app: feedback |
@ -0,0 +1,19 @@
|
||||
apiVersion: v1 |
||||
clusters: |
||||
- cluster: |
||||
certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUN5RENDQWJDZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFWTVJNd0VRWURWUVFERXdwcmRXSmwKY201bGRHVnpNQjRYRFRJeU1Ea3lOekF4TXpRek9Wb1hEVE15TURreU5EQXhNelF6T1Zvd0ZURVRNQkVHQTFVRQpBeE1LYTNWaVpYSnVaWFJsY3pDQ0FTSXdEUVlKS29aSWh2Y05BUUVCQlFBRGdnRVBBRENDQVFvQ2dnRUJBS1VGClBZdjVCdlRYLzlXdjZhWU9vWmM5cUtnclVnQjRzZFBWYVVJMFFBRlV1cUhEeE1RMGdBc1RBL2xtUkxZL0NJRm8KS21pOHNYR1J4Wmh2Lytqd01iKzB6U0oxNzd5RVpGSmQyZlQ3QkRkRHdJVkdNRnVUYytUN2xnNzdLVXFENHBSMgp1Mm1hcmRuWGs3cmtzNUR0alg1QUdhdW45VWRiMmRrb3orYmc5aC9XWTB6NjczUysvcVBnUzBER1o3bUtUTm5zCjdQaXdYbDV2MFNqUDM0ejRNRjAxU0g1Y3RxQm12OUhUOERvL0pMRjlkNUVaaGtPWlBuL1RiTjZqSGRKenZqTzUKbjU4T1ZQQ3VKUGhrbm1VUE1pZDJISU1ncEdqMUN3NWJYQXdDZ0RmeVpuNG15WEJ6eU0wb0FSazBYbUd3QXpWegpkQ0g4d2ZGL2lPWi81SGpZaGswQ0F3RUFBYU1qTUNFd0RnWURWUjBQQVFIL0JBUURBZ0trTUE4R0ExVWRFd0VCCi93UUZNQU1CQWY4d0RRWUpLb1pJaHZjTkFRRUxCUUFEZ2dFQkFBRlJRZEdnaENaNUFqckFidjJOenUvUzJ2cXAKRGQ3Z3FJUytXYVdTVDNoUXRYTjl2UUpiN3dGWktJb3l6Y3hZOUtOeldjT3Z5V05UZnliK2Z4dFI3RHJpRDV6WApUWngyZWdZSlN3R3Y3T0hPU0VGVHpTSXBRTlBLNURhejZ4b0ZsUE85M1lyZ1o1VTd0bVlRN3FTOUZXV1VWR3hZCk42TFpjbEtrYTM4MEFZRzd2TlZZNFdacHZDVG9Ed2xsb2JMOE85WVdWdmp2TGw1TDAwL201MDNNZTViREEydVEKSjdPa1dENGtiL2Rob0paQjdaOWZId0tWaTgxYUkxNm9ERlAwbTR5YWQvckZBS3FHUlcxdVpLTXNYK29JL0ttVApVcHp0QStzSXhZZXlBK1VaSXJoN1NjSkZ3amVHdE1YUkJIM0RRUzRZc05SdHkxUnZjUnJXSk1uU3Z1MD0KLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo= |
||||
server: https://192.168.1.156:6443 |
||||
name: kubernetes |
||||
contexts: |
||||
- context: |
||||
cluster: kubernetes |
||||
user: kubernetes-admin |
||||
name: kubernetes-admin@kubernetes |
||||
current-context: kubernetes-admin@kubernetes |
||||
kind: Config |
||||
preferences: {} |
||||
users: |
||||
- name: kubernetes-admin |
||||
user: |
||||
client-certificate-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUM4akNDQWRxZ0F3SUJBZ0lJTFV6blJtKzZqUkV3RFFZSktvWklodmNOQVFFTEJRQXdGVEVUTUJFR0ExVUUKQXhNS2EzVmlaWEp1WlhSbGN6QWVGdzB5TWpBNU1qY3dNVE0wTXpsYUZ3MHlNekE1TWpjd01UTTBOREJhTURReApGekFWQmdOVkJBb1REbk41YzNSbGJUcHRZWE4wWlhKek1Sa3dGd1lEVlFRREV4QnJkV0psY201bGRHVnpMV0ZrCmJXbHVNSUlCSWpBTkJna3Foa2lHOXcwQkFRRUZBQU9DQVE4QU1JSUJDZ0tDQVFFQTNYOFZrc2x3N3AxQUF3aG4KbW5nRHU3NWRUUUpXUm1EN014a3ZPN0ZiWFFXVTVHUDg3bHpEV2pMeUt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TFid0pya3k3b3hKc0dackg1OUdGK3VTT3J0Ci0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0tCg== |
@ -0,0 +1,42 @@
|
||||
server: |
||||
name: room |
||||
http: |
||||
addr: 0.0.0.0:8000 |
||||
timeout: 30 |
||||
grpc: |
||||
addr: 0.0.0.0:9000 |
||||
timeout: 30 |
||||
data: |
||||
database: |
||||
source: "host=192.168.1.156 user=metachat password=metachat dbname=feedback port=15433 sslmode=disable TimeZone=Asia/Shanghai" |
||||
# source: postgresql://metachat:metachat@127.0.0.1:15432/room |
||||
redis: |
||||
addr: 192.168.1.156:16378 |
||||
password: MM5ZsXL0 |
||||
read_timeout: 1 |
||||
write_timeout: 1 |
||||
|
||||
etcd: |
||||
host: "127.0.0.1:20000" |
||||
|
||||
log: |
||||
level: "debug" |
||||
name: "room" |
||||
kafka: |
||||
addr: |
||||
- "127.0.0.1:9092" |
||||
amqp: |
||||
host: 192.168.1.156:5672 |
||||
username: jm |
||||
password: jm123456 |
||||
|
||||
id_encode: |
||||
uid: |
||||
salt: "test" |
||||
min_length: 8 |
||||
|
||||
rtctoken: |
||||
app_id: 6eeb2e6be9a141d1b0db920f36a5a9f3 |
||||
app_certificate: 80438856882e4563841d56f3cefeb763 |
||||
privilege_expiration: 3600 |
||||
token_expiration: 3600 |
@ -0,0 +1,59 @@
|
||||
package test |
||||
|
||||
import ( |
||||
"context" |
||||
k8sclient "git.gz.internal.jumaiyx.cn/pkg/k8s-client" |
||||
"git.gz.internal.jumaiyx.cn/pkg/log" |
||||
v1 "k8s.io/api/batch/v1" |
||||
corev1 "k8s.io/api/core/v1" |
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
||||
"testing" |
||||
) |
||||
|
||||
// pods=$(kubectl get pods --selector=job-name=room-hot-compute-job --output=jsonpath='{.items[*].metadata.name}')
|
||||
// echo $pods
|
||||
func TestCreateJob(t *testing.T) { |
||||
l := log.DefaultLogger() |
||||
job, err := k8sclient.NewJob(k8sclient.DevNamespace, l) |
||||
if err != nil { |
||||
t.Fatal(err) |
||||
} |
||||
ctx := context.TODO() |
||||
ttl := int32(60) |
||||
ttls := int64(60) |
||||
_, err = job.Create(ctx, &v1.Job{ |
||||
ObjectMeta: metav1.ObjectMeta{ |
||||
Name: "room-hot-compute-job", |
||||
Namespace: k8sclient.DevNamespace, |
||||
}, |
||||
Spec: v1.JobSpec{ |
||||
ActiveDeadlineSeconds: &ttls, |
||||
TTLSecondsAfterFinished: &ttl, |
||||
Template: corev1.PodTemplateSpec{ |
||||
ObjectMeta: metav1.ObjectMeta{ |
||||
Name: "room-hot-compute-job", |
||||
Labels: map[string]string{ |
||||
"app": "room-job", |
||||
}, |
||||
}, |
||||
Spec: corev1.PodSpec{ |
||||
RestartPolicy: corev1.RestartPolicyNever, |
||||
Containers: []corev1.Container{ |
||||
{ |
||||
Name: "room-hot-compute-job", |
||||
Image: "registry.internal.jumaiyx.cn/job/room-hot-compute:v1.0.0", |
||||
}, |
||||
}, |
||||
ImagePullSecrets: []corev1.LocalObjectReference{ |
||||
{ |
||||
Name: k8sclient.DockerRegistryHarbor, |
||||
}, |
||||
}, |
||||
}, |
||||
}, |
||||
}, |
||||
}) |
||||
if err != nil { |
||||
t.Fatal(err) |
||||
} |
||||
} |
Loading…
Reference in new issue