Compare commits

..

19 Commits

Author SHA1 Message Date
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
bamanker
a83edb9479 传递环境变量19
Some checks failed
Build Push and Deploy Image / build (push) Has been cancelled
2025-12-26 11:15:39 +08:00
bamanker
2bf5e16dcd 传递环境变量18
Some checks failed
Build Push and Deploy Image / build (push) Has been cancelled
2025-12-26 11:12:02 +08:00
bamanker
d726553254 传递环境变量17
Some checks failed
Build Push and Deploy Image / build (push) Has been cancelled
2025-12-26 11:03:07 +08:00
bamanker
a66c3341d8 传递环境变量16 2025-12-26 11:01:51 +08:00
bamanker
ade040c622 传递环境变量15
Some checks failed
Build Push and Deploy Image / build (push) Has been cancelled
2025-12-26 10:57:34 +08:00
bamanker
9384be3d8a 传递环境变量14
Some checks failed
Build Push and Deploy Image / build (push) Has been cancelled
2025-12-26 10:47:13 +08:00
bamanker
cb0355b2d3 传递环境变量13
Some checks failed
Build Push and Deploy Image / build (push) Has been cancelled
2025-12-26 10:45:29 +08:00
bamanker
a59bf54e56 传递环境变量12
Some checks failed
Build Push and Deploy Image / build (push) Has been cancelled
2025-12-26 10:20:13 +08:00
bamanker
a82e7e9c26 传递环境变量11
Some checks failed
Build Push and Deploy Image / build (push) Has been cancelled
2025-12-26 10:03:49 +08:00
bamanker
1e81261aef 传递环境变量10
Some checks failed
Build Push and Deploy Image / build (push) Failing after 2s
2025-12-26 10:02:07 +08:00
3 changed files with 70 additions and 50 deletions

View File

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

View File

@@ -26,7 +26,7 @@ spec:
version: $APP_TAG
spec:
containers:
- image: registry.cn-chengdu.aliyuncs.com/bamanker/myk3stest:$APP_TAG #$REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME
- image: $REGISTRY/$IMAGE_NAMESPACE/$IMAGE_NAME:$APP_TAG
name: $APP_NAME
imagePullPolicy: Always
readinessProbe:

30
pom.xml
View File

@@ -8,9 +8,10 @@
<version>4.0.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.bamanker</groupId>
<artifactId>myk3sTest</artifactId>
<version>0.0.1</version>
<version>v1.1.9</version>
<name>myk3sTest</name>
<description>myk3sTest</description>
<url/>
@@ -28,11 +29,13 @@
</scm>
<properties>
<java.version>25</java.version>
<app.version>${version}</app.version>
<app.name>${artifactId}</app.name>
<maven.compiler.source>25</maven.compiler.source>
<maven.compiler.target>25</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
@@ -59,7 +62,27 @@
<build>
<finalName>myk3sTest</finalName>
<!--指定filtering=true.maven的占位符解析表达式就可以用于它里面的文件-->
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<!--支持yaml读取pom的参数-->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<encoding>UTF-8</encoding>
<delimiters>
<delimiter>@</delimiter>
</delimiters>
<useDefaultDelimiters>false</useDefaultDelimiters>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
@@ -77,13 +100,11 @@
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
@@ -94,5 +115,4 @@
</plugin>
</plugins>
</build>
</project>