Skip to content

Commit

Permalink
[improve] Allow to build and push multi-arch Docker images (apache#19432
Browse files Browse the repository at this point in the history
)

Co-authored-by: Lari Hotari <[email protected]>
Co-authored-by: Yong Zhang <[email protected]>
Co-authored-by: Zixuan Liu <[email protected]>
Co-authored-by: tison <[email protected]>

(cherry picked from commit 4190e40)
Signed-off-by: Zixuan Liu <[email protected]>
  • Loading branch information
5 people committed Apr 28, 2024
1 parent 0e2a543 commit a0212e7
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 17 deletions.
1 change: 1 addition & 0 deletions build/build_java_test_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ if [[ "$(docker version -f '{{.Server.Experimental}}' 2>/dev/null)" == "true" ]]
SQUASH_PARAM="-Ddocker.squash=true"
fi
mvn -am -pl tests/docker-images/java-test-image -Pcore-modules,-main,integrationTests,docker \
-DUBUNTU_MIRROR="${UBUNTU_MIRROR}" -DUBUNTU_SECURITY_MIRROR="${UBUNTU_SECURITY_MIRROR}" \
-Dmaven.test.skip=true -DskipSourceReleaseAssembly=true -Dspotbugs.skip=true -Dlicense.skip=true $SQUASH_PARAM \
"$@" install
3 changes: 2 additions & 1 deletion build/pulsar_ci_tool.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ function ci_print_thread_dumps() {
}

function _ci_mvn() {
mvn -B -ntp "$@"
mvn -B -ntp -DUBUNTU_MIRROR="${UBUNTU_MIRROR}" -DUBUNTU_SECURITY_MIRROR="${UBUNTU_SECURITY_MIRROR}" \
"$@"
}

# runs OWASP Dependency Check for all projects
Expand Down
42 changes: 35 additions & 7 deletions docker/pulsar-all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@
<profiles>
<profile>
<id>docker</id>
<properties>
<docker.buildArg.PULSAR_IO_DIR>target/apache-pulsar-io-connectors-${project.version}-bin</docker.buildArg.PULSAR_IO_DIR>
<docker.buildArg.PULSAR_OFFLOADER_TARBALL>target/pulsar-offloader-distribution-${project.version}-bin.tar.gz</docker.buildArg.PULSAR_OFFLOADER_TARBALL>
</properties>
<!-- include the docker image only when docker profile is active -->
<dependencies>
<dependency>
Expand Down Expand Up @@ -143,23 +139,55 @@
<configuration>
<images>
<image>
<name>pulsar-all</name>
<name>${docker.organization}/pulsar-all</name>
<build>
<contextDir>${project.basedir}</contextDir>
<tags>
<tag>latest</tag>
<tag>${project.version}</tag>
</tags>
<args>
<PULSAR_IO_DIR>target/apache-pulsar-io-connectors-${project.version}-bin</PULSAR_IO_DIR>
<PULSAR_OFFLOADER_TARBALL>target/pulsar-offloader-distribution-${project.version}-bin.tar.gz</PULSAR_OFFLOADER_TARBALL>
</args>
<buildx>
<platforms>
<platform>${docker.platforms}</platform>
</platforms>
</buildx>
</build>
</image>
</images>
<tagName>latest</tagName>
<repo>${docker.organization}</repo>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

<profile>
<id>docker-push</id>
<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<executions>
<execution>
<id>default</id>
<phase>package</phase>
<goals>
<goal>build</goal>
<goal>tag</goal>
<goal>push</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

</profiles>
</project>
50 changes: 42 additions & 8 deletions docker/pulsar/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@
</dependency>
</dependencies>

<properties>
<UBUNTU_MIRROR>mirror://mirrors.ubuntu.com/mirrors.txt</UBUNTU_MIRROR>
<UBUNTU_SECURITY_MIRROR>http://security.ubuntu.com/ubuntu/</UBUNTU_SECURITY_MIRROR>
</properties>

<profiles>
<profile>
<id>docker</id>
<properties>
<docker.buildArg.PULSAR_TARBALL>target/pulsar-server-distribution-${project.version}-bin.tar.gz</docker.buildArg.PULSAR_TARBALL>
<docker.buildArg.PULSAR_CLIENT_PYTHON_VERSION>${pulsar.client.python.version}</docker.buildArg.PULSAR_CLIENT_PYTHON_VERSION>
<docker.buildArg.UBUNTU_MIRROR>${env.UBUNTU_MIRROR}</docker.buildArg.UBUNTU_MIRROR>
</properties>
<build>
<plugins>
<plugin>
Expand All @@ -71,17 +71,27 @@
<configuration>
<images>
<image>
<name>pulsar</name>
<name>${docker.organization}/pulsar</name>
<build>
<args>
<PULSAR_TARBALL>target/pulsar-server-distribution-${project.version}-bin.tar.gz</PULSAR_TARBALL>
<PULSAR_CLIENT_PYTHON_VERSION>${pulsar.client.python.version}</PULSAR_CLIENT_PYTHON_VERSION>
<UBUNTU_MIRROR>${UBUNTU_MIRROR}</UBUNTU_MIRROR>
<UBUNTU_SECURITY_MIRROR>${UBUNTU_SECURITY_MIRROR}</UBUNTU_SECURITY_MIRROR>
</args>
<contextDir>${project.basedir}</contextDir>
<tags>
<tag>latest</tag>
<tag>${project.version}</tag>
</tags>
<buildx>
<platforms>
<platform>${docker.platforms}</platform>
</platforms>
</buildx>
</build>
</image>
</images>
<tagName>latest</tagName>
<repo>${docker.organization}</repo>
</configuration>
</execution>
</executions>
Expand All @@ -107,5 +117,29 @@
</plugins>
</build>
</profile>

<profile>
<id>docker-push</id>
<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<executions>
<execution>
<id>default</id>
<phase>package</phase>
<goals>
<goal>build</goal>
<goal>tag</goal>
<goal>push</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

</profiles>
</project>
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ flexible messaging model and an intuitive client API.</description>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<redirectTestOutputToFile>true</redirectTestOutputToFile>

<!-- By default build for local Docker platform.
To create multi-arch image, pass -Ddocker.platforms=linux/arm64,linux/amd64
-->
<docker.platforms></docker.platforms>

<test.additional.args></test.additional.args>
<testReuseFork>true</testReuseFork>
<testForkCount>4</testForkCount>
Expand Down Expand Up @@ -129,7 +135,7 @@ flexible messaging model and an intuitive client API.</description>
<reflections.version>0.9.11</reflections.version>
<swagger.version>1.6.10</swagger.version>
<puppycrawl.checkstyle.version>8.37</puppycrawl.checkstyle.version>
<docker-maven.version>0.40.2</docker-maven.version>
<docker-maven.version>0.42.1</docker-maven.version>
<docker.verbose>true</docker.verbose>
<typetools.version>0.5.0</typetools.version>
<byte-buddy.version>1.14.12</byte-buddy.version>
Expand Down
6 changes: 6 additions & 0 deletions tests/docker-images/latest-version-image/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
<phase>package</phase>
<goals>
<goal>build</goal>
<goal>tag</goal>
</goals>
<configuration>
<images>
Expand All @@ -128,6 +129,11 @@
<tag>${project.version}</tag>
</tags>
<noCache>true</noCache>
<buildx>
<platforms>
<platform>${docker.platforms}</platform>
</platforms>
</buildx>
</build>
</image>
</images>
Expand Down

0 comments on commit a0212e7

Please sign in to comment.