feat: Add CI/CD

This commit is contained in:
devad 2023-07-19 09:00:54 +08:00
parent 6fac561e9d
commit 8848bf608a
4 changed files with 218 additions and 8 deletions

100
.devops/未命名项目.yml Normal file
View File

@ -0,0 +1,100 @@
version: 2
name: 未命名项目
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-participant-ac"'
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-participant-ac.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-participant-ac"'
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-participant-ac"'
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

View File

@ -1,7 +1,22 @@
FROM alpine:3.16.2
WORKDIR /home
FROM golang:1.20.2-alpine3.17 AS builder
# 修改alpine源为上海交通大学
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
RUN go build -o /app/pcm-participant-ac /app/hpcac.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 && \
@ -9,12 +24,11 @@ RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.sjtug.sjtu.edu.cn/g' /etc/apk/repos
apk add --update tzdata && \
rm -rf /var/cache/apk/*
COPY pcm-ac /home/
COPY etc/hpcac.yaml /home/
COPY --from=builder /app/pcm-participant-ac .
COPY etc/hpcac.yaml .
ENV TZ=Asia/Shanghai
EXPOSE 2002
EXPOSE 2001
ENTRYPOINT ./pcm-ac -f hpcac.yaml
ENTRYPOINT ./pcm-participant-ac -f hpcac.yaml

View File

@ -0,0 +1,67 @@
kind: Deployment
apiVersion: apps/v1
metadata:
name: pcm-participant-ac-deployment
namespace: jcce-system
labels:
k8s-app: pcm-participant-ac
spec:
replicas: 1
selector:
matchLabels:
k8s-app: pcm-participant-ac
template:
metadata:
name: pcm-participant-ac
labels:
k8s-app: pcm-participant-ac
spec:
hostAliases:
- hostnames:
- nacos.jcce.dev
ip: nacos_host
imagePullSecrets:
- name: secret_name
containers:
- name: pcm-participant-ac
image: image_name
resources: {}
imagePullPolicy: Always
securityContext:
privileged: false
procMount: Default
ports:
- containerPort: 80
volumeMounts: []
volumes: []
restartPolicy: Always
terminationGracePeriodSeconds: 30
dnsPolicy: ClusterFirst
securityContext: {}
schedulerName: default-scheduler
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 25%
maxSurge: 25%
revisionHistoryLimit: 10
progressDeadlineSeconds: 600
---
apiVersion: v1
kind: Service
metadata:
namespace: jcce-system
name: pcm-participant-ac-service
labels:
k8s-service: pcm-participant-ac
spec:
selector:
k8s-app: pcm-participant-ac
ports:
- name: web
protocol: TCP
port: 2001
targetPort: 2001
type: ClusterIP