Adds ci/cd

Signed-off-by: devad <cossjie@foxmail.com>
This commit is contained in:
devad 2023-10-19 17:08:51 +08:00
parent 0d05cbe568
commit eb5369e82c
5 changed files with 172 additions and 11 deletions

100
.devops/dev.yml Normal file
View File

@ -0,0 +1,100 @@
version: 2
name: dev
description: ""
global:
concurrent: 1
param:
- ref: nacos_host
name: nacos_host
value: '"10.206.0.12"'
required: false
type: STRING
hidden: false
- ref: secret_name
name: ""
value: '"jcce-aliyuncs"'
required: false
type: STRING
hidden: false
- ref: project_name
name: ""
value: '"pcm-openstack"'
required: false
type: STRING
hidden: false
trigger:
webhook: gitlink@1.0.0
event:
- ref: create_tag
ruleset:
- param-ref: tag
operator: EQ
value: '""'
ruleset-operator: AND
workflow:
- ref: start
name: 开始
task: start
- ref: git_clone_0
name: git clone
task: git_clone@1.2.6
input:
remote_url: '"https://gitlink.org.cn/jcce-pcm/pcm-openstack.git"'
ref: '"refs/heads/master"'
commit_id: '""'
depth: 1
needs:
- start
- ref: docker_image_build_0
name: docker镜像构建
task: docker_image_build@1.6.0
input:
docker_username: ((dev.docker_user))
docker_password: ((dev.docker_password))
image_name: '"registry.cn-hangzhou.aliyuncs.com/jcce/pcm-openstack"'
image_tag: git_clone_0.commit_time
registry_address: '"registry.cn-hangzhou.aliyuncs.com"'
docker_build_path: git_clone_0.git_path
workspace: git_clone_0.git_path
image_clean: true
image_push: true
build_args: '""'
needs:
- shell_0
- ref: end
name: 结束
task: end
needs:
- kubectl_deploy_0
- ref: kubectl_deploy_0
name: kubectl部署资源
task: kubectl_deploy@1.1.0
input:
command: '"apply"'
resource_file_path: git_clone_0.git_path
certificate_authority_data: ((dev.k8s_cad))
server: '"https://119.45.100.73:6443"'
client_certificate_data: ((dev.k8s_ccd))
client_key_data: ((dev.k8s_ckd))
hosts: '""'
needs:
- docker_image_build_0
- ref: shell_0
name: shell
image: docker.jianmuhub.com/library/debian:buster-slim
env:
IMAGE_NAME: '"registry.cn-hangzhou.aliyuncs.com/jcce/pcm-openstack"'
IMAGE_TAG: git_clone_0.commit_time
SECRET_NAME: global.secret_name
NACOS_HOST: global.nacos_host
PROJECT_NAME: global.project_name
PROJECT_PATH: git_clone_0.git_path
script:
- cd ${PROJECT_PATH}
- sed -i "s#image_name#${IMAGE_NAME}:${IMAGE_TAG}#" ${PROJECT_NAME}.yaml
- sed -i "s#secret_name#${SECRET_NAME}#" ${PROJECT_NAME}.yaml
- sed -i "s#nacos_host#${NACOS_HOST}#" ${PROJECT_NAME}.yaml
- cat ${PROJECT_NAME}.yaml
needs:
- git_clone_0

29
.gitignore vendored Normal file
View File

@ -0,0 +1,29 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
coverage.txt
# Dependency directories (remove the comment below to include it)
vendor/
# buf for protobuf
buf.lock
# idea project
.idea/
.vscode/
# config file
configs/tenanter.yaml
log/
/go_build_gitlink_org_cn_JCCE_PCM

32
Dockerfile Normal file
View File

@ -0,0 +1,32 @@
FROM golang:1.20.2-alpine3.17 AS builder
WORKDIR /app
LABEL stage=gobuilder
ENV CGO_ENABLED 0
ENV GOARCH amd64
ENV GOPROXY https://goproxy.cn,direct
COPY . .
COPY etc/ /app/
RUN go mod download && go build -o pcm-openstack /app/pcmopenstack.go
FROM alpine:3.16.2
WORKDIR /app
#修改alpine源为上海交通大学
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.sjtug.sjtu.edu.cn/g' /etc/apk/repositories && \
apk update && \
apk upgrade && \
apk add --no-cache ca-certificates && update-ca-certificates && \
apk add --update tzdata && \
rm -rf /var/cache/apk/*
COPY --from=builder /app/pcm-openstack .
COPY etc/pcmopenstack.yaml .
ENV TZ=Asia/Shanghai
EXPOSE 2003
ENTRYPOINT ./pcm-participant-openstack -f pcmopenstack.yaml

View File

@ -3,7 +3,7 @@ def BUILD_NUMBER = "${env.BUILD_NUMBER}"
def label = "jenkins-${JOB_NAME}-${BUILD_NUMBER}-${UUID.randomUUID().toString()}" def label = "jenkins-${JOB_NAME}-${BUILD_NUMBER}-${UUID.randomUUID().toString()}"
def code_path = "./" def code_path = "./"
def project_name = "pcm-participant-openstack" def project_name = "pcm-openstack"
podTemplate(label: label, containers: [ podTemplate(label: label, containers: [
containerTemplate(name: 'golang', image: 'golang:1.20.2-alpine3.17', command: 'cat', ttyEnabled: true), containerTemplate(name: 'golang', image: 'golang:1.20.2-alpine3.17', command: 'cat', ttyEnabled: true),
@ -15,7 +15,7 @@ podTemplate(label: label, containers: [
node(label) { node(label) {
def imageEndpoint = "jcce/${project_name}" def imageEndpoint = "jcce/${project_name}"
stage('拉取代码') { stage('拉取代码') {
checkout scmGit(branches: [[name: "*/${branches}"]], extensions: [], userRemoteConfigs: [[credentialsId: 'gitlink-zj', url: 'https://gitlink.org.cn/jcce-pcm/pcm-participant-openstack.git']]) checkout scmGit(branches: [[name: "*/${branches}"]], extensions: [], userRemoteConfigs: [[credentialsId: 'gitlink-zj', url: 'https://gitlink.org.cn/jcce-pcm/pcm-openstack.git']])
echo "获取commit_id 作为镜像标签" echo "获取commit_id 作为镜像标签"
script { script {
env.imageTag = sh(returnStdout: true, script: 'git rev-parse --short HEAD').trim() env.imageTag = sh(returnStdout: true, script: 'git rev-parse --short HEAD').trim()

View File

@ -1,20 +1,20 @@
kind: Deployment kind: Deployment
apiVersion: apps/v1 apiVersion: apps/v1
metadata: metadata:
name: pcm-participant-openstack-deployment name: pcm-openstack-deployment
namespace: jcce-system namespace: jcce-system
labels: labels:
k8s-app: pcm-participant-openstack k8s-app: pcm-openstack
spec: spec:
replicas: 1 replicas: 1
selector: selector:
matchLabels: matchLabels:
k8s-app: pcm-participant-openstack k8s-app: pcm-openstack
template: template:
metadata: metadata:
name: pcm-participant-openstack name: pcm-openstack
labels: labels:
k8s-app: pcm-participant-openstack k8s-app: pcm-openstack
spec: spec:
hostAliases: hostAliases:
- hostnames: - hostnames:
@ -23,7 +23,7 @@ spec:
imagePullSecrets: imagePullSecrets:
- name: secret_name - name: secret_name
containers: containers:
- name: pcm-participant-openstack - name: pcm-openstack
image: image_name image: image_name
resources: {} resources: {}
imagePullPolicy: Always imagePullPolicy: Always
@ -53,12 +53,12 @@ apiVersion: v1
kind: Service kind: Service
metadata: metadata:
namespace: jcce-system namespace: jcce-system
name: pcm-participant-openstack-service name: pcm-openstack-service
labels: labels:
k8s-service: pcm-participant-openstack k8s-service: pcm-openstack
spec: spec:
selector: selector:
k8s-app: pcm-participant-openstack k8s-app: pcm-openstack
ports: ports:
- name: web - name: web
protocol: TCP protocol: TCP