Update CI/CD pipeline configuration for deployment
This commit is contained in:
parent
ad275634ae
commit
61ead142df
25
.github/workflows/master.yml
vendored
25
.github/workflows/master.yml
vendored
@ -1,11 +1,12 @@
|
|||||||
name: CI/CD Pipeline
|
# 复制到 itfx 仓库: .github/workflows/deploy.yml
|
||||||
|
# Secrets: TCR_USERNAME, TCR_PASSWORD, SSH_HOST(42), SSH_USERNAME, SSH_PASSWORD
|
||||||
|
name: Build and Deploy
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches: [master]
|
||||||
- master # 监视的分支
|
|
||||||
|
|
||||||
env: # ← 定义在这里
|
env:
|
||||||
TCR_REGISTRY: ccr.ccs.tencentyun.com
|
TCR_REGISTRY: ccr.ccs.tencentyun.com
|
||||||
TCR_NAMESPACE: ideship
|
TCR_NAMESPACE: ideship
|
||||||
IMAGE_NAME: interfaceforward_api
|
IMAGE_NAME: interfaceforward_api
|
||||||
@ -14,11 +15,10 @@ env: # ← 定义在这里
|
|||||||
DOCKERFILE: src/InterfaceForward.Api/Dockerfile
|
DOCKERFILE: src/InterfaceForward.Api/Dockerfile
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
deploy:
|
build-deploy:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- uses: actions/checkout@v4
|
||||||
uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- uses: docker/setup-buildx-action@v3
|
- uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
@ -38,18 +38,21 @@ jobs:
|
|||||||
tags: |
|
tags: |
|
||||||
${{ env.TCR_REGISTRY }}/${{ env.TCR_NAMESPACE }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
|
${{ env.TCR_REGISTRY }}/${{ env.TCR_NAMESPACE }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
|
||||||
${{ env.TCR_REGISTRY }}/${{ env.TCR_NAMESPACE }}/${{ env.IMAGE_NAME }}:latest
|
${{ env.TCR_REGISTRY }}/${{ env.TCR_NAMESPACE }}/${{ env.IMAGE_NAME }}:latest
|
||||||
|
# 👇 关键:开启缓存,复用 Docker 各层
|
||||||
cache-from: type=gha
|
cache-from: type=gha
|
||||||
cache-to: type=gha,mode=max
|
cache-to: type=gha,mode=max
|
||||||
|
# 👇 配置镜像加速(国内必选)
|
||||||
|
build-args: |
|
||||||
|
BUILDKIT_DOCKER_REGISTRY_MIRROR=https://mirror.ccs.tencentyun.com
|
||||||
|
|
||||||
- name: Deploy to k3s
|
- name: Deploy to k3s
|
||||||
uses: appleboy/ssh-action@v1.0.3
|
uses: appleboy/ssh-action@v1.0.3
|
||||||
with:
|
with:
|
||||||
host: ${{ secrets.SSH_K3S_HOST }}
|
host: ${{ secrets.SSH_HOST }}
|
||||||
username: ${{ secrets.SSH_K3S_USERNAME }}
|
username: ${{ secrets.SSH_USERNAME }}
|
||||||
password: ${{ secrets.SSH_K3S_PASSWORD }}
|
password: ${{ secrets.SSH_PASSWORD }}
|
||||||
script: |
|
script: |
|
||||||
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
|
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
|
||||||
IMG="${{ env.TCR_REGISTRY }}/${{ env.TCR_NAMESPACE }}/${{ env.IMAGE_NAME }}:${{ github.sha }}"
|
IMG="${{ env.TCR_REGISTRY }}/${{ env.TCR_NAMESPACE }}/${{ env.IMAGE_NAME }}:${{ github.sha }}"
|
||||||
kubectl -n prod set image deploy/${{ env.DEPLOY_NAME }} ${{ env.CONTAINER_NAME }}="$IMG"
|
kubectl -n prod set image deploy/${{ env.DEPLOY_NAME }} ${{ env.CONTAINER_NAME }}="$IMG"
|
||||||
kubectl -n prod rollout status deploy/${{ env.DEPLOY_NAME }} --timeout=180s
|
kubectl -n prod rollout status deploy/${{ env.DEPLOY_NAME }} --timeout=180s
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user