linux下构建rocketmq-dashboard多架构镜像——筑梦之路

接上篇:linux上构建任意版本的rocketmq多架构x86 arm镜像------筑梦之路-CSDN博客

这里来记录下构建rocketmq-dashboard多架构镜像的方法步骤。

当前rocketmq-dashboard只有一个版本,源码地址如下:

https://dist.apache.org/repos/dist/release/rocketmq/rocketmq-dashboard/1.0.0/rocketmq-dashboard-1.0.0-source-release.zip

1. 编写Dockerfile文件

bash 复制代码
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

FROM centos:7

RUN yum install -y java-1.8.0-openjdk-devel.x86_64 unzip openssl, which gnupg, wget \
 && yum clean all -y

# FROM openjdk:8-jdk
# RUN apt-get update && apt-get install -y --no-install-recommends \
#  bash libapr1 unzip telnet wget gnupg ca-certificates \
# && rm -rf /var/lib/apt/lists/*

ARG user=rocketmq
ARG group=rocketmq
ARG uid=3000
ARG gid=3000

# RocketMQ Dashboard runs with user `rocketmq`, uid = 3000
# If you bind mount a volume from the host or a data container,
# ensure you use the same uid
RUN groupadd -g ${gid} ${group} \
    && useradd -u ${uid} -g ${gid} -m -s /bin/bash ${user}

ARG version

# install maven 3.9.5
ARG MAVEN_VERSION=3.9.5
ARG MAVEN_DOWNLOAD_URL=https://dlcdn.apache.org/maven/maven-3/${MAVEN_VERSION}/binaries/apache-maven-${MAVEN_VERSION}-bin.tar.gz

RUN mkdir -p /usr/share/maven /usr/share/maven/ref && \
    wget -O /tmp/apache-maven.tar.gz ${MAVEN_DOWNLOAD_URL} --no-check-certificate && \
    tar -xzf /tmp/apache-maven.tar.gz -C /usr/share/maven --strip-components=1 && \
    rm -f /tmp/apache-maven.tar.gz && \
    ln -s /usr/share/maven/bin/mvn /usr/bin/mvn
    
### make it faster if remove those "#"s bellow
# RUN sed -i '159i \
#     <mirror> \
#       <id>nexus-tencentyun</id> \
#       <mirrorOf>*</mirrorOf> \
#       <name>Nexus tencentyun</name> \
#       <url>http://mirrors.cloud.tencent.com/nexus/repository/maven-public/</url> \
#     </mirror> \
# ' /usr/share/maven/conf/settings.xml

RUN cat /usr/share/maven/conf/settings.xml

ENV ROCKETMQ_DASHBOARD_VERSION ${version}
ENV ROCKETMQ_DASHBOARD_HOME  /home/rocketmq/rocketmq-dashboard-${ROCKETMQ_DASHBOARD_VERSION}
WORKDIR ${ROCKETMQ_DASHBOARD_HOME}

RUN set -eux; \
    curl -L https://dist.apache.org/repos/dist/release/rocketmq/rocketmq-dashboard/${ROCKETMQ_DASHBOARD_VERSION}/rocketmq-dashboard-${ROCKETMQ_DASHBOARD_VERSION}-source-release.zip -o rocketmq-dashboard.zip; \
    curl -L https://dist.apache.org/repos/dist/release/rocketmq/rocketmq-dashboard/${ROCKETMQ_DASHBOARD_VERSION}/rocketmq-dashboard-${ROCKETMQ_DASHBOARD_VERSION}-source-release.zip.asc -o rocketmq-dashboard.zip.asc; \
    wget https://www.apache.org/dist/rocketmq/KEYS --no-check-certificate; \
    \
    gpg --import KEYS; \
    gpg --batch --verify rocketmq-dashboard.zip.asc rocketmq-dashboard.zip ; \
    unzip rocketmq-dashboard.zip ; \
    rm rocketmq-dashboard.zip rocketmq-dashboard.zip.asc KEYS;
    
RUN cd rocketmq-dashboard-${ROCKETMQ_DASHBOARD_VERSION} ; \
    mvn -DskipTests clean install ;\
    ls -l target ; 


RUN mkdir bin; \
    mv rocketmq-dashboard-${ROCKETMQ_DASHBOARD_VERSION}/target/rocketmq-dashboard-${ROCKETMQ_DASHBOARD_VERSION}.jar bin/ ; \
    mv bin/rocketmq-dashboard-${ROCKETMQ_DASHBOARD_VERSION}.jar bin/rocketmq-dashboard.jar; \
    ls -l bin; \
    rm -rf rocketmq-dashboard-${ROCKETMQ_DASHBOARD_VERSION}
    
RUN rm -rf /root/.m2/repository/*
RUN rm -rf /usr/share/maven
RUN yum remove wget unzip openssl -y

RUN chown -R ${uid}:${gid} ${ROCKETMQ_DASHBOARD_HOME}
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "bin/rocketmq-dashboard.jar"];

这个Dockerfile太繁杂,优化的话考虑使用多阶段构建方式。

2. 编写构建脚本

bash 复制代码
#!/usr/bin/env bash

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

checkVersion() {
    echo "Version = $1"
	echo $1 |grep -E "^[0-9]+\.[0-9]+\.[0-9]+" > /dev/null
    if [ $? = 0 ]; then
        return 1
    fi

	echo "Version $1 illegal, it should be X.X.X format(e.g. 4.5.0), please check released versions in 'https://archive.apache.org/dist/rocketmq/'"
    exit -1
}

if [ $# -lt 2 ]; then
    echo -e "Usage: sh $0 Version BaseImage"
    exit -1
fi

ROCKETMQ_DASHBOARD_VERSION=$1
BASE_IMAGE=$2

checkVersion $ROCKETMQ_DASHBOARD_VERSION

# Build rocketmq
case "${BASE_IMAGE}" in
    centos)
        docker run --privileged --rm harbor.codemiracle.com.cn/baseapp/binfmt:latest --install all
        docker buildx create --use --name=mybuilder-rocketmq-dashboard --driver docker-container --driver-opt image=harbor.codemiracle.com.cn/baseapp/buildkit:master
        docker buildx build --no-cache -f Dockerfile-centos-dashboard --platform=linux/amd64,linux/arm64 -t harbor.codemiracle.com.cn/baseapp/rocketmq-dashboard:${ROCKETMQ_DASHBOARD_VERSION} --build-arg version=${ROCKETMQ_DASHBOARD_VERSION} . --push
        docker buildx rm mybuilder-rocketmq-dashboard
        #docker build --no-cache -f Dockerfile-centos-dashboard -t apache/rocketmq-dashboard:${ROCKETMQ_DASHBOARD_VERSION}-centos --build-arg version=${ROCKETMQ_DASHBOARD_VERSION} .
    ;;
    *)
        echo "${BASE_IMAGE} is not supported, supported base images: centos"
        exit -1
    ;;
esac

3. 如何使用

bash 复制代码
# 如何构建多架构镜像

sh  build-image-dashboard.sh [版本号]  centos

eg:
    sh build-image-dashboard.sh 1.0.0 centos

rocketmq-dashboard是一个可视化管理rocketmq的web界面工具。市面上几乎没有双架构镜像,基本上只有amd64的,通过我这个脚本可以构建支持x86 \ arm 架构的双架构镜像。

相关推荐
卡奥斯开源社区官方41 分钟前
NVIDIA Blackwell架构深度解析:2080亿晶体管如何重构AI算力规则?
人工智能·重构·架构
黄雪超2 小时前
从流批一体到湖仓一体架构演进的思考
大数据·架构·数据湖
周杰伦_Jay5 小时前
【智能体(Agent)技术深度解析】从架构到实现细节,核心是实现“感知环境→处理信息→决策行动→影响环境”的闭环
人工智能·机器学习·微服务·架构·golang·数据挖掘
hweiyu006 小时前
Docker(K8S)容器架构教程(视频教程)
docker·架构·kubernetes
眠りたいです7 小时前
基于脚手架微服务的视频点播系统-客户端业务逻辑处理部分(三)-客户端主体部分完结
c++·微服务·云原生·架构·json·restful·qt6.7
孟祥_成都12 小时前
最好的组件库教程又回来了,升级为 headless 组件库!
前端·面试·架构
绝无仅有13 小时前
某东互联网大厂的Redis面试知识点分析
后端·面试·架构
踏浪无痕14 小时前
RocketMQ本地消息表:生产环境下的分布式事务最佳实践
rocketmq
serendipity_hky14 小时前
【微服务 - easy视频 | day04】Seata解决分布式事务
java·spring boot·分布式·spring cloud·微服务·架构
hour_go16 小时前
DeepHunt微服务故障定位系统核心技术解析1
微服务·云原生·架构