jenkins自动发布之java项目
Contents
java项目
微服务
安装插件
Maven Integration
Dockerfile
FROM openjdk:8-jre-slim
MAINTAINER yanyong
ARG ACTIVE
ENV JAVA_OPT="-Xms1g -Xmx1g"
ENV JAVA_ARG="--spring.profiles.active=$ACTIVE"
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo 'Asia/Shanghai' > /etc/timezone
ADD target/*.jar /opt/app.jar
CMD ["sh","-c","exec java $JAVA_OPT -jar /opt/app.jar $JAVA_ARG"]
deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: megaordermiddleware-basic-gateway
spec:
selector:
matchLabels:
app: megaordermiddleware-basic-gateway
replicas: 2
template:
metadata:
labels:
app: megaordermiddleware-basic-gateway
spec:
containers:
- name: megaordermiddleware-basic-gateway
image: harbor.mkl.io/oms/megaordermiddleware-basic-gateway:1.0-$BUILD_NUMBER
imagePullPolicy: IfNotPresent
ports:
- containerPort: 7777
imagePullSecrets:
- name: secret-harbor-user
---
apiVersion: v1
kind: Service
metadata:
name: megaordermiddleware-basic-gateway
spec:
type: NodePort
selector:
app: megaordermiddleware-basic-gateway
ports:
- port: 7777
targetPort: 7777
多环境区分,src/main/resources/bootstrap.yml
nacos配置中心增加命名空间:yanyong
spring:
profiles: yanyong
cloud:
nacos:
discovery:
server-addr: nacos.mkl.io
namespace: yanyong
config:
server-addr: nacos.mkl.io
file-extension: yml
namespace: yanyong
jenkins, maven打包
clean package -pl megaordermiddleware-basic/megaordermiddleware-basic-gateway -am -Dmaven.test.skip=true
jenkins, Build脚本
|
|
jenkins, Post-build Actions设置
#Source files
megaordermiddleware-basic/megaordermiddleware-basic-gateway/deployment-test.yaml
#Remove prefix
megaordermiddleware-basic/megaordermiddleware-basic-gateway
#Remote directory
DEPLOY/$JOB_BASE_NAME
#Exec command
export BUILD_NUMBER=$BUILD_NUMBER
envsubst < DEPLOY/$JOB_BASE_NAME/deployment-test.yaml | kubectl apply -f -
前端vue
Dockerfile
FROM node:14.17.3 as nodebuilder
WORKDIR /Node
COPY . .
#RUN apt update && apt-get -y install yarn && yarn && yarn build:prod
#RUN npm install && npm run build:prod
#RUN npm install --registry=https://registry.npm.taobao.org && npm run build:prod
#RUN npm install --registry=https://mirrors.huaweicloud.com/repository/npm/ && npm run build:prod
RUN git config --global url."https://".insteadOf git:// \
&& cp .env.test .env.production \
&& apt update && apt-get -y install yarn \
&& yarn && yarn build:prod
FROM nginx:alpine
MAINTAINER megacombine
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo 'Asia/Shanghai' > /etc/timezone
COPY --from=nodebuilder /Node/dist/ /usr/share/nginx/html/
nmp install安装依赖时报错:
ERR! /usr/bin/git ls-remote -h -t git://github.com/adobe-webplatform/eve.git
解决办法:
|
|
deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: megaordermiddleware-management-ui-vue
spec:
selector:
matchLabels:
app: megaordermiddleware-management-ui-vue
replicas: 2
template:
metadata:
labels:
app: megaordermiddleware-management-ui-vue
spec:
containers:
- name: megaordermiddleware-management-ui-vue
image: harbor.mkl.io/oms/megaordermiddleware-management-ui-vue:1.0-$BUILD_NUMBER
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
imagePullSecrets:
- name: secret-harbor-user
---
apiVersion: v1
kind: Service
metadata:
name: megaordermiddleware-management-ui-vue
spec:
type: NodePort
selector:
app: megaordermiddleware-management-ui-vue
ports:
- port: 80
targetPort: 80
jenkins, Build脚本
|
|
jenkins, Post-build Actions脚本
|
|