update
continuous-integration/drone/push Build is passing Details

master
icechen 2022-01-04 00:21:33 +08:00
parent 7074461935
commit c242cdbd30
7 changed files with 494 additions and 60 deletions

View File

@ -29,15 +29,19 @@ type (
ApiList []Api ApiList []Api
Api struct { Api struct {
Name string `json:"name" yaml:"name"` Name string `json:"name" yaml:"name"`
AliasName string `json:"alias_name" yaml:"aliasName"`
Root string `json:"root" yaml:"root"` Root string `json:"root" yaml:"root"`
Type string `json:"type" yaml:"type"` Type string `json:"type" yaml:"type"`
Port string `json:"port" yaml:"port"` Port string `json:"port" yaml:"port"`
Host string `json:"host" yaml:"host"`
Path string `json:"path" yaml:"path"`
} }
) )
type ( type (
ServiceList []Service ServiceList []Service
Service struct { Service struct {
Name string `json:"name" yaml:"name"` Name string `json:"name" yaml:"name"`
AliasName string `json:"alias_name" yaml:"aliasName"`
Root string `json:"root" yaml:"root"` Root string `json:"root" yaml:"root"`
Type string `json:"type" yaml:"type"` Type string `json:"type" yaml:"type"`
Port string `json:"port" yaml:"port"` Port string `json:"port" yaml:"port"`

View File

@ -14,8 +14,11 @@ const TypeGolang = "golang"
type GoApiHandler struct { type GoApiHandler struct {
NameSpace string NameSpace string
Name string Name string
AliasName string
Root string Root string
Port string Port string
Host string
Path string
ServiceEnv map[string]string ServiceEnv map[string]string
DeployEnv consts.Env DeployEnv consts.Env
} }

View File

@ -15,20 +15,140 @@ steps:
from_secret: reg_password from_secret: reg_password
repo: reg.icechen.cn/{{ .NameSpace }}/api-{{ .Name }} repo: reg.icechen.cn/{{ .NameSpace }}/api-{{ .Name }}
registry: reg.icechen.cn registry: reg.icechen.cn
tags: ${DRONE_COMMIT:0:8} tags:
- ${DRONE_TAG}
- latest
dockerfile: ./{{ .Root }}/Dockerfile dockerfile: ./{{ .Root }}/Dockerfile
- name: run - name: deploy
image: docker image: sinlead/drone-kubectl
volumes: settings:
- name: docker kubernetes_server:
path: /var/run/docker.sock from_secret: kubernetes_server
kubernetes_cert:
from_secret: kubernetes_cert
kubernetes_token:
from_secret: kubernetes_token
commands: commands:
- docker rm -f {{ .NameSpace }}-api-{{ .Name }} - echo ` + ApiProductionDeploy + ` | kubectl apply -f -
- docker run -d --name="{{ .NameSpace }}-api-{{ .Name }}" --network="nginx-net"{{ range $key, $value := .ServiceEnv }} --env {{ $key }}={{ $value }} {{ end }}reg.icechen.cn/{{ .NameSpace }}/api-{{ .Name }}:${DRONE_COMMIT:0:8} # - kubectl wait --for=condition=Ready --timeout=300s -f deploy/deployment.yaml
`
volumes:
- name: docker const ApiProductionDeploy = `kind: Deployment
host: apiVersion: apps/v1
path: /var/run/docker.sock metadata:
name: api-{{ .Name }}
namespace: {{ .NameSpace }}
labels:
app: api-{{ .Name }}
annotations:
kubesphere.io/alias-name: {{ .AliasName }}
kubesphere.io/creator: drone
spec:
replicas: 1
selector:
matchLabels:
app: api-{{ .Name }}
template:
metadata:
creationTimestamp: null
labels:
app: api-{{ .Name }}
spec:
volumes:
- name: host-time
hostPath:
path: /etc/localtime
type: ''
containers:
- image: 'reg.icechen.cn/{{ .NameSpace }}/api-{{ .Name }}:${DRONE_TAG}'
ports:
- containerPort: {{ .Port }}
protocol: TCP
envFrom:
- configMapRef:
name: service
env:
- name: endpoints
value: 'etcd:2379'
resources:
limits:
cpu: 200m
memory: 1000Mi
requests:
cpu: 50m
memory: 200Mi
volumeMounts:
- name: host-time
readOnly: true
mountPath: /etc/localtime
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: IfNotPresent
restartPolicy: Always
terminationGracePeriodSeconds: 30
dnsPolicy: ClusterFirst
serviceAccountName: default
serviceAccount: default
securityContext: {}
imagePullSecrets:
- name: registry-secret
schedulerName: default-scheduler
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 25%
maxSurge: 25%
revisionHistoryLimit: 10
progressDeadlineSeconds: 600
---
kind: Service
apiVersion: v1
metadata:
name: api-{{ .Name }}
namespace: {{ .NameSpace }}
labels:
app: api-{{ .Name }}
spec:
ports:
- name: http-api-{{ .Name }}
protocol: TCP
port: 80
targetPort: {{ .Port }}
selector:
app: api-{{ .Name }}
type: ClusterIP
sessionAffinity: None
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
{{ if and .Host .Path }}
---
kind: Ingress
apiVersion: networking.k8s.io/v1
metadata:
name: api-{{ .Name }}
namespace: {{ .NameSpace }}
annotations:
kubesphere.io/creator: drone
nginx.ingress.kubernetes.io/enable-cors: 'true'
nginx.ingress.kubernetes.io/rewrite-target: /$1
nginx.ingress.kubernetes.io/use-regex: 'true'
spec:
rules:
- host: {{ .Host }}
http:
paths:
- path: {{ .Path }}
pathType: ImplementationSpecific
backend:
service:
name: api-{{ .Name }}
port:
number: 80
{{ end }}
` `

View File

@ -15,20 +15,140 @@ steps:
from_secret: reg_password from_secret: reg_password
repo: reg.icechen.cn/{{ .NameSpace }}/api-{{ .Name }} repo: reg.icechen.cn/{{ .NameSpace }}/api-{{ .Name }}
registry: reg.icechen.cn registry: reg.icechen.cn
tags: ${DRONE_COMMIT:0:8} tags:
- ${DRONE_COMMIT:0:8}
- latest
dockerfile: ./{{ .Root }}/Dockerfile dockerfile: ./{{ .Root }}/Dockerfile
- name: run - name: deploy
image: docker image: sinlead/drone-kubectl
volumes: settings:
- name: docker kubernetes_server:
path: /var/run/docker.sock from_secret: kubernetes_server_test
kubernetes_cert:
from_secret: kubernetes_cert_test
kubernetes_token:
from_secret: kubernetes_token_test
commands: commands:
- docker rm -f {{ .NameSpace }}-api-{{ .Name }} - echo ` + ApiTestDeploy + ` | kubectl apply -f -
- docker run -d --name="{{ .NameSpace }}-api-{{ .Name }}" --network="nginx-net"{{ range $key, $value := .ServiceEnv }} --env {{ $key }}={{ $value }} {{ end }}reg.icechen.cn/{{ .NameSpace }}/api-{{ .Name }}:${DRONE_COMMIT:0:8} # - kubectl wait --for=condition=Ready --timeout=300s -f deploy/deployment.yaml
`
volumes:
- name: docker const ApiTestDeploy = `kind: Deployment
host: apiVersion: apps/v1
path: /var/run/docker.sock metadata:
name: api-{{ .Name }}-test
namespace: {{ .NameSpace }}
labels:
app: api-{{ .Name }}-test
annotations:
kubesphere.io/alias-name: {{ .AliasName }}
kubesphere.io/creator: drone
spec:
replicas: 1
selector:
matchLabels:
app: api-{{ .Name }}-test
template:
metadata:
creationTimestamp: null
labels:
app: api-{{ .Name }}-test
spec:
volumes:
- name: host-time
hostPath:
path: /etc/localtime
type: ''
containers:
- image: 'reg.icechen.cn/{{ .NameSpace }}/api-{{ .Name }}:${DRONE_COMMIT:0:8}'
ports:
- containerPort: {{ .Port }}
protocol: TCP
envFrom:
- configMapRef:
name: service
env:
- name: endpoints
value: 'etcd:2379'
resources:
limits:
cpu: 200m
memory: 1000Mi
requests:
cpu: 50m
memory: 200Mi
volumeMounts:
- name: host-time
readOnly: true
mountPath: /etc/localtime
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: IfNotPresent
restartPolicy: Always
terminationGracePeriodSeconds: 30
dnsPolicy: ClusterFirst
serviceAccountName: default
serviceAccount: default
securityContext: {}
imagePullSecrets:
- name: registry-secret
schedulerName: default-scheduler
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 25%
maxSurge: 25%
revisionHistoryLimit: 10
progressDeadlineSeconds: 600
---
kind: Service
apiVersion: v1
metadata:
name: api-{{ .Name }}-test
namespace: {{ .NameSpace }}
labels:
app: api-{{ .Name }}-test
spec:
ports:
- name: http-api-{{ .Name }}-test
protocol: TCP
port: 80
targetPort: {{ .Port }}
selector:
app: api-{{ .Name }}-test
type: ClusterIP
sessionAffinity: None
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
{{ if and .Host .Path }}
---
kind: Ingress
apiVersion: networking.k8s.io/v1
metadata:
name: api-{{ .Name }}-test
namespace: {{ .NameSpace }}
annotations:
kubesphere.io/creator: drone
nginx.ingress.kubernetes.io/enable-cors: 'true'
nginx.ingress.kubernetes.io/rewrite-target: /$1
nginx.ingress.kubernetes.io/use-regex: 'true'
spec:
rules:
- host: t{{ .Host }}
http:
paths:
- path: {{ .Path }}
pathType: ImplementationSpecific
backend:
service:
name: api-{{ .Name }}-test
port:
number: 80
{{ end }}
` `

View File

@ -15,20 +15,113 @@ steps:
from_secret: reg_password from_secret: reg_password
repo: reg.icechen.cn/{{ .NameSpace }}/service-{{ .Name }} repo: reg.icechen.cn/{{ .NameSpace }}/service-{{ .Name }}
registry: reg.icechen.cn registry: reg.icechen.cn
tags: ${DRONE_COMMIT:0:8} tags:
- ${DRONE_TAG}
- latest
dockerfile: ./{{ .Root }}/Dockerfile dockerfile: ./{{ .Root }}/Dockerfile
- name: run - name: deploy
image: docker image: sinlead/drone-kubectl
volumes: settings:
- name: docker kubernetes_server:
path: /var/run/docker.sock from_secret: kubernetes_server
kubernetes_cert:
from_secret: kubernetes_cert
kubernetes_token:
from_secret: kubernetes_token
commands: commands:
- docker rm -f {{ .NameSpace }}-service-{{ .Name }} - echo ` + ServiceProductionDeploy + ` | kubectl apply -f -
- docker run -d --name="{{ .NameSpace }}-service-{{ .Name }}" --network="nginx-net"{{ range $key, $value := .ServiceEnv }} --env {{ $key }}={{ $value }} {{ end }}reg.icechen.cn/{{ .NameSpace }}/service-{{ .Name }}:${DRONE_COMMIT:0:8} # - kubectl wait --for=condition=Ready --timeout=300s -f deploy/deployment.yaml
`
volumes:
- name: docker const ServiceProductionDeploy = `kind: Deployment
host: apiVersion: apps/v1
path: /var/run/docker.sock metadata:
name: service-{{ .Name }}
namespace: {{ .NameSpace }}
labels:
app: service-{{ .Name }}
annotations:
kubesphere.io/alias-name: {{ .AliasName }}
kubesphere.io/creator: drone
spec:
replicas: 1
selector:
matchLabels:
app: service-{{ .Name }}
template:
metadata:
creationTimestamp: null
labels:
app: service-{{ .Name }}
spec:
volumes:
- name: host-time
hostPath:
path: /etc/localtime
type: ''
containers:
- image: 'reg.icechen.cn/{{ .NameSpace }}/service-{{ .Name }}:${DRONE_TAG}'
ports:
- containerPort: {{ .Port }}
protocol: TCP
envFrom:
- configMapRef:
name: service
env:
- name: endpoints
value: 'etcd:2379'
resources:
limits:
cpu: 200m
memory: 1000Mi
requests:
cpu: 50m
memory: 200Mi
volumeMounts:
- name: host-time
readOnly: true
mountPath: /etc/localtime
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: IfNotPresent
restartPolicy: Always
terminationGracePeriodSeconds: 30
dnsPolicy: ClusterFirst
serviceAccountName: default
serviceAccount: default
securityContext: {}
imagePullSecrets:
- name: registry-secret
schedulerName: default-scheduler
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 25%
maxSurge: 25%
revisionHistoryLimit: 10
progressDeadlineSeconds: 600
---
kind: Service
apiVersion: v1
metadata:
name: service-{{ .Name }}
namespace: {{ .NameSpace }}
labels:
app: service-{{ .Name }}
spec:
ports:
- name: http-service-{{ .Name }}
protocol: TCP
port: 80
targetPort: {{ .Port }}
selector:
app: service-{{ .Name }}
type: ClusterIP
sessionAffinity: None
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
` `

View File

@ -15,20 +15,113 @@ steps:
from_secret: reg_password from_secret: reg_password
repo: reg.icechen.cn/{{ .NameSpace }}/service-{{ .Name }} repo: reg.icechen.cn/{{ .NameSpace }}/service-{{ .Name }}
registry: reg.icechen.cn registry: reg.icechen.cn
tags: ${DRONE_COMMIT:0:8} tags:
- ${DRONE_COMMIT:0:8}
- latest
dockerfile: ./{{ .Root }}/Dockerfile dockerfile: ./{{ .Root }}/Dockerfile
- name: run - name: deploy
image: docker image: sinlead/drone-kubectl
volumes: settings:
- name: docker kubernetes_server:
path: /var/run/docker.sock from_secret: kubernetes_server_test
kubernetes_cert:
from_secret: kubernetes_cert_test
kubernetes_token:
from_secret: kubernetes_token_test
commands: commands:
- docker rm -f {{ .NameSpace }}-service-{{ .Name }} - echo ` + ServiceTestDeploy + ` | kubectl apply -f -
- docker run -d --name="{{ .NameSpace }}-service-{{ .Name }}" --network="nginx-net"{{ range $key, $value := .ServiceEnv }} --env {{ $key }}={{ $value }} {{ end }}reg.icechen.cn/{{ .NameSpace }}/service-{{ .Name }}:${DRONE_COMMIT:0:8} # - kubectl wait --for=condition=Ready --timeout=300s -f deploy/deployment.yaml
`
volumes:
- name: docker const ServiceTestDeploy = `kind: Deployment
host: apiVersion: apps/v1
path: /var/run/docker.sock metadata:
name: service-{{ .Name }}-test
namespace: {{ .NameSpace }}
labels:
app: service-{{ .Name }}-test
annotations:
kubesphere.io/alias-name: {{ .AliasName }}
kubesphere.io/creator: drone
spec:
replicas: 1
selector:
matchLabels:
app: service-{{ .Name }}-test
template:
metadata:
creationTimestamp: null
labels:
app: service-{{ .Name }}-test
spec:
volumes:
- name: host-time
hostPath:
path: /etc/localtime
type: ''
containers:
- image: 'reg.icechen.cn/{{ .NameSpace }}/service-{{ .Name }}:${DRONE_COMMIT:0:8}'
ports:
- containerPort: {{ .Port }}
protocol: TCP
envFrom:
- configMapRef:
name: service
env:
- name: endpoints
value: 'etcd:2379'
resources:
limits:
cpu: 200m
memory: 1000Mi
requests:
cpu: 50m
memory: 200Mi
volumeMounts:
- name: host-time
readOnly: true
mountPath: /etc/localtime
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: IfNotPresent
restartPolicy: Always
terminationGracePeriodSeconds: 30
dnsPolicy: ClusterFirst
serviceAccountName: default
serviceAccount: default
securityContext: {}
imagePullSecrets:
- name: registry-secret
schedulerName: default-scheduler
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 25%
maxSurge: 25%
revisionHistoryLimit: 10
progressDeadlineSeconds: 600
---
kind: Service
apiVersion: v1
metadata:
name: service-{{ .Name }}-test
namespace: {{ .NameSpace }}
labels:
app: service-{{ .Name }}-test
spec:
ports:
- name: http-service-{{ .Name }}-test
protocol: TCP
port: 80
targetPort: {{ .Port }}
selector:
app: service-{{ .Name }}-test
type: ClusterIP
sessionAffinity: None
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
` `

View File

@ -12,6 +12,7 @@ import (
type GoServiceHandler struct { type GoServiceHandler struct {
NameSpace string NameSpace string
Name string Name string
AliasName string
Root string Root string
Port string Port string
ServiceEnv map[string]string ServiceEnv map[string]string