Add K8s deployment in CI/CD
This commit is contained in:
83
.drone.yml
83
.drone.yml
@@ -1,11 +1,13 @@
|
|||||||
kind: pipeline
|
kind: pipeline
|
||||||
type: docker
|
type: docker
|
||||||
|
|
||||||
name: build-and-push
|
name: build-and-deploy-dev
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
event:
|
event:
|
||||||
- push
|
- push
|
||||||
|
branch:
|
||||||
|
- dev
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: restore-cache
|
- name: restore-cache
|
||||||
@@ -29,18 +31,87 @@ steps:
|
|||||||
- name: build-image
|
- name: build-image
|
||||||
image: plugins/docker
|
image: plugins/docker
|
||||||
settings:
|
settings:
|
||||||
repo: ccr.ccs.tencentyun.com/todo-{{ if eq .Branch "master" }}prod{{ else }}test{{ end }}/todo-frontend
|
repo: ccr.ccs.tencentyun.com/todo-test/todo-frontend
|
||||||
tags:
|
tags:
|
||||||
- {{ .Commit SHA }}
|
- {{ .Commit SHA }}
|
||||||
- {{ if eq .Branch "master" }}v1.0.0{{ else }}latest{{ end }}
|
- latest
|
||||||
username:
|
username:
|
||||||
from_secret: registry_username
|
from_secret: registry_username
|
||||||
password:
|
password:
|
||||||
from_secret: registry_password
|
from_secret: registry_password
|
||||||
|
|
||||||
|
- name: deploy-to-k8s
|
||||||
|
image: bitnami/kubectl:latest
|
||||||
|
commands:
|
||||||
|
- kubectl set image deployment/todo-frontend todo-frontend=ccr.ccs.tencentyun.com/todo-test/todo-frontend:{{ .Commit SHA }} -n todo-test
|
||||||
|
- kubectl rollout status deployment/todo-frontend -n todo-test
|
||||||
|
environment:
|
||||||
|
KUBECONFIG:
|
||||||
|
from_secret: kubeconfig
|
||||||
when:
|
when:
|
||||||
branch:
|
status:
|
||||||
- master
|
- success
|
||||||
- dev
|
|
||||||
|
- name: rebuild-cache
|
||||||
|
rebuild_cache:
|
||||||
|
keys:
|
||||||
|
- npm-{{ .Environment.DRONE_REPO_NAME }}-{{ checksum "package.json" }}
|
||||||
|
- npm-{{ .Environment.DRONE_REPO_NAME }}-
|
||||||
|
|
||||||
|
---
|
||||||
|
kind: pipeline
|
||||||
|
type: docker
|
||||||
|
|
||||||
|
name: build-and-deploy-prod
|
||||||
|
|
||||||
|
trigger:
|
||||||
|
event:
|
||||||
|
- push
|
||||||
|
branch:
|
||||||
|
- master
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: restore-cache
|
||||||
|
restore_cache:
|
||||||
|
keys:
|
||||||
|
- npm-{{ .Environment.DRONE_REPO_NAME }}-{{ checksum "package.json" }}
|
||||||
|
- npm-{{ .Environment.DRONE_REPO_NAME }}-
|
||||||
|
|
||||||
|
- name: install
|
||||||
|
image: node:18-alpine
|
||||||
|
commands:
|
||||||
|
- npm install
|
||||||
|
cache_from:
|
||||||
|
- npm-{{ .Environment.DRONE_REPO_NAME }}-{{ checksum "package.json" }}
|
||||||
|
|
||||||
|
- name: build
|
||||||
|
image: node:18-alpine
|
||||||
|
commands:
|
||||||
|
- npm run build:h5
|
||||||
|
|
||||||
|
- name: build-image
|
||||||
|
image: plugins/docker
|
||||||
|
settings:
|
||||||
|
repo: ccr.ccs.tencentyun.com/todo-prod/todo-frontend
|
||||||
|
tags:
|
||||||
|
- {{ .Commit SHA }}
|
||||||
|
- v1.0.0
|
||||||
|
username:
|
||||||
|
from_secret: registry_username
|
||||||
|
password:
|
||||||
|
from_secret: registry_password
|
||||||
|
|
||||||
|
- name: deploy-to-k8s
|
||||||
|
image: bitnami/kubectl:latest
|
||||||
|
commands:
|
||||||
|
- kubectl set image deployment/todo-frontend todo-frontend=ccr.ccs.tencentyun.com/todo-prod/todo-frontend:{{ .Commit SHA }} -n todo-prod
|
||||||
|
- kubectl rollout status deployment/todo-frontend -n todo-prod
|
||||||
|
environment:
|
||||||
|
KUBECONFIG:
|
||||||
|
from_secret: kubeconfig
|
||||||
|
when:
|
||||||
|
status:
|
||||||
|
- success
|
||||||
|
|
||||||
- name: rebuild-cache
|
- name: rebuild-cache
|
||||||
rebuild_cache:
|
rebuild_cache:
|
||||||
|
|||||||
Reference in New Issue
Block a user