• 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文件

    1. #
    2. # Licensed to the Apache Software Foundation (ASF) under one or more
    3. # contributor license agreements. See the NOTICE file distributed with
    4. # this work for additional information regarding copyright ownership.
    5. # The ASF licenses this file to You under the Apache License, Version 2.0
    6. # (the "License"); you may not use this file except in compliance with
    7. # the License. You may obtain a copy of the License at
    8. #
    9. # http://www.apache.org/licenses/LICENSE-2.0
    10. #
    11. # Unless required by applicable law or agreed to in writing, software
    12. # distributed under the License is distributed on an "AS IS" BASIS,
    13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14. # See the License for the specific language governing permissions and
    15. # limitations under the License.
    16. #
    17. FROM centos:7
    18. RUN yum install -y java-1.8.0-openjdk-devel.x86_64 unzip openssl, which gnupg, wget \
    19. && yum clean all -y
    20. # FROM openjdk:8-jdk
    21. # RUN apt-get update && apt-get install -y --no-install-recommends \
    22. # bash libapr1 unzip telnet wget gnupg ca-certificates \
    23. # && rm -rf /var/lib/apt/lists/*
    24. ARG user=rocketmq
    25. ARG group=rocketmq
    26. ARG uid=3000
    27. ARG gid=3000
    28. # RocketMQ Dashboard runs with user `rocketmq`, uid = 3000
    29. # If you bind mount a volume from the host or a data container,
    30. # ensure you use the same uid
    31. RUN groupadd -g ${gid} ${group} \
    32. && useradd -u ${uid} -g ${gid} -m -s /bin/bash ${user}
    33. ARG version
    34. # install maven 3.9.5
    35. ARG MAVEN_VERSION=3.9.5
    36. ARG MAVEN_DOWNLOAD_URL=https://dlcdn.apache.org/maven/maven-3/${MAVEN_VERSION}/binaries/apache-maven-${MAVEN_VERSION}-bin.tar.gz
    37. RUN mkdir -p /usr/share/maven /usr/share/maven/ref && \
    38. wget -O /tmp/apache-maven.tar.gz ${MAVEN_DOWNLOAD_URL} --no-check-certificate && \
    39. tar -xzf /tmp/apache-maven.tar.gz -C /usr/share/maven --strip-components=1 && \
    40. rm -f /tmp/apache-maven.tar.gz && \
    41. ln -s /usr/share/maven/bin/mvn /usr/bin/mvn
    42. ### make it faster if remove those "#"s bellow
    43. # RUN sed -i '159i \
    44. # \
    45. # nexus-tencentyun \
    46. # * \
    47. # Nexus tencentyun \
    48. # http://mirrors.cloud.tencent.com/nexus/repository/maven-public/ \
    49. # \
    50. # ' /usr/share/maven/conf/settings.xml
    51. RUN cat /usr/share/maven/conf/settings.xml
    52. ENV ROCKETMQ_DASHBOARD_VERSION ${version}
    53. ENV ROCKETMQ_DASHBOARD_HOME /home/rocketmq/rocketmq-dashboard-${ROCKETMQ_DASHBOARD_VERSION}
    54. WORKDIR ${ROCKETMQ_DASHBOARD_HOME}
    55. RUN set -eux; \
    56. 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; \
    57. 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; \
    58. wget https://www.apache.org/dist/rocketmq/KEYS --no-check-certificate; \
    59. \
    60. gpg --import KEYS; \
    61. gpg --batch --verify rocketmq-dashboard.zip.asc rocketmq-dashboard.zip ; \
    62. unzip rocketmq-dashboard.zip ; \
    63. rm rocketmq-dashboard.zip rocketmq-dashboard.zip.asc KEYS;
    64. RUN cd rocketmq-dashboard-${ROCKETMQ_DASHBOARD_VERSION} ; \
    65. mvn -DskipTests clean install ;\
    66. ls -l target ;
    67. RUN mkdir bin; \
    68. mv rocketmq-dashboard-${ROCKETMQ_DASHBOARD_VERSION}/target/rocketmq-dashboard-${ROCKETMQ_DASHBOARD_VERSION}.jar bin/ ; \
    69. mv bin/rocketmq-dashboard-${ROCKETMQ_DASHBOARD_VERSION}.jar bin/rocketmq-dashboard.jar; \
    70. ls -l bin; \
    71. rm -rf rocketmq-dashboard-${ROCKETMQ_DASHBOARD_VERSION}
    72. RUN rm -rf /root/.m2/repository/*
    73. RUN rm -rf /usr/share/maven
    74. RUN yum remove wget unzip openssl -y
    75. RUN chown -R ${uid}:${gid} ${ROCKETMQ_DASHBOARD_HOME}
    76. EXPOSE 8080
    77. ENTRYPOINT ["java", "-jar", "bin/rocketmq-dashboard.jar"];

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

    2. 编写构建脚本

    1. #!/usr/bin/env bash
    2. # Licensed to the Apache Software Foundation (ASF) under one or more
    3. # contributor license agreements. See the NOTICE file distributed with
    4. # this work for additional information regarding copyright ownership.
    5. # The ASF licenses this file to You under the Apache License, Version 2.0
    6. # (the "License"); you may not use this file except in compliance with
    7. # the License. You may obtain a copy of the License at
    8. #
    9. # http://www.apache.org/licenses/LICENSE-2.0
    10. #
    11. # Unless required by applicable law or agreed to in writing, software
    12. # distributed under the License is distributed on an "AS IS" BASIS,
    13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14. # See the License for the specific language governing permissions and
    15. # limitations under the License.
    16. checkVersion() {
    17. echo "Version = $1"
    18. echo $1 |grep -E "^[0-9]+\.[0-9]+\.[0-9]+" > /dev/null
    19. if [ $? = 0 ]; then
    20. return 1
    21. fi
    22. 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/'"
    23. exit -1
    24. }
    25. if [ $# -lt 2 ]; then
    26. echo -e "Usage: sh $0 Version BaseImage"
    27. exit -1
    28. fi
    29. ROCKETMQ_DASHBOARD_VERSION=$1
    30. BASE_IMAGE=$2
    31. checkVersion $ROCKETMQ_DASHBOARD_VERSION
    32. # Build rocketmq
    33. case "${BASE_IMAGE}" in
    34. centos)
    35. docker run --privileged --rm harbor.codemiracle.com.cn/baseapp/binfmt:latest --install all
    36. docker buildx create --use --name=mybuilder-rocketmq-dashboard --driver docker-container --driver-opt image=harbor.codemiracle.com.cn/baseapp/buildkit:master
    37. 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
    38. docker buildx rm mybuilder-rocketmq-dashboard
    39. #docker build --no-cache -f Dockerfile-centos-dashboard -t apache/rocketmq-dashboard:${ROCKETMQ_DASHBOARD_VERSION}-centos --build-arg version=${ROCKETMQ_DASHBOARD_VERSION} .
    40. ;;
    41. *)
    42. echo "${BASE_IMAGE} is not supported, supported base images: centos"
    43. exit -1
    44. ;;
    45. esac

    3. 如何使用

    1. # 如何构建多架构镜像
    2. sh build-image-dashboard.sh [版本号] centos
    3. eg:
    4. sh build-image-dashboard.sh 1.0.0 centos

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

  • 相关阅读:
    Django-图书管理系统(含源码)
    Espresso Test 1: 前言
    Docker安装MongoDB
    栈&队列OJ练习题(C语言版)
    形式化定义软件动态更新
    [数据结构C++实现]二叉搜索树
    《Python+Kivy(App开发)从入门到实践》自学笔记:简单UX部件——Switch开关
    定了!百度WAVE SUMMIT 2024正式定档6月28日
    [C语言] 数据存储
    Spring boot整合Activemq的原理
  • 原文地址:https://blog.csdn.net/qq_34777982/article/details/134188122