Skip to content

workflow

workflow #1

Workflow file for this run

name: Deploy
on: # action触发条件,此处即为push以v开头tag时触发
push:
tags:
- v**
jobs:
Deploy:
runs-on: self-hosted # 运行环境,此处为自建runner,已在组织中设置共享,可直接调用,禁止直接修改其环境
steps:
- name: Checkout # 检出代码,固定项
uses: actions/checkout@v3
- name: Get Docker Image Url # 获取镜像地址,只需修改url为habrbor中镜像地址
id: image
env:
URL: harbor.ncuos.com/fresh/hello
run: |
echo LATEST=${URL}:latest >> $GITHUB_OUTPUT
echo VERSION=${URL}:${GITHUB_REF/refs\/tags\//} >> $GITHUB_OUTPUT
- name: Build the Docker image # 构建镜像,在容器中安装环境和依赖
run: |
docker build . --file Dockerfile \
--tag ${{ steps.image.outputs.VERSION }} \
--tag ${{ steps.image.outputs.LATEST }}
- name: Push # 推送镜像
run: |
docker push ${{ steps.image.outputs.VERSION }}
docker push ${{ steps.image.outputs.LATEST }}
- name: Update Deployment # 推送部署,只需修改namespace和workload
uses: MultiMx/K8sSetImageAction@v0.5
with:
backend: "https://rancher.ncuhome.club"
token: ${{ secrets.LOCAL_RANCHER_DEPLOY}} #token在rancher中获取然后在settings-secrets-action中设置,
namespace: fresh
workload: hello #workload为rancher中的deployment名称
image: ${{ steps.image.outputs.VERSION }}