Dockerfile 安装echarts插件给java提供服务
java调用echarts插件,生成图片保存到磁盘然后插入到pptx中报表。
Dockerfile文件内容:
#基础镜像,如果本地仓库没有,会从远程仓库拉取 openjdk:8
FROM docker.io/centos:centos7
#暴露端口
EXPOSE 9311
# 避免centos 日志输出 中文乱码
ENV LANG en_US.utf8
#容器中创建工作目录
WORKDIR /usr/local/plugin
#容器中创建子目录
RUN mkdir -p ./data \
&& mkdir -p ./Echart \
&& yum -y install fontconfig-devel \
&& yum groupinstall 'fonts' -y
# 构建容器时 复制解压 echarts phantomjs jdk 到容器
ADD jdk-8u202-linux-x64.tar.gz ./
ADD echarts-convert.tar.gz ./
ADD phantomjs-2.1.1-linux-x86_64.tar.bz2 ./
# 构建容器时 编译后的jar包copy到容器中创建到目录内
COPY realize-market-value.jar ./
COPY MVDR_YYYYMMDD_Template.docx ./
# 构建容器时 安装phantomjs 依赖系统libfontconfig.so文件
#RUN yum -y install fontconfig-devel
# 构建容器时 安装phantomjs 生成echart图片中文字体乱码解决
#RUN yum groupinstall 'fonts' -y
#配置环境变量
ENV JAVA_HOME=./jdk1.8.0_202
ENV CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV PATH=$JAVA_HOME/bin:$PATH
# 构建容器时 指定容器时区
RUN rm -f /etc/localtime \
&& ln -sv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone
# 启动容器时 要执行的命令
ENTRYPOINT ["java","-jar","-Dspring.profiles.active=server","realize-market-value.jar"]
# 启动容器时 启动 tomcat
# CMD ["/usr/local/tomcat/apache-tomcat-8.5.27/bin/catalina.sh", "run"]
# 启动容器时 CMD的参数可以在镜像运行的时候被替换掉,并且成为ENTRYPOINT命令的参数
# CMD ["realize-market-value.jar"]
k8s文件:
apiVersion: v1
kind: Service
metadata:
name: $IMG_NAME
namespace: rz-dt
labels:
app: $IMG_NAME
spec:
type: ClusterIP
ports:
- name: tcp-9311-9311
port: 9311
protocol: TCP
targetPort: 9311
selector:
app: $IMG_NAME
---
apiVersion: apps/v1
kind: Deployment #对象类型
metadata:
name: $IMG_NAME #名称
namespace: rz-dt
labels:
app: $IMG_NAME #标注
spec:
replicas: 1 #运行容器的副本数,修改这里可以快速修改分布式节点数量
selector:
matchLabels:
app: $IMG_NAME
template:
metadata:
labels:
app: $IMG_NAME
spec:
containers: #docker容器的配置
- name: $IMG_NAME
env:
- name: aliyun_logs_catalina
value: stdout
image: rz-dt-image-server-registry-vpc.cn-shanghai.cr.aliyuncs.com/rz-dt-real/$IMG_NAME:$IMG_TAG # pull镜像的地址 ip:prot/dir/images:tag
imagePullPolicy: Always #pull镜像时机,
ports:
- containerPort: 9311 #容器对外开放端口,需与springboot配置文件一致
volumeMounts:
- name: time-config
mountPath: /etc/localtime
readOnly: true
- name: volume-logs
mountPath: /logs
subPath: logs
resources:
limits:
cpu: 5000m
memory: 1Gi
requests:
cpu: 3000m
memory: 200Mi
#从私有仓库拉取镜像凭证
imagePullSecrets:
- name: rz-dt-miyue-vpc
volumes:
- name: time-config
hostPath:
path: /usr/share/zoneinfo/Asia/Shanghai
- name: volume-logs
persistentVolumeClaim:
claimName: rz-dt-nas-volume-claim-real
发布文件脚本:
echo "开始制作镜像..."
image_name=realize-market-value
image_tag=`date +%Y-%m-%d-%H-%M-%S` #_%H%M
echo "当前时间版本号:$image_tag"
docker build -t ${image_name}:${image_tag} .
echo "制作镜像成功!"
echo "登录"
sudo docker login --username=aliyun0398513152 rz-dt-image-server-registry-vpc.cn-shanghai.cr.aliyuncs.com --password=1234!@#$qwerQWER
echo "镜像最新版本提交"
docker tag ${image_name}:${image_tag} rz-dt-image-server-registry-vpc.cn-shanghai.cr.aliyuncs.com/rz-dt-real/${image_name}:${image_tag}
docker push rz-dt-image-server-registry-vpc.cn-shanghai.cr.aliyuncs.com/rz-dt-real/${image_name}:${image_tag}
echo "k8s一键部署"
export IMG_TAG=${image_tag}
export IMG_NAME=${image_name}
envsubst < ${image_name}'-real'.yaml | kubectl --kubeconfig ~/.kube-rz-real/config apply -f -