一、目标
同一套代码,在不同环境构建时加载各自环境的配置文件,如下图
在maven命令中根据-P参数加载resources下不同文件夹下的配置文件,如下面的命令就可加载dev文件夹下的配置文件dev.config
mvn -B clean package -U -Pdev
二、步骤
eova或JFinal同springboot差不多,主要以下几点:
1、pom.xml,在后面加上下面profile
<!--放在build后面-->
<profiles>
<!--默认为测试环境-->
<!--mvn package -Ptest 打包测试配置-->
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<config.dir>dev</config.dir>
</properties>
</profile>
<profile>
<id>prod</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<config.dir>default</config.dir>
</properties>
</profile>
<profile>
<id>pre</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<config.dir>pre</config.dir>
</properties>
</profile>
</profiles>
2、package.xml,因为eova会把一些打包的命令放在此文件内,所以此文件也要加上配置
<fileSets>
<!-- src/main/resources 全部 copy 到 config 目录下 -->
<fileSet>
<directory>${basedir}/src/main/resources</directory>
<outputDirectory>config</outputDirectory>
<includes>
<!-- Maven -P [dev|prd]自定义参数控制 -->
<include>${config.dir}/*.config</include>
<include>*.xml</include>
<include>*.properties</include>
<include>*.txt</include>
</includes>
</fileSet>
</fileSets>
关键一段是:<include>${config.dir}/*.config</include>
3、deploy.yaml,这个由运维提供,没啥特别的
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: 应用名
name: 应用名
namespace: 空间名
spec:
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
app: 应用名
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
annotations:
armsPilotAutoEnable: 'on'
armsPilotCreateAppName: 应用名-test
labels:
app: 应用名
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- eova
topologyKey: kubernetes.io/hostname
containers:
- image: >-
${IMAGE_NAME}
imagePullPolicy: IfNotPresent
name: eova
ports:
- containerPort: 9001
protocol: TCP
livenessProbe:
tcpSocket:
port: 9001
initialDelaySeconds: 60
periodSeconds: 15
timeoutSeconds: 10
successThreshold: 1
failureThreshold: 3
readinessProbe:
tcpSocket:
port: 9001
initialDelaySeconds: 60
periodSeconds: 15
timeoutSeconds: 10
successThreshold: 1
failureThreshold: 3
resources:
limits:
# cpu: 2
memory: 4Gi
requests:
# cpu: 1
memory: 4Gi
imagePullSecrets:
- name: regsecret
restartPolicy: Always
---
apiVersion: v1
kind: Service
metadata:
name: 应用名
namespace: 空间名
spec:
ports:
- name: 应用名
port: 9001
protocol: TCP
targetPort: 9001
selector:
app: 应用名
type: ClusterIP
4、阿里云效构建
最简单的mvn命令
?
三、注意(Anolis OS)坑
服务器是架在阿里云上,阿里云linux(即Anolis OS)是基于centOS开发;但以centOS8的Anolis OS却无法部署,执行init ModLoader后就报错了,后来阿里的客户没找到原因,涉及内核,还好,用CentOS7的服务器就可以实现上述功能,多环境加载。
|