From 5532b2f06a1d138e6103d3a3c67729e6e1e7cf0f Mon Sep 17 00:00:00 2001 From: Zixuan Liu Date: Thu, 4 Jul 2024 14:37:23 +0800 Subject: [PATCH 1/2] improve: build bk and current-version-image images by docker-maven-plugin --- .github/workflows/bk-ci.yml | 4 +- docker/Dockerfile | 58 ++++++---- docker/pom.xml | 107 ++++++++++++++++++ pom.xml | 16 +++ .../current-version-image/Dockerfile | 51 +-------- .../current-version-image/pom.xml | 35 +----- 6 files changed, 164 insertions(+), 107 deletions(-) create mode 100644 docker/pom.xml diff --git a/.github/workflows/bk-ci.yml b/.github/workflows/bk-ci.yml index 1f6ffd652ec..ebaa0d76a73 100644 --- a/.github/workflows/bk-ci.yml +++ b/.github/workflows/bk-ci.yml @@ -238,7 +238,7 @@ jobs: $GITHUB_WORKSPACE/dev/ci-tool pick_ubuntu_mirror - name: Build with Maven - run: mvn -B -nsu clean install -Pdocker -DskipTests + run: mvn -B -nsu clean install -Pdocker -DskipTests -Ddocker.image=bookkeeper-$(date +%s) - name: Run metadata driver tests run: mvn -B -nsu -f metadata-drivers/pom.xml test -DintegrationTests @@ -323,7 +323,7 @@ jobs: $GITHUB_WORKSPACE/dev/ci-tool pick_ubuntu_mirror - name: Build with Maven - run: mvn -B -nsu clean install -Pdocker -DskipTests + run: mvn -B -nsu clean install -Pdocker -DskipTests -Ddocker.image=bookkeeper-$(date +%s) - name: Test current server with old clients run: mvn -B -nsu -DbackwardCompatTests -DfailIfNoTests -pl :backward-compat-current-server-old-clients test diff --git a/docker/Dockerfile b/docker/Dockerfile index a58d0da0c45..17a8fe838a2 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -17,6 +17,37 @@ # under the License. # +FROM alpine:3.20 as bk-dist + +ARG BK_TARBALL + +ARG BK_VERSION=4.17.1 +ARG DISTRO_NAME=bookkeeper-server-${BK_VERSION}-bin +ARG DISTRO_URL=https://archive.apache.org/dist/bookkeeper/bookkeeper-${BK_VERSION}/${DISTRO_NAME}.tar.gz + +COPY . /temp/ +RUN echo $BK_TARBALL +RUN if [ -n "$BK_TARBALL" ] && [ -f "/temp/$BK_TARBALL" ]; then \ + echo "Adding tarball: $BK_TARBALL" \ + && tar -xzf /temp/$BK_TARBALL -C /opt/ \ + && mv /opt/bookkeeper-*/ /opt/bookkeeper/; \ + else \ + # Download Apache Bookkeeper, untar and clean up + echo "Downloading Apache Bookkeeper" \ + && apk update && apk add gpg gpg-agent wget \ + && cd /opt \ + && wget -q "${DISTRO_URL}" \ + && wget -q "${DISTRO_URL}.asc" \ + && wget -q "${DISTRO_URL}.sha512" \ + && sha512sum -c ${DISTRO_NAME}.tar.gz.sha512 \ + && wget -q https://dist.apache.org/repos/dist/release/bookkeeper/KEYS \ + && gpg --import KEYS \ + && gpg --batch --verify "$DISTRO_NAME.tar.gz.asc" "$DISTRO_NAME.tar.gz" \ + && tar -xzf "$DISTRO_NAME.tar.gz" \ + && mv bookkeeper-server-${BK_VERSION}/ /opt/bookkeeper/ \ + && rm -rf "$DISTRO_NAME.tar.gz" "$DISTRO_NAME.tar.gz.asc" "$DISTRO_NAME.tar.gz.sha512"; \ + fi + FROM eclipse-temurin:17 as jre-build # Create a custom Java runtime @@ -34,21 +65,16 @@ RUN echo networkaddress.cache.negative.ttl=1 >> /javaruntime/conf/security/java. FROM ubuntu:22.04 MAINTAINER Apache BookKeeper -ARG TARGETARCH -ARG BK_VERSION=4.17.1 -ARG DISTRO_NAME=bookkeeper-server-${BK_VERSION}-bin -ARG DISTRO_URL=https://archive.apache.org/dist/bookkeeper/bookkeeper-${BK_VERSION}/${DISTRO_NAME}.tar.gz - ENV BOOKIE_PORT=3181 ENV BOOKIE_HTTP_PORT=8080 -EXPOSE $BOOKIE_PORT $BOOKIE_HTTP_PORT +ENV BOOKIE_GRPC_PORT=4181 +EXPOSE $BOOKIE_PORT $BOOKIE_HTTP_PORT $BOOKIE_GRPC_PORT ENV BK_USER=bookkeeper ENV BK_HOME=/opt/bookkeeper ENV DEBIAN_FRONTEND=noninteractive ARG UBUNTU_MIRROR=http://archive.ubuntu.com/ubuntu/ ARG UBUNTU_SECURITY_MIRROR=http://security.ubuntu.com/ubuntu/ -# Download Apache Bookkeeper, untar and clean up RUN set -x \ && sed -i -e "s|http://archive\.ubuntu\.com/ubuntu/|${UBUNTU_MIRROR:-http://archive.ubuntu.com/ubuntu/}|g" \ -e "s|http://security\.ubuntu\.com/ubuntu/|${UBUNTU_SECURITY_MIRROR:-http://security.ubuntu.com/ubuntu/}|g" /etc/apt/sources.list \ @@ -58,31 +84,19 @@ RUN set -x \ && apt-get install -y ca-certificates apt-transport-https \ && apt-get install -y --no-install-recommends python3 pip \ && ln -s /usr/bin/python3 /usr/bin/python \ - && apt-get install -y --no-install-recommends gpg gpg-agent wget sudo \ + && apt-get install -y --no-install-recommends wget sudo \ && apt-get -y --purge autoremove \ && apt-get autoclean \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* \ - && mkdir -pv /opt \ - && cd /opt \ - && wget -q "${DISTRO_URL}" \ - && wget -q "${DISTRO_URL}.asc" \ - && wget -q "${DISTRO_URL}.sha512" \ - && sha512sum -c ${DISTRO_NAME}.tar.gz.sha512 \ - && wget https://dist.apache.org/repos/dist/release/bookkeeper/KEYS \ - && gpg --import KEYS \ - && gpg --batch --verify "$DISTRO_NAME.tar.gz.asc" "$DISTRO_NAME.tar.gz" \ - && tar -xzf "$DISTRO_NAME.tar.gz" \ - && mv bookkeeper-server-${BK_VERSION}/ /opt/bookkeeper/ \ - && rm -rf "$DISTRO_NAME.tar.gz" "$DISTRO_NAME.tar.gz.asc" "$DISTRO_NAME.tar.gz.sha512" \ && pip install zk-shell -WORKDIR /opt/bookkeeper - ENV JAVA_HOME=/opt/java/openjdk ENV PATH="$PATH:$JAVA_HOME/bin" COPY --from=jre-build /javaruntime $JAVA_HOME +WORKDIR /opt/bookkeeper +COPY --from=bk-dist /opt/bookkeeper /opt/bookkeeper COPY scripts /opt/bookkeeper/scripts RUN chmod +x -R /opt/bookkeeper/scripts/ diff --git a/docker/pom.xml b/docker/pom.xml new file mode 100644 index 00000000000..b7d954ee724 --- /dev/null +++ b/docker/pom.xml @@ -0,0 +1,107 @@ + + + + pom + 4.0.0 + + org.apache.bookkeeper + bookkeeper + 4.18.0-SNAPSHOT + + docker-images + Apache BookKeeper :: Docker Images + + + + org.apache.bookkeeper + bookkeeper-dist-server + ${project.parent.version} + bin + tar.gz + provided + + + + + + docker + + + + io.fabric8 + docker-maven-plugin + + + default + package + + build + push + + + + + ${docker.organization}/${docker.image} + + + ${project.version} + target/bookkeeper-dist-server-${project.version}-bin.tar.gz + ${UBUNTU_MIRROR} + ${UBUNTU_SECURITY_MIRROR} + + ${project.basedir} + + ${docker.tag} + + + + ${docker.platforms} + + + + + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-docker-dependencies + + copy-dependencies + + generate-resources + + ${project.build.directory}/ + bookkeeper-dist-server + true + + + + + + + + + + diff --git a/pom.xml b/pom.xml index 1651bfcac71..76089ad176c 100644 --- a/pom.xml +++ b/pom.xml @@ -68,6 +68,7 @@ shaded microbenchmarks bookkeeper-slogger + docker tests native-io testtools @@ -204,6 +205,16 @@ 1.26.0 http://archive.ubuntu.com/ubuntu/ http://security.ubuntu.com/ubuntu/ + + + 0.44.0 + true + true + apache + bookkeeper:latest + + + @@ -1347,6 +1358,11 @@ ${maven.compiler.release} + + io.fabric8 + docker-maven-plugin + ${docker-maven-plugin.version} + diff --git a/tests/docker-images/current-version-image/Dockerfile b/tests/docker-images/current-version-image/Dockerfile index 0e489eb5ea6..af10873973e 100644 --- a/tests/docker-images/current-version-image/Dockerfile +++ b/tests/docker-images/current-version-image/Dockerfile @@ -17,59 +17,12 @@ # under the License. # -FROM ubuntu:22.04 -MAINTAINER Apache BookKeeper +ARG BK_IMAGE +FROM $BK_IMAGE -ARG BK_VERSION=DOESNOTEXISTS -ARG DISTRO_NAME=bookkeeper-dist-server-${BK_VERSION}-bin -ARG PKG_NAME=bookkeeper-server-${BK_VERSION} - -ENV BOOKIE_PORT=3181 -ENV BOOKIE_HTTP_PORT=8080 -ENV BOOKIE_GRPC_PORT=4181 -EXPOSE ${BOOKIE_PORT} ${BOOKIE_HTTP_PORT} ${BOOKIE_GRPC_PORT} -ENV BK_USER=bookkeeper -ENV BK_HOME=/opt/bookkeeper -ENV DEBIAN_FRONTEND=noninteractive -ARG UBUNTU_MIRROR=http://archive.ubuntu.com/ubuntu/ -ARG UBUNTU_SECURITY_MIRROR=http://security.ubuntu.com/ubuntu/ - -RUN set -x \ - && sed -i -e "s|http://archive\.ubuntu\.com/ubuntu/|${UBUNTU_MIRROR:-http://archive.ubuntu.com/ubuntu/}|g" \ - -e "s|http://security\.ubuntu\.com/ubuntu/|${UBUNTU_SECURITY_MIRROR:-http://security.ubuntu.com/ubuntu/}|g" /etc/apt/sources.list \ - && echo 'Acquire::http::Timeout "30";\nAcquire::http::ConnectionAttemptDelayMsec "2000";\nAcquire::https::Timeout "30";\nAcquire::https::ConnectionAttemptDelayMsec "2000";\nAcquire::ftp::Timeout "30";\nAcquire::ftp::ConnectionAttemptDelayMsec "2000";\nAcquire::Retries "15";' > /etc/apt/apt.conf.d/99timeout_and_retries \ - && adduser "${BK_USER}" \ - && apt-get update \ - && apt-get install -y ca-certificates apt-transport-https \ - && apt-get install -y --no-install-recommends openjdk-17-jdk \ - && apt-get install -y --no-install-recommends python3 pip \ - && ln -s /usr/bin/python3 /usr/bin/python \ - && apt-get install -y --no-install-recommends gpg gpg-agent wget sudo \ - && apt-get -y install netcat dnsutils less procps iputils-ping \ - && apt-get -y --purge autoremove \ - && apt-get autoclean \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists/* \ - && pip install zk-shell \ - && JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java)))) \ - && echo networkaddress.cache.ttl=1 >> $JAVA_HOME/conf/security/java.security \ - && echo networkaddress.cache.negative.ttl=1 >> $JAVA_HOME/conf/security/java.security - -# untar tarballs -ADD target/${DISTRO_NAME}.tar.gz /opt -RUN mv /opt/${PKG_NAME} /opt/bookkeeper - -WORKDIR /opt/bookkeeper - -COPY target/scripts /opt/bookkeeper/scripts COPY scripts/install-python-client.sh /opt/bookkeeper/scripts RUN chmod +x -R /opt/bookkeeper/scripts/ # copy the python client ADD target/bookkeeper-client/ /opt/bookkeeper/bookkeeper-client RUN /opt/bookkeeper/scripts/install-python-client.sh - -ENTRYPOINT [ "/bin/bash", "/opt/bookkeeper/scripts/entrypoint.sh" ] -CMD ["bookie"] - -#HEALTHCHECK --interval=10s --timeout=60s CMD /bin/bash /opt/bookkeeper/scripts/healthcheck.sh diff --git a/tests/docker-images/current-version-image/pom.xml b/tests/docker-images/current-version-image/pom.xml index 36130533847..6204d285fb0 100644 --- a/tests/docker-images/current-version-image/pom.xml +++ b/tests/docker-images/current-version-image/pom.xml @@ -26,16 +26,6 @@ current-version-image Apache BookKeeper :: Tests :: Docker Images :: Current Version pom - - - org.apache.bookkeeper - bookkeeper-dist-server - ${project.parent.version} - bin - tar.gz - provided - - docker @@ -81,9 +71,6 @@ copy python wheel file - copying docker scripts - - @@ -117,30 +104,10 @@ false true - ${project.version} - ${UBUNTU_MIRROR} - ${UBUNTU_SECURITY_MIRROR} + ${docker.image} - - org.apache.maven.plugins - maven-dependency-plugin - - - copy-docker-dependencies - - copy-dependencies - - generate-resources - - ${project.build.directory}/ - bookkeeper-dist-server - true - - - - From a6d9bc72c001d709f0fb70ef74d39089663e3991 Mon Sep 17 00:00:00 2001 From: Zixuan Liu Date: Thu, 4 Jul 2024 15:12:18 +0800 Subject: [PATCH 2/2] Fix BK_IMAGE --- tests/docker-images/current-version-image/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/docker-images/current-version-image/pom.xml b/tests/docker-images/current-version-image/pom.xml index 6204d285fb0..b72e96e0292 100644 --- a/tests/docker-images/current-version-image/pom.xml +++ b/tests/docker-images/current-version-image/pom.xml @@ -104,7 +104,7 @@ false true - ${docker.image} + ${docker.organization}/${docker.image}