54 lines
1.5 KiB
YAML
54 lines
1.5 KiB
YAML
name: CI/CD
|
|
|
|
on:
|
|
push:
|
|
branches: [ main ]
|
|
|
|
jobs:
|
|
build-and-deploy:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
|
|
- name: 设置 Node.js
|
|
uses: actions/setup-node@v3
|
|
with:
|
|
node-version: '20.x'
|
|
|
|
- name: 设置淘宝依赖源
|
|
run: npm config set registry https://registry.npmmirror.com
|
|
|
|
- name: 安装依赖
|
|
run: npm i
|
|
|
|
- name: 构建项目
|
|
run: npm run build
|
|
|
|
- name: 登录到 Docker Hub
|
|
uses: docker/login-action@v2
|
|
with:
|
|
registry: registry.cn-guangzhou.aliyuncs.com
|
|
username: ${{ secrets.NROP_DOCKERHUB_USERNAME }}
|
|
password: ${{ secrets.NROP_DOCKERHUB_TOKEN }}
|
|
|
|
- name: 构建并推送 Docker 镜像
|
|
uses: docker/build-push-action@v4
|
|
with:
|
|
context: .
|
|
push: true
|
|
tags: registry.cn-guangzhou.aliyuncs.com/acme_nrop/vue-cicd-k8s-sample:${{ github.sha }}
|
|
|
|
- name: 设置 Kubernetes 工具
|
|
uses: azure/setup-kubectl@v3
|
|
|
|
- name: deploy to cluster
|
|
uses: steebchen/kubectl@v2.0.0
|
|
with:
|
|
config: ${{ secrets.NROP_K8S_CONFIG_DATA }}
|
|
command: set image --record deployment/vue-cicd-k8s-sample vue-deploy-k8s=registry.cn-guangzhou.aliyuncs.com/acme_nrop/vue-cicd-k8s-sample:${{ github.sha }}
|
|
- name: verify deployment
|
|
uses: steebchen/kubectl@v2.0.0
|
|
with:
|
|
config: ${{ secrets.NROP_K8S_CONFIG_DATA }}
|
|
command: rollout status deployment/vue-cicd-k8s-sample |