rocketmq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vongosl...@apache.org
Subject [rocketmq-docker] 21/50: Feat(Dockerfile): support openjdk-alpine as base image to provide light-weight image version
Date Tue, 03 Dec 2019 13:50:44 GMT
This is an automated email from the ASF dual-hosted git repository.

vongosling pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-docker.git

commit 6a542ddbdb663085e8c912d2dc7d903c9e5422d1
Author: liuruiyiyang <245422695@qq.com>
AuthorDate: Wed Aug 7 17:01:42 2019 +0800

    Feat(Dockerfile): support openjdk-alpine as base image to provide light-weight image version
---
 README.md                                       |  6 ++--
 image-build/Dockerfile-alpine                   | 39 ++++++++++++-------------
 image-build/build-image.sh                      | 39 ++++++++++++++++++++-----
 image-build/scripts/runbroker-customize.sh      |  4 +--
 image-build/scripts/runserver-customize.sh      |  4 +--
 product/conf/2m-noslave/broker-trace.properties |  2 --
 stage.sh                                        | 21 +++++++++----
 7 files changed, 72 insertions(+), 43 deletions(-)

diff --git a/README.md b/README.md
index ec46e17..40fa54c 100644
--- a/README.md
+++ b/README.md
@@ -22,10 +22,10 @@ Note: This is an experimented code to allow users to build docker image
locally
 
 ```
 cd image-build
-sh build-image.sh RMQ-VERSION
+sh build-image.sh RMQ-VERSION BASE-IMAGE
 ```
 
-Tip: The supported RMQ-VERSIONs can be obtained from [here](https://dist.apache.org/repos/dist/release/rocketmq/)
+> Tip: The supported RMQ-VERSIONs can be obtained from [here](https://dist.apache.org/repos/dist/release/rocketmq/).
The supported BASE-IMAGEs are [centos, alpine]. For example: ```sh build-image.sh 4.5.0 alpine```
 
 ### B. Stage a specific version
 
@@ -44,7 +44,7 @@ Run:
 ```
 cd stages/4.5.0 
 
-./play-docker.sh
+./play-docker.sh alpine
 
 ```
 > NOTE:
diff --git a/image-build/Dockerfile-alpine b/image-build/Dockerfile-alpine
index b810dc6..6145021 100644
--- a/image-build/Dockerfile-alpine
+++ b/image-build/Dockerfile-alpine
@@ -15,15 +15,9 @@
 # limitations under the License.
 #
 
-FROM centos:7
+FROM openjdk:8-alpine
 
-RUN yum install -y java-1.8.0-openjdk-devel.x86_64 unzip gettext nmap-ncat openssl, which
gnupg, telnet \
- && 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/*
+RUN apk add --no-cache bash gettext nmap-ncat openssl busybox-extras
 
 ARG user=rocketmq
 ARG group=rocketmq
@@ -33,8 +27,8 @@ ARG gid=3000
 # RocketMQ is run 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}
+RUN addgroup --gid ${gid} ${group} \
+    && adduser --uid ${uid} -G ${group} ${user} -s /bin/bash -D
 
 ARG version
 
@@ -46,41 +40,46 @@ ENV ROCKETMQ_HOME  /home/rocketmq/rocketmq-${ROCKETMQ_VERSION}
 
 WORKDIR  ${ROCKETMQ_HOME}
 
+# Install
 RUN set -eux; \
+    apk add --virtual .build-deps curl gnupg unzip; \
     curl https://dist.apache.org/repos/dist/release/rocketmq/${ROCKETMQ_VERSION}/rocketmq-all-${ROCKETMQ_VERSION}-bin-release.zip
-o rocketmq.zip; \
     curl https://dist.apache.org/repos/dist/release/rocketmq/${ROCKETMQ_VERSION}/rocketmq-all-${ROCKETMQ_VERSION}-bin-release.zip.asc
-o rocketmq.zip.asc; \
     #https://www.apache.org/dist/rocketmq/KEYS
 	curl https://www.apache.org/dist/rocketmq/KEYS -o KEYS; \
 	\
 	gpg --import KEYS; \
-    gpg --batch --verify rocketmq.zip.asc rocketmq.zip ; \
-    unzip rocketmq.zip ; \
+    gpg --batch --verify rocketmq.zip.asc rocketmq.zip; \
+    unzip rocketmq.zip; \
 	mv rocketmq-all*/* . ; \
-	rmdir rocketmq-all*  ; \
-	rm rocketmq.zip rocketmq.zip.asc KEYS
+	rmdir rocketmq-all* ; \
+	rm rocketmq.zip rocketmq.zip.asc KEYS; \
+	apk del .build-deps ; \
+    rm -rf /var/cache/apk/* ; \
+    rm -rf /tmp/*
 
-# add scripts
+# Copy customized scripts
 COPY scripts/ ${ROCKETMQ_HOME}/bin/
 
 RUN chown -R ${uid}:${gid} ${ROCKETMQ_HOME}
 
-# expose namesrv port
+# Expose namesrv port
 EXPOSE 9876
 
-# add customized scripts for namesrv
+# Override customized scripts for namesrv
 RUN mv ${ROCKETMQ_HOME}/bin/runserver-customize.sh ${ROCKETMQ_HOME}/bin/runserver.sh \
  && chmod a+x ${ROCKETMQ_HOME}/bin/runserver.sh \
  && chmod a+x ${ROCKETMQ_HOME}/bin/mqnamesrv
 
-# expose broker ports
+# Expose broker ports
 EXPOSE 10909 10911 10912
 
-# add customized scripts for broker
+# Override customized scripts for broker
 RUN mv ${ROCKETMQ_HOME}/bin/runbroker-customize.sh ${ROCKETMQ_HOME}/bin/runbroker.sh \
  && chmod a+x ${ROCKETMQ_HOME}/bin/runbroker.sh \
  && chmod a+x ${ROCKETMQ_HOME}/bin/mqbroker
 
-# export Java options
+# Export Java options
 RUN export JAVA_OPT=" -Duser.home=/opt"
 
 # Add ${JAVA_HOME}/lib/ext as java.ext.dirs
diff --git a/image-build/build-image.sh b/image-build/build-image.sh
index 59891ab..3faefcd 100755
--- a/image-build/build-image.sh
+++ b/image-build/build-image.sh
@@ -15,16 +15,39 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-if [ $# -lt 1 ]; then
-    echo "Usage: sh $0 version#"
+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://dist.apache.org/repos/dist/release/rocketmq/'"
     exit -1
-fi
+}
 
-ROCKETMQ_VERSION=${1}
-if [ -z "${ROCKETMQ_VERSION}" ]
-then
-  ROCKETMQ_VERSION="4.5.0"
+if [ $# -lt 2 ]; then
+    echo -e "Usage: sh $0 Version BaseImage"
+    exit -1
 fi
 
+ROCKETMQ_VERSION=$1
+BASE_IMAGE=$2
+
+checkVersion $ROCKETMQ_VERSION
+
 # Build rocketmq
-docker build --no-cache -t rocketmqinc/rocketmq:${ROCKETMQ_VERSION} --build-arg version=${ROCKETMQ_VERSION}
.
+case "${BASE_IMAGE}" in
+    alpine)
+        docker build --no-cache -f Dockerfile-alpine -t rocketmqinc/rocketmq:${ROCKETMQ_VERSION}-alpine
--build-arg version=${ROCKETMQ_VERSION} .
+    ;;
+    centos)
+        docker build --no-cache -f Dockerfile-centos -t rocketmqinc/rocketmq:${ROCKETMQ_VERSION}
--build-arg version=${ROCKETMQ_VERSION} .
+    ;;
+    *)
+        echo "${BASE_IMAGE} is not supported, supported base images: centos, alpine"
+        exit -1
+    ;;
+esac
+
diff --git a/image-build/scripts/runbroker-customize.sh b/image-build/scripts/runbroker-customize.sh
index cf82645..8ae360f 100755
--- a/image-build/scripts/runbroker-customize.sh
+++ b/image-build/scripts/runbroker-customize.sh
@@ -63,13 +63,13 @@ then
 	elif [ "$CAL_UNIT" == "K" -o "$CAL_UNIT" == "k" ]; then
 		MAX_POSSIBLE_RAM=$(echo ${MAX_POSSIBLE_RAM_STR:0:${#MAX_POSSIBLE_RAM_STR}-1} `expr 1 \*
1024` | awk '{printf "%d",$1*$2}')
 	fi
-	MAX_POSSIBLE_HEAP=$[MAX_POSSIBLE_RAM/4]
+	MAX_POSSIBLE_HEAP=`expr $MAX_POSSIBLE_RAM / 4`
 fi
 
 # Dynamically calculate parameters, for reference.
 Xms=$MAX_POSSIBLE_HEAP
 Xmx=$MAX_POSSIBLE_HEAP
-Xmn=$[MAX_POSSIBLE_HEAP/2]
+Xmn=`expr $MAX_POSSIBLE_HEAP / 2`
 MaxDirectMemorySize=$MAX_POSSIBLE_HEAP
 # Set for `JAVA_OPT`.
 JAVA_OPT="${JAVA_OPT} -server -Xms${Xms} -Xmx${Xmx} -Xmn${Xmn}"
diff --git a/image-build/scripts/runserver-customize.sh b/image-build/scripts/runserver-customize.sh
index 7135b6b..0b76aa2 100755
--- a/image-build/scripts/runserver-customize.sh
+++ b/image-build/scripts/runserver-customize.sh
@@ -63,13 +63,13 @@ then
 	elif [ "$CAL_UNIT" == "K" -o "$CAL_UNIT" == "k" ]; then
 		MAX_POSSIBLE_RAM=$(echo ${MAX_POSSIBLE_RAM_STR:0:${#MAX_POSSIBLE_RAM_STR}-1} `expr 1 \*
1024` | awk '{printf "%d",$1*$2}')
 	fi
-	MAX_POSSIBLE_HEAP=$[MAX_POSSIBLE_RAM/4]
+	MAX_POSSIBLE_HEAP=`expr $MAX_POSSIBLE_RAM / 4`
 fi
 
 # Dynamically calculate parameters, for reference.
 Xms=$MAX_POSSIBLE_HEAP
 Xmx=$MAX_POSSIBLE_HEAP
-Xmn=$[MAX_POSSIBLE_HEAP/2]
+Xmn=`expr $MAX_POSSIBLE_HEAP / 2`
 # Set for `JAVA_OPT`.
 JAVA_OPT="${JAVA_OPT} -server -Xms${Xms} -Xmx${Xmx} -Xmn${Xmn}"
 JAVA_OPT="${JAVA_OPT} -XX:+UseConcMarkSweepGC -XX:+UseCMSCompactAtFullCollection -XX:CMSInitiatingOccupancyFraction=70
-XX:+CMSParallelRemarkEnabled -XX:SoftRefLRUPolicyMSPerMB=0 -XX:+CMSClassUnloadingEnabled
-XX:SurvivorRatio=8  -XX:-UseParNewGC"
diff --git a/product/conf/2m-noslave/broker-trace.properties b/product/conf/2m-noslave/broker-trace.properties
index 966bb5f..fe1c82f 100644
--- a/product/conf/2m-noslave/broker-trace.properties
+++ b/product/conf/2m-noslave/broker-trace.properties
@@ -1,4 +1,3 @@
-#
 # 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.
@@ -13,7 +12,6 @@
 # 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.
-#
 brokerClusterName=DefaultCluster
 brokerName=broker-trace
 brokerId=0
diff --git a/stage.sh b/stage.sh
index dbf24f4..652d160 100644
--- a/stage.sh
+++ b/stage.sh
@@ -15,7 +15,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-function checkVersion()        
+checkVersion()
 {
     echo "Stage version = $1"
 	echo $1 |grep -E "^[0-9]+\.[0-9]+\.[0-9]+" > /dev/null
@@ -50,9 +50,18 @@ cp -rf "$CURRENT_DIR/templates/" "$STAGE_DIR/$version"
 
 echo "staged templates into folder $STAGE_DIR/$version"
 
-# Stage the real version
-# todo fix on linux (sed)
-#find "$STAGE_DIR/$version" -type f -exec sed -i "" "s/ROCKETMQ_VERSION/${version}/g" {}
\;
-find "$STAGE_DIR/$version" -type f | xargs perl -pi -e "s/ROCKETMQ_VERSION/${version}/g"
+# Replace ROCKETMQ_VERSION with real version string in all files under $STAGE_DIR/$version
+replace_version()
+{
+    case "`uname`" in
+        Darwin)
+            find "$STAGE_DIR/$version" -type f | xargs perl -pi -e "s/ROCKETMQ_VERSION/${version}/g"
+        ;;
+        *)
+            #sed -i "s/ROCKETMQ_VERSION/${version}/g"  `grep ROCKETMQ_VERSION -rl $STAGE_DIR/$version/template`
+            find "$STAGE_DIR/$version/template" -type f | xargs perl -pi -e "s/ROCKETMQ_VERSION/${version}/g"
+        ;;
+    esac
+}
 
-cd $STAGE_DIR
+replace_version
\ No newline at end of file


Mime
View raw message