Gitea+Drone(K8S CI/CD)2
先上pipelinekind: pipelinetype: kubernetesname: defaultsteps:- name: build packageimage: golang:1.17.8-alpine3.15commands:- export GO111MODULE=on- export GOPROXY=https://goproxy.cn- go get -d -v github.
·
先上pipeline
kind: pipeline
type: kubernetes
name: default
steps:
- name: build package
image: golang:1.17.8-alpine3.15
commands:
- export GO111MODULE=on
- export GOPROXY=https://goproxy.cn
- go get -d -v github.com/gin-gonic/gin
- go get -d -v github.com/shirou/gopsutil/host
- go mod init app
- go mod tidy
- CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .
- name: docker build push
image: plugins/docker
settings:
dockerfile: Dockerfile
repo: registry-intl.cn-shenzhen.aliyuncs.com/sztest/szz
registry: registry-intl.cn-shenzhen.aliyuncs.com
tags: [ "${DRONE_COMMIT_SHA:0:7}"]
username:
from_secret: docker_username
password:
from_secret: docker_password
- name: deploy
image: bh90210/dron8s:latest
#image: registry.cn-shenzhen.aliyuncs.com/jbjb/csi:bh90210
settings:
yaml: ./test.yaml
image_tag: [ "${DRONE_COMMIT_SHA:0:7}"]
kubeconfig:
from_secret: kubeconfig
when:
event: push
branch: master
---
kind: secret
name: kubeconfig
get:
path: dron8s
name: kubeconfig
k8s的yaml模板
containers:
- name: nginx
image: registry-intl.cn-shenzhen.aliyuncs.com/sztest/szz:{{.image_tag}}
resources:
requests:
cpu: 100m
memory: 100Mi
ports:
- containerPort: 8000
变量, 必须是小写,用法:{{.image_tag}}
docker 部分
- name: docker build push
image: plugins/docker
settings:
dockerfile: Dockerfile
repo: registry-intl.cn-shenzhen.aliyuncs.com/sztest/szz
registry: registry-intl.cn-shenzhen.aliyuncs.com
tags: [ "${DRONE_COMMIT_SHA:0:7}"]
username:
from_secret: docker_username
password:
from_secret: docker_password
指定你的dockerfile也可以加路径如下:
dockerfile: /path/Dockerfile
tags获取随机使用DRONE_COMMIT_SHA内置变量只要7位数做镜像名
tags: [ "${DRONE_COMMIT_SHA:0:7}"]
可以通过GUI来完成变量或者通过k8s的secrets来管理
username:
from_secret: docker_username
password:
from_secret: docker_password
deploy部分
- name: deploy
image: bh90210/dron8s:latest
#image: registry.cn-shenzhen.aliyuncs.com/jbjb/csi:bh90210
settings:
yaml: ./test.yaml
image_tag: [ "${DRONE_COMMIT_SHA:0:7}"]
kubeconfig:
from_secret: kubeconfig
when:
event: push
branch: master
kubeconfig也可以通过GUI管理
也可以通过k8s管理,使用需要手动创建资源以允许 Drone 的群集编辑访问权限。clusterrolebinding
如果您选择手动安装,则必须将 --serviceaccount 和/或 --namespace 标志替换为您使用的正确服务/命名空间名称(–serviceaccount=drone-ci:default --namespace=default)。
kubectl create clusterrolebinding dron8s --clusterrole=edit --serviceaccount=drone:default --namespace=drone
kubectl create secret generic dron8s --from-file=kubeconfig=$HOME/.kube/config
个人比较喜欢drone集成因为功能很强大,社区工具链丰富比较实用可以参考以下连接,强力推荐drone CI/CD一条龙服务
https://plugins.drone.io/
更多推荐
已为社区贡献82条内容
所有评论(0)