diff --git a/.drone.yml b/.drone.yml index 4f0490d..28b69d6 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,9 +1,10 @@ kind: pipeline type: kubernetes -clone: - disable: true + name: build-and-deploy-dev +service_account_name: drone-builder-sa + trigger: event: - push @@ -11,50 +12,41 @@ trigger: - dev 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 - image: node:18-alpine + image: ccr.ccs.tencentyun.com/violin/node:18-alpine commands: - npm install - name: dev-build - image: node:18-alpine + image: ccr.ccs.tencentyun.com/violin/node:18-alpine commands: - npm run build:h5 - name: dev-build-image - image: ccr.ccs.tencentyun.com/violin/docker:linux-amd64 + image: ccr.ccs.tencentyun.com/violin/drone-kaniko:latest settings: repo: ccr.ccs.tencentyun.com/violin/todo-frontend tags: - - ${DRONE_COMMIT_SHA} - latest - username: - from_secret: registry_username + - ${DRONE_COMMIT_SHA:0:8} + dockerfile: Dockerfile + context: . + registry: ccr.ccs.tencentyun.com + username: 100024540033 password: - from_secret: registry_password + from_secret: docker_password - name: dev-deploy image: ccr.ccs.tencentyun.com/violin/kubectl:latest + cluster: kubernetes + namespace: drone commands: - - kubectl set image deployment/todo-frontend todo-frontend=ccr.ccs.tencentyun.com/violin/todo-frontend:${DRONE_COMMIT_SHA} -n drone - - kubectl rollout status deployment/todo-frontend -n drone - environment: - KUBECONFIG: - from_secret: kubeconfig + - kubectl apply -f k8s/deployment.yaml --- kind: pipeline type: kubernetes -clone: - disable: true + name: build-and-deploy-prod trigger: @@ -64,41 +56,33 @@ trigger: - master 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 - image: node:18-alpine + image: ccr.ccs.tencentyun.com/violin/node:18-alpine commands: - npm install - name: prod-build - image: node:18-alpine + image: ccr.ccs.tencentyun.com/violin/node:18-alpine commands: - npm run build:h5 - name: prod-build-image - image: ccr.ccs.tencentyun.com/violin/docker:linux-amd64 + image: ccr.ccs.tencentyun.com/violin/drone-kaniko:latest settings: repo: ccr.ccs.tencentyun.com/violin/todo-frontend tags: - - ${DRONE_COMMIT_SHA} - v1.0.0 - username: - from_secret: registry_username + dockerfile: Dockerfile + context: . + registry: ccr.ccs.tencentyun.com + username: 100024540033 password: - from_secret: registry_password + from_secret: docker_password - name: prod-deploy image: ccr.ccs.tencentyun.com/violin/kubectl:latest + cluster: kubernetes + namespace: drone commands: - - kubectl set image deployment/todo-frontend todo-frontend=ccr.ccs.tencentyun.com/violin/todo-frontend:${DRONE_COMMIT_SHA} -n drone - - kubectl rollout status deployment/todo-frontend -n drone - environment: - KUBECONFIG: - from_secret: kubeconfig + - kubectl set image deployment/todo-frontend todo-frontend=ccr.ccs.tencentyun.com/violin/todo-frontend:v1.0.0 + - kubectl rollout status deployment/todo-frontend diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..fb19e9c --- /dev/null +++ b/Dockerfile @@ -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;"] diff --git a/k8s/deployment.yaml b/k8s/deployment.yaml new file mode 100644 index 0000000..46d7180 --- /dev/null +++ b/k8s/deployment.yaml @@ -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