chore: 参照后端配置,使用 kaniko 构建,添加 k8s 部署文件

This commit is contained in:
Agent
2026-03-23 13:27:55 +00:00
parent 63da0788f8
commit c4d83d18bb
3 changed files with 72 additions and 44 deletions

View File

@@ -1,9 +1,10 @@
kind: pipeline kind: pipeline
type: kubernetes type: kubernetes
clone:
disable: true
name: build-and-deploy-dev name: build-and-deploy-dev
service_account_name: drone-builder-sa
trigger: trigger:
event: event:
- push - push
@@ -11,50 +12,41 @@ trigger:
- dev - dev
steps: steps:
- name: dev-clone
image: ccr.ccs.tencentyun.com/violin/git-alpine:latest
settings:
username:
from_secret: git_username
password:
from_secret: git_password
- name: dev-install - name: dev-install
image: node:18-alpine image: ccr.ccs.tencentyun.com/violin/node:18-alpine
commands: commands:
- npm install - npm install
- name: dev-build - name: dev-build
image: node:18-alpine image: ccr.ccs.tencentyun.com/violin/node:18-alpine
commands: commands:
- npm run build:h5 - npm run build:h5
- name: dev-build-image - name: dev-build-image
image: ccr.ccs.tencentyun.com/violin/docker:linux-amd64 image: ccr.ccs.tencentyun.com/violin/drone-kaniko:latest
settings: settings:
repo: ccr.ccs.tencentyun.com/violin/todo-frontend repo: ccr.ccs.tencentyun.com/violin/todo-frontend
tags: tags:
- ${DRONE_COMMIT_SHA}
- latest - latest
username: - ${DRONE_COMMIT_SHA:0:8}
from_secret: registry_username dockerfile: Dockerfile
context: .
registry: ccr.ccs.tencentyun.com
username: 100024540033
password: password:
from_secret: registry_password from_secret: docker_password
- name: dev-deploy - name: dev-deploy
image: ccr.ccs.tencentyun.com/violin/kubectl:latest image: ccr.ccs.tencentyun.com/violin/kubectl:latest
cluster: kubernetes
namespace: drone
commands: commands:
- kubectl set image deployment/todo-frontend todo-frontend=ccr.ccs.tencentyun.com/violin/todo-frontend:${DRONE_COMMIT_SHA} -n drone - kubectl apply -f k8s/deployment.yaml
- kubectl rollout status deployment/todo-frontend -n drone
environment:
KUBECONFIG:
from_secret: kubeconfig
--- ---
kind: pipeline kind: pipeline
type: kubernetes type: kubernetes
clone:
disable: true
name: build-and-deploy-prod name: build-and-deploy-prod
trigger: trigger:
@@ -64,41 +56,33 @@ trigger:
- master - master
steps: steps:
- name: prod-clone
image: ccr.ccs.tencentyun.com/violin/git-alpine:latest
settings:
username:
from_secret: git_username
password:
from_secret: git_password
- name: prod-install - name: prod-install
image: node:18-alpine image: ccr.ccs.tencentyun.com/violin/node:18-alpine
commands: commands:
- npm install - npm install
- name: prod-build - name: prod-build
image: node:18-alpine image: ccr.ccs.tencentyun.com/violin/node:18-alpine
commands: commands:
- npm run build:h5 - npm run build:h5
- name: prod-build-image - name: prod-build-image
image: ccr.ccs.tencentyun.com/violin/docker:linux-amd64 image: ccr.ccs.tencentyun.com/violin/drone-kaniko:latest
settings: settings:
repo: ccr.ccs.tencentyun.com/violin/todo-frontend repo: ccr.ccs.tencentyun.com/violin/todo-frontend
tags: tags:
- ${DRONE_COMMIT_SHA}
- v1.0.0 - v1.0.0
username: dockerfile: Dockerfile
from_secret: registry_username context: .
registry: ccr.ccs.tencentyun.com
username: 100024540033
password: password:
from_secret: registry_password from_secret: docker_password
- name: prod-deploy - name: prod-deploy
image: ccr.ccs.tencentyun.com/violin/kubectl:latest image: ccr.ccs.tencentyun.com/violin/kubectl:latest
cluster: kubernetes
namespace: drone
commands: commands:
- kubectl set image deployment/todo-frontend todo-frontend=ccr.ccs.tencentyun.com/violin/todo-frontend:${DRONE_COMMIT_SHA} -n drone - kubectl set image deployment/todo-frontend todo-frontend=ccr.ccs.tencentyun.com/violin/todo-frontend:v1.0.0
- kubectl rollout status deployment/todo-frontend -n drone - kubectl rollout status deployment/todo-frontend
environment:
KUBECONFIG:
from_secret: kubeconfig

7
Dockerfile Normal file
View File

@@ -0,0 +1,7 @@
FROM ccr.ccs.tencentyun.com/violin/nginx:alpine
COPY dist/build/h5 /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

37
k8s/deployment.yaml Normal file
View File

@@ -0,0 +1,37 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: todo-frontend
namespace: drone
labels:
app: todo-frontend
spec:
replicas: 1
selector:
matchLabels:
app: todo-frontend
template:
metadata:
labels:
app: todo-frontend
spec:
imagePullSecrets:
- name: tencentyun-secret
containers:
- name: todo-frontend
image: ccr.ccs.tencentyun.com/violin/todo-frontend:latest
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: todo-frontend
namespace: drone
spec:
selector:
app: todo-frontend
ports:
- port: 80
targetPort: 80
type: ClusterIP