Compare commits

...

12 Commits

Author SHA1 Message Date
bamanker
2cc70877a0 直接用本地kubectl
Some checks failed
Build Push and Deploy Image / build (push) Failing after 1m7s
2025-12-26 17:04:07 +08:00
bamanker
44c6fab1f4 更换kubectl action,修复了bug3
Some checks failed
Build Push and Deploy Image / build (push) Failing after 1m17s
2025-12-26 16:37:45 +08:00
bamanker
cf924d1ee7 更换kubectl action,修复了bug1
Some checks failed
Build Push and Deploy Image / build (push) Failing after 47s
2025-12-26 16:04:13 +08:00
bamanker
d97d39e5c4 更换kubectl action,修复了bug
Some checks failed
Build Push and Deploy Image / build (push) Failing after 30s
2025-12-26 15:51:23 +08:00
bamanker
55f57f9085 更换kubectl action
All checks were successful
Build Push and Deploy Image / build (push) Successful in 2m7s
2025-12-26 15:42:05 +08:00
bamanker
0389942e4f debug22
Some checks failed
Build Push and Deploy Image / build (push) Has been cancelled
2025-12-26 15:00:39 +08:00
bamanker
bc853144b8 debug21
Some checks failed
Build Push and Deploy Image / build (push) Has been cancelled
2025-12-26 14:57:57 +08:00
bamanker
f5b1de075f add 显示注入后的deployment文件
Some checks failed
Build Push and Deploy Image / build (push) Failing after 1m14s
2025-12-26 12:50:09 +08:00
bamanker
24df5cd7d6 修复了一个小问题
Some checks failed
Build Push and Deploy Image / build (push) Has been cancelled
2025-12-26 12:45:45 +08:00
bamanker
6ed61c6501 修复传递环境变量不成功的问题1
Some checks failed
Build Push and Deploy Image / build (push) Failing after 13s
2025-12-26 12:43:23 +08:00
bamanker
f677828aae 修复传递环境变量不成功的问题
Some checks failed
Build Push and Deploy Image / build (push) Failing after 14s
2025-12-26 12:19:43 +08:00
bamanker
29f1bc8aa1 传递环境变量20
Some checks failed
Build Push and Deploy Image / build (push) Has been cancelled
2025-12-26 12:00:41 +08:00
2 changed files with 38 additions and 48 deletions

View File

@@ -10,51 +10,48 @@ on:
# - main # - main
workflow_dispatch: #手动构建h workflow_dispatch: #手动构建h
#设置全局环境变量
env: env:
PATH: /opt/node/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin PATH: /opt/node/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
REGISTRY: registry.cn-chengdu.aliyuncs.com REGISTRY: ${{ secrets.DOCKER_REGISTRY }}
IMAGE_NAMESPACE: bamanker IMAGE_NAMESPACE: bamanker # todo 可以通过读取pom文件获取下面这些属性值
IMAGE_NAME: myk3stest IMAGE_NAME: myk3stest
APP_NAME: myk3s-test APP_NAME: myk3s-test
# 构建 Job
jobs: jobs:
# 构建 Job
build: build:
runs-on: host runs-on: host
steps: steps:
# 下载仓库源码,依赖java环境,因此构建服务器本地需要下载安装java并设置环境变量 # 下载仓库源码,依赖node环境,因此构建服务器本地需要下载安装node并设置环境变量
- name: Checkout repository code - name: Checkout repository code
#使用自定义仓库action
uses: http://139.9.216.111:3000/bamanker/checkout@v6 uses: http://139.9.216.111:3000/bamanker/checkout@v6
# - name: Set up Java
# uses: https://gitee.com/bamanker/setup-java@v5 # 获取 TAG 并设置为环境变量
# with:
# java-version: '25.0.1'
# distribution: 'openjdk'
# cache: 'maven'
#检查tag
- name: Get version - name: Get version
id: get_version id: get_version
# e.g. refs/tags/v1.0.0 # e.g. refs/tags/v1.0.0
run: | run: |
echo "version=${GITHUB_REF/refs\/tags\/v}" >> $GITHUB_OUTPUT echo "APP_TAG=${GITHUB_REF/refs\/tags\/v}" >> $GITHUB_ENV
# - name: Check java version
# run: java -version
# 检查 TAG 并传参
- name: Set envVar
id: set_envar
run: |
echo "The app version is $APP_TAG" && echo "tag=$APP_TAG" >> $GITHUB_OUTPUT &&
echo "now workspace: ${{ github.workspace }}" &&
pwd
- name: Set Env Var # 为其他配置文件注入环境变量
env: - name: Inject envVar
APP_VERSION: ${{ steps.get_version.outputs.version }}
run: | run: |
echo "The app version is $APP_VERSION" && export APP_TAG=$APP_VERSION envsubst < ./deployment-temp.yml > ./deployment.yml &&
# export APP_TAG=$env.TAG cat ./deployment.yml
# echo APP_TAG=${{ env.TAG }} |
# export APP_NAME=${{ env.APP_NAME }} | # 构建java项目
# echo APP_NAME=${{ env.APP_NAME }} |
- name: Inject Env Var
run: |
envsubst < ./deployment.yml
- name: Build with Maven - name: Build with Maven
# 设置Maven执行权限使用maven绝对路径执行打包命令 #使用maven绝对路径执行打包命令
run: /usr/local/maven/bin/mvn clean package -DskipTests -Pprod run: /usr/local/maven/bin/mvn clean package -DskipTests -Pprod
# 登录镜像仓库,方便后续上传镜像 # 登录镜像仓库,方便后续上传镜像
@@ -66,40 +63,33 @@ jobs:
# 这里也可以通过 secrets 传入,后面再介绍 # 这里也可以通过 secrets 传入,后面再介绍
password: ${{ secrets.DOCKERHUB_PASSWORD }} password: ${{ secrets.DOCKERHUB_PASSWORD }}
# 获取时间戳 # # 获取时间戳
- name: Get datetime # - name: Get datetime
id: datetime # id: datetime
run: | # run: |
echo "datetime=$(date '+%Y-%m-%d-%H-%M-%S')" >> $GITHUB_OUTPUT # echo "datetime=$(date '+%Y-%m-%d-%H-%M-%S')" >> $GITHUB_OUTPUT
# 构建并上传镜像 # 构建并上传镜像
- name: Build and push Docker image - name: Build and push Docker image
uses: http://139.9.216.111:3000/bamanker/build-push-action@v6 # 获取上一步截取到的版本号,既 1.0.0 uses: http://139.9.216.111:3000/bamanker/build-push-action@v6 # 获取上一步截取到的版本号,既 1.0.0
#只能这样接收
env: env:
TAG: ${{ steps.get_version.outputs.version }} TAG: ${{ steps.set_envar.outputs.tag }}
with: with:
context: . context: .
platforms: linux/amd64 platforms: linux/amd64
file: Dockerfile file: Dockerfile
push: true push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAMESPPACE }}/${{ env.IMAGE_NAME }}:${{ env.TAG }} tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAMESPACE }}/${{ env.IMAGE_NAME }}:${{ env.TAG }}
#发布到 k8s
- name: k8s Check and Apply New Deployment - name: Generate kubeconfig and deploy
uses: http://139.9.216.111:3000/bamanker/steevchen-kubectl@master run: kubectl apply -f ./deployment.yml
with: # command: apply -f http://139.9.216.111:3000/bamanker/myk3sTest/raw/branch/master/.deploy/deployment-temp.yml
config: ${{ secrets.KUBE_CONFIG }}
command: apply -f http://139.9.216.111:3000/bamanker/myk3sTest/raw/branch/master/.deploy/deployment.yml
- name: k8s Check Pods Health - name: k8s Check Pods Health
uses: http://139.9.216.111:3000/bamanker/steevchen-kubectl@master run: kubectl get pod -n default -l app=${{ env.APP_NAME }}
with:
config: ${{ secrets.KUBE_CONFIG }}
command: get pod -n default -l app=${{ env.APP_NAME }}
- name: k8s Update Deployment - name: k8s Update Deployment
uses: http://139.9.216.111:3000/bamanker/steevchen-kubectl@master run: kubectl rollout restart deployment ${{ env.APP_NAME }}-${{ gitea.ref_name }}
env:
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
with:
command: rollout restart deployment ${{ env.APP_NAME }}-${{ gitea.ref_name }}