Drone k8s自动化部署java应用
Drone k8s自动化部署java应用
主要是配置的案例,方便大家作为参考
kind: pipeline
type: docker
name: default
steps:
- name: build
pull: if-not-exists
image: maven:3.8.6-jdk-8-slim
volumes:
- name: mavenRep
path: /root/.m2
commands:
- echo ${DRONE_BRANCH}
- mvn -pl ${project} -am package -DskipTests=true
- ls -l ${project}/target
- name: image
pull: if-not-exists
image: plugins/docker
volumes:
- name: dockerSock
path: /var/run/docker.sock
settings:
insecure: true
registry: 192.168.2.41:8082
mirror: https://dkwe3jow.mirror.aliyuncs.com
build_args: "JAR_FILE=${project}/target/${project}.jar"
username:
from_secret: registry_nexus_username
password:
from_secret: registry_nexus_password
repo: 192.168.2.41:8082/qunfeng/${project}
tags:
- ${DRONE_BUILD_NUMBER}
- latest
- name: deploy-to-k8s
pull: if-not-exists
image: registry.cn-hangzhou.aliyuncs.com/sanchar/kubectl:v1.20.1
volumes:
- name: kube
path: /root/.kube
commands:
# - kubectl --kubeconfig /root/.kube/config rollout restart deployment ${project} -n qunfeng-${DRONE_BRANCH}
- kubectl --kubeconfig /root/.kube/config set image deployment/${project} *='192.168.2.41:8082/qunfeng/${project}:${DRONE_BUILD_NUMBER}' -n qunfeng-${DRONE_BRANCH}
# - kubectl set image deployment/qunfeng-tech-admin container*='192.168.2.41:8082/qunfeng/qunfeng-tech-admin:104' -n qunfeng-dev
volumes:
- name: mavenRep
host:
path: /.m2
- name: kube
host:
path: /root/.kube
- name: dockerSock
host:
path: /var/run/docker.sock
#trigger:
# branch:
# - dev
# - feature-ci
# event:
# - push
trigger:
# event:
# include:
# - push
# - pull_request
branch:
- prod
- test
- dev