Update master.yml
This commit is contained in:
parent
1056dcf050
commit
7bc15e7e9d
61
.github/workflows/master.yml
vendored
61
.github/workflows/master.yml
vendored
@ -1,5 +1,6 @@
|
|||||||
# 复制到 itfx 仓库: .github/workflows/deploy.yml
|
# 复制到 itfx: .github/workflows/deploy.yml
|
||||||
# Secrets: TCR_USERNAME, TCR_PASSWORD, SSH_HOST(42), SSH_USERNAME, SSH_PASSWORD
|
# Secrets: SSH_HOST(42), SSH_USERNAME, SSH_PASSWORD
|
||||||
|
# 集群: ./scripts/16-setup-kaniko.sh
|
||||||
name: Build and Deploy
|
name: Build and Deploy
|
||||||
|
|
||||||
on:
|
on:
|
||||||
@ -7,52 +8,38 @@ on:
|
|||||||
branches: [master]
|
branches: [master]
|
||||||
|
|
||||||
env:
|
env:
|
||||||
TCR_REGISTRY: ccr.ccs.tencentyun.com
|
GIT_URL: https://github.com/xiaoliutral/itfx.git
|
||||||
TCR_NAMESPACE: ideship
|
DOCKERFILE: src/InterfaceForward.Api/Dockerfile
|
||||||
IMAGE_NAME: interfaceforward_api
|
IMAGE_NAME: interfaceforward_api
|
||||||
DEPLOY_NAME: interfaceforward-api
|
DEPLOY_NAME: interfaceforward-api
|
||||||
CONTAINER_NAME: interfaceforward-api
|
CONTAINER_NAME: interfaceforward-api
|
||||||
DOCKERFILE: src/InterfaceForward.Api/Dockerfile
|
TCR_REGISTRY: ccr.ccs.tencentyun.com
|
||||||
|
TCR_NAMESPACE: ideship
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-deploy:
|
deploy:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- name: Kaniko build + deploy
|
||||||
|
|
||||||
- uses: docker/setup-buildx-action@v3
|
|
||||||
|
|
||||||
- name: Login to TCR
|
|
||||||
uses: docker/login-action@v3
|
|
||||||
with:
|
|
||||||
registry: ${{ env.TCR_REGISTRY }}
|
|
||||||
username: ${{ secrets.TCR_USERNAME }}
|
|
||||||
password: ${{ secrets.TCR_PASSWORD }}
|
|
||||||
|
|
||||||
- name: Build and push
|
|
||||||
uses: docker/build-push-action@v5
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
file: ${{ env.DOCKERFILE }}
|
|
||||||
push: true
|
|
||||||
tags: |
|
|
||||||
${{ env.TCR_REGISTRY }}/${{ env.TCR_NAMESPACE }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
|
|
||||||
${{ env.TCR_REGISTRY }}/${{ env.TCR_NAMESPACE }}/${{ env.IMAGE_NAME }}:latest
|
|
||||||
# 👇 关键:开启缓存,复用 Docker 各层
|
|
||||||
cache-from: type=gha
|
|
||||||
cache-to: type=gha,mode=max
|
|
||||||
# 👇 配置镜像加速(国内必选)
|
|
||||||
build-args: |
|
|
||||||
BUILDKIT_DOCKER_REGISTRY_MIRROR=https://mirror.ccs.tencentyun.com
|
|
||||||
|
|
||||||
- name: Deploy to k3s
|
|
||||||
uses: appleboy/ssh-action@v1.0.3
|
uses: appleboy/ssh-action@v1.0.3
|
||||||
with:
|
with:
|
||||||
host: ${{ secrets.SSH_HOST }}
|
host: ${{ secrets.SSH_HOST }}
|
||||||
username: ${{ secrets.SSH_USERNAME }}
|
username: ${{ secrets.SSH_USERNAME }}
|
||||||
password: ${{ secrets.SSH_PASSWORD }}
|
password: ${{ secrets.SSH_PASSWORD }}
|
||||||
script: |
|
script: |
|
||||||
|
set -e
|
||||||
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 }}"
|
cd /data/k3s
|
||||||
kubectl -n prod set image deploy/${{ env.DEPLOY_NAME }} ${{ env.CONTAINER_NAME }}="$IMG"
|
TAG="${{ github.sha }}"
|
||||||
kubectl -n prod rollout status deploy/${{ env.DEPLOY_NAME }} --timeout=180s
|
IMG="${{ env.TCR_REGISTRY }}/${{ env.TCR_NAMESPACE }}/${{ env.IMAGE_NAME }}:${TAG}"
|
||||||
|
|
||||||
|
./scripts/ci-kaniko-build.sh \
|
||||||
|
"${{ env.GIT_URL }}" \
|
||||||
|
"${{ env.DOCKERFILE }}" \
|
||||||
|
"${{ env.IMAGE_NAME }}" \
|
||||||
|
"${TAG}" \
|
||||||
|
"${TAG}"
|
||||||
|
|
||||||
|
kubectl -n prod set image "deploy/${{ env.DEPLOY_NAME }}" \
|
||||||
|
"${{ env.CONTAINER_NAME }}=${IMG}"
|
||||||
|
kubectl -n prod rollout status "deploy/${{ env.DEPLOY_NAME }}" --timeout=180s
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user