Compare commits
49 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f677828aae | ||
|
|
29f1bc8aa1 | ||
|
|
a83edb9479 | ||
|
|
2bf5e16dcd | ||
|
|
d726553254 | ||
|
|
a66c3341d8 | ||
|
|
ade040c622 | ||
|
|
9384be3d8a | ||
|
|
cb0355b2d3 | ||
|
|
a59bf54e56 | ||
|
|
a82e7e9c26 | ||
|
|
1e81261aef | ||
|
|
c0975a75ed | ||
|
|
10153898c2 | ||
|
|
8412554d26 | ||
|
|
8555ea3077 | ||
|
|
79471c11a5 | ||
|
|
11c1c2fa23 | ||
|
|
90e4fb4e96 | ||
|
|
3dab5fc361 | ||
|
|
a2cea3ca9a | ||
|
|
b37172331e | ||
|
|
6d9fba8ea8 | ||
|
|
77a1f50115 | ||
|
|
1f7d5eb904 | ||
|
|
9f4028e439 | ||
|
|
b7085d2765 | ||
|
|
d2d3e9e3f5 | ||
|
|
95edbd85aa | ||
|
|
255baf2f3d | ||
|
|
713a47c337 | ||
|
|
044ddf9ef1 | ||
|
|
7d057843be | ||
|
|
d837507f10 | ||
|
|
9dd0d38cf8 | ||
|
|
647ee0937e | ||
|
|
2444817f63 | ||
|
|
6e0fe5d06b | ||
|
|
38e753b473 | ||
|
|
89f4565cd7 | ||
|
|
2da2f058ca | ||
|
|
af34178bf5 | ||
|
|
355372126f | ||
|
|
829c7b569b | ||
|
|
272b36d656 | ||
|
|
80341eb16c | ||
|
|
366c38401e | ||
|
|
b09e99e348 | ||
|
|
644d75b828 |
@@ -1,79 +0,0 @@
|
|||||||
---
|
|
||||||
## k8s默认是访问不了外部服务的,需要代理,以mysql和redis为例,代理myservice名称到192.168.0.100,配置文件中对应的ip修改为myservice
|
|
||||||
#apiVersion: v1
|
|
||||||
#kind: Endpoints
|
|
||||||
#metadata:
|
|
||||||
# name: myservice
|
|
||||||
#subsets:
|
|
||||||
# - addresses:
|
|
||||||
# - ip: 192.168.0.100
|
|
||||||
# ports:
|
|
||||||
# - port: 6379
|
|
||||||
# protocol: TCP
|
|
||||||
# name: redis
|
|
||||||
# - port: 3306
|
|
||||||
# protocol: TCP
|
|
||||||
# name: mysql
|
|
||||||
#---
|
|
||||||
#apiVersion: v1
|
|
||||||
#kind: Service
|
|
||||||
#metadata:
|
|
||||||
# name: myservice
|
|
||||||
#spec:
|
|
||||||
# ports:
|
|
||||||
# - port: 6379
|
|
||||||
# targetPort: 6379
|
|
||||||
# protocol: TCP
|
|
||||||
# name: redis
|
|
||||||
# - port: 3306
|
|
||||||
# targetPort: 3306
|
|
||||||
# protocol: TCP
|
|
||||||
# name: mysql
|
|
||||||
#
|
|
||||||
---
|
|
||||||
apiVersion: apps/v1
|
|
||||||
kind: Deployment
|
|
||||||
metadata:
|
|
||||||
name: myk3sTest
|
|
||||||
spec:
|
|
||||||
replicas: 2
|
|
||||||
revisionHistoryLimit: 3
|
|
||||||
selector:
|
|
||||||
matchLabels:
|
|
||||||
app: myk3sTest
|
|
||||||
template:
|
|
||||||
metadata:
|
|
||||||
labels:
|
|
||||||
app: myk3sTest
|
|
||||||
spec:
|
|
||||||
containers:
|
|
||||||
- image: ${env.REGISTRY}/${env.IMAGE_NAME}:${steps.datetime.outputs.datetime}
|
|
||||||
name: myk3sTest
|
|
||||||
imagePullPolicy: Always
|
|
||||||
readinessProbe:
|
|
||||||
httpGet:
|
|
||||||
path: /actuator/health
|
|
||||||
port: 9090
|
|
||||||
initialDelaySeconds: 1
|
|
||||||
successThreshold: 5
|
|
||||||
ports:
|
|
||||||
- containerPort: 9090
|
|
||||||
imagePullSecrets:
|
|
||||||
- name: dockerhub-id
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
apiVersion: v1
|
|
||||||
kind: Service
|
|
||||||
metadata:
|
|
||||||
name: myk3sTest
|
|
||||||
spec:
|
|
||||||
type: NodePort
|
|
||||||
externalTrafficPolicy: Local
|
|
||||||
ports:
|
|
||||||
- name: http-8080
|
|
||||||
protocol: TCP
|
|
||||||
port: 9090
|
|
||||||
nodePort: 30099
|
|
||||||
selector:
|
|
||||||
app: myk3sTest
|
|
||||||
@@ -10,40 +10,46 @@ 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_NAME: bamanker/myk3stest
|
IMAGE_NAMESPACE: bamanker # todo 可以通过读取pom文件获取下面这些属性值
|
||||||
CONTAINER_NAME: myk3stest
|
IMAGE_NAME: myk3stest
|
||||||
|
APP_NAME: myk3s-test
|
||||||
|
|
||||||
|
# 构建 Job
|
||||||
jobs:
|
jobs:
|
||||||
# 构建 Job
|
|
||||||
build:
|
build:
|
||||||
runs-on: host
|
runs-on: host
|
||||||
outputs: # 声明作业的输出变量,方便在其他 Job 引用
|
|
||||||
datetime: ${{ steps.datetime.outputs.datetime }}
|
|
||||||
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'
|
|
||||||
#检查java版本
|
|
||||||
- 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 "version=${GITHUB_REF/refs\/tags\/v}" >> $GITHUB_OUTPUT
|
||||||
- name: Check java version
|
|
||||||
run: java -version
|
# 检查 TAG 设置为环境变量
|
||||||
- name: Show now path
|
- name: Set envVar
|
||||||
run: echo $(pwd)
|
env:
|
||||||
|
APP_VERSION: ${{ steps.get_version.outputs.version }}
|
||||||
|
run: |
|
||||||
|
echo "The app version is $APP_VERSION" && echo "APP_TAG=$APP_VERSION" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
# 为其他配置文件注入环境变量
|
||||||
|
- name: Inject envVar
|
||||||
|
run: |
|
||||||
|
envsubst < ./deployment-temp.yml > ./deployment.yml
|
||||||
|
|
||||||
|
# 构建java项目
|
||||||
- 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
|
||||||
|
|
||||||
# 登录镜像仓库,方便后续上传镜像
|
# 登录镜像仓库,方便后续上传镜像
|
||||||
@@ -55,38 +61,41 @@ 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: $APP_TAG
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
platforms: linux/amd64
|
platforms: linux/amd64
|
||||||
file: Dockerfile
|
file: Dockerfile
|
||||||
push: true
|
push: true
|
||||||
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.TAG }}
|
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAMESPPACE }}/${{ env.IMAGE_NAME }}:${{ env.TAG }}
|
||||||
|
|
||||||
|
|
||||||
|
#发布到 k8s
|
||||||
- name: k8s Check and Apply New Deployment
|
- name: k8s Check and Apply New Deployment
|
||||||
run: ls
|
uses: http://139.9.216.111:3000/bamanker/steevchen-kubectl@master
|
||||||
# uses: http://139.9.216.111:3000/bamanker/kubectl@master
|
with:
|
||||||
# env:
|
config: ${{ secrets.KUBE_CONFIG }}
|
||||||
# KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
|
command: 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
|
||||||
|
with:
|
||||||
|
config: ${{ secrets.KUBE_CONFIG }}
|
||||||
|
command: get pod -n default -l app=${{ env.APP_NAME }}
|
||||||
|
|
||||||
# with:
|
- name: k8s Update Deployment
|
||||||
# args: get pods -A
|
uses: http://139.9.216.111:3000/bamanker/steevchen-kubectl@master
|
||||||
## args: apply -f http://${{ secrets.DEVOPS_GITEA_TOKEN }}@/bamanker/myk3sTest/src/branch/master/.deploy/deployment.yml
|
env:
|
||||||
# - name: k8s Update Deployment
|
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
|
||||||
# uses: http://139.9.216.111:3000/bamanker/kubectl@master
|
with:
|
||||||
# env:
|
command: rollout restart deployment ${{ env.APP_NAME }}-${{ gitea.ref_name }}
|
||||||
# KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
|
|
||||||
# with:
|
|
||||||
# args: rollout restart deployment ${{ env.CONTAINER_NAME }}-${{ gitea.ref_name }}
|
|
||||||
|
|
||||||
|
|||||||
61
deployment-temp.yml
Normal file
61
deployment-temp.yml
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: $APP_NAME
|
||||||
|
version: $APP_TAG
|
||||||
|
name: $APP_NAME
|
||||||
|
namespace: default
|
||||||
|
spec:
|
||||||
|
progressDeadlineSeconds: 600
|
||||||
|
replicas: 1
|
||||||
|
revisionHistoryLimit: 2
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: $APP_NAME
|
||||||
|
strategy:
|
||||||
|
rollingUpdate:
|
||||||
|
maxSurge: 50%
|
||||||
|
maxUnavailable: 50%
|
||||||
|
type: RollingUpdate
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: $APP_NAME
|
||||||
|
version: $APP_TAG
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: $REGISTRY/$IMAGE_NAMESPACE/$IMAGE_NAME:$APP_TAG
|
||||||
|
name: $APP_NAME
|
||||||
|
imagePullPolicy: Always
|
||||||
|
readinessProbe:
|
||||||
|
httpGet:
|
||||||
|
path: /actuator/health
|
||||||
|
port: 9090
|
||||||
|
initialDelaySeconds: 1
|
||||||
|
timeoutSeconds: 10
|
||||||
|
failureThreshold: 30
|
||||||
|
successThreshold: 5
|
||||||
|
ports:
|
||||||
|
- containerPort: 9090
|
||||||
|
imagePullSecrets:
|
||||||
|
- name: dockerhub-id
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: $APP_NAME
|
||||||
|
name: $APP_NAME
|
||||||
|
namespace: default
|
||||||
|
spec:
|
||||||
|
type: NodePort
|
||||||
|
externalTrafficPolicy: Local
|
||||||
|
ports:
|
||||||
|
- name: http
|
||||||
|
protocol: TCP
|
||||||
|
port: 9090
|
||||||
|
nodePort: 9090
|
||||||
|
selector:
|
||||||
|
app: $APP_NAME
|
||||||
32
pom.xml
32
pom.xml
@@ -8,9 +8,10 @@
|
|||||||
<version>4.0.1</version>
|
<version>4.0.1</version>
|
||||||
<relativePath/> <!-- lookup parent from repository -->
|
<relativePath/> <!-- lookup parent from repository -->
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<groupId>com.bamanker</groupId>
|
<groupId>com.bamanker</groupId>
|
||||||
<artifactId>myk3sTest</artifactId>
|
<artifactId>myk3sTest</artifactId>
|
||||||
<version>0.0.1</version>
|
<version>v1.1.9</version>
|
||||||
<name>myk3sTest</name>
|
<name>myk3sTest</name>
|
||||||
<description>myk3sTest</description>
|
<description>myk3sTest</description>
|
||||||
<url/>
|
<url/>
|
||||||
@@ -28,11 +29,13 @@
|
|||||||
</scm>
|
</scm>
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>25</java.version>
|
<java.version>25</java.version>
|
||||||
|
<app.version>${version}</app.version>
|
||||||
|
<app.name>${artifactId}</app.name>
|
||||||
<maven.compiler.source>25</maven.compiler.source>
|
<maven.compiler.source>25</maven.compiler.source>
|
||||||
<maven.compiler.target>25</maven.compiler.target>
|
<maven.compiler.target>25</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
@@ -59,15 +62,33 @@
|
|||||||
|
|
||||||
<build>
|
<build>
|
||||||
<finalName>myk3sTest</finalName>
|
<finalName>myk3sTest</finalName>
|
||||||
|
<!--指定filtering=true.maven的占位符解析表达式就可以用于它里面的文件-->
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
<plugins>
|
<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>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>25</source>
|
<source>25</source>
|
||||||
<target>25</target>
|
<target>25</target>
|
||||||
|
|
||||||
|
|
||||||
<annotationProcessorPaths>
|
<annotationProcessorPaths>
|
||||||
<path>
|
<path>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
@@ -79,13 +100,11 @@
|
|||||||
</path>
|
</path>
|
||||||
</annotationProcessorPaths>
|
</annotationProcessorPaths>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
<configuration>
|
<configuration>
|
||||||
|
|
||||||
<excludes>
|
<excludes>
|
||||||
<exclude>
|
<exclude>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
@@ -96,5 +115,4 @@
|
|||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
Reference in New Issue
Block a user