This is an automated email from the ASF dual-hosted git repository.

jbonofre pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/karaf.git


The following commit(s) were added to refs/heads/master by this push:
     new f7d9360  Feature/add build docker image multi-platform (OS/Arch) 
(#1160)
f7d9360 is described below

commit f7d9360dcbc44748bbd91217bea7f8a33b265f86
Author: Antonio Musarra <antonio.musa...@gmail.com>
AuthorDate: Thu Aug 27 14:01:17 2020 +0200

    Feature/add build docker image multi-platform (OS/Arch) (#1160)
    
    Able to build docker image for multi-platform (OS/Arch)
---
 assemblies/docker/Dockerfile |  2 +-
 assemblies/docker/README.md  | 55 +++++++++++++++++++++++++++++++++++++++++++-
 assemblies/docker/build.sh   | 31 ++++++++++++++++++++++---
 3 files changed, 83 insertions(+), 5 deletions(-)

diff --git a/assemblies/docker/Dockerfile b/assemblies/docker/Dockerfile
index bc147fb..09fa2ea 100644
--- a/assemblies/docker/Dockerfile
+++ b/assemblies/docker/Dockerfile
@@ -16,7 +16,7 @@
 # limitations under the License.
 
################################################################################
 
-FROM openjdk:8-jre
+FROM adoptopenjdk:11-jre-hotspot
 
 # Karaf environment variables
 ENV KARAF_INSTALL_PATH /opt
diff --git a/assemblies/docker/README.md b/assemblies/docker/README.md
index 0ddf667..fbb2bf6 100644
--- a/assemblies/docker/README.md
+++ b/assemblies/docker/README.md
@@ -26,9 +26,13 @@ https://docs.docker.com/installation/
 Install the most recent stable version of docker-compose
 https://docs.docker.com/compose/install/
 
+If you want to build multi-platform (OS/Arch) Docker images, then you must 
install
+[`buildx`](https://docs.docker.com/buildx/working-with-buildx/).
+On macOS, an easy way to install `buildx` is to install [Docker Desktop 
Edge](https://docs.docker.com/docker-for-mac/edge-release-notes/).
+
 ## Build
 
-Images are based on the official Java Alpine (OpenJDK 8) image. If you want to
+Images are based on the Docker official [AdoptOpenJDK 11 JRE 
Hotspot](https://hub.docker.com/_/adoptopenjdk?tab=tags&page=1&name=11-jre-hotspot)
 image. If you want to
 build the Karaf image run:
 
 ```
@@ -48,6 +52,55 @@ you can configure it with the `KARAF_VERSION` arg:
 docker build --build-arg KARAF_VERSION=4.2.0 -t "karaf:4.2.0" karaf
 ```
 
+If you want to build the container for a specific version of Karaf and
+specific version of the platform, and push the image to the Docker Hub 
repository,
+you can use this command (replacing the version, image name, and targets as 
appropriate):
+
+```
+./build.sh --from-release --karaf-version 4.2.9 --image-name 
amusarra/karaf:4.2.9 \
+ --build-multi-platform linux/arm64,linux/arm/v7,linux/amd64
+```
+
+Below is the output you should get from running the previous command.
+
+```
+Downloading apache-karaf-4.2.9.tar.gz from 
https://downloads.apache.org/karaf/4.2.9/
+Checking if buildx installed...
+Found buildx {github.com/docker/buildx v0.3.1-tp-docker 
6db68d029599c6710a32aa7adcba8e5a344795a7} on your docker system
+Starting build of the docker image for the platform 
linux/arm64,linux/arm/v7,linux/amd64
+[+] Building 15.8s (16/16) FINISHED
+ => [internal] load build definition from Dockerfile                           
                                                                                
              0.0s
+ => => transferring dockerfile: 32B                                            
                                                                                
              0.0s
+ => [internal] load .dockerignore                                              
                                                                                
              0.1s
+ => => transferring context: 2B                                                
                                                                                
              0.0s
+ => [linux/arm64 internal] load metadata for 
docker.io/library/openjdk:8u212-jre-alpine                                      
                                                2.5s
+ => [linux/arm/v7 internal] load metadata for 
docker.io/library/openjdk:8u212-jre-alpine                                      
                                               2.6s
+ => [linux/amd64 internal] load metadata for 
docker.io/library/openjdk:8u212-jre-alpine                                      
                                                2.5s
+ => [linux/amd64 1/3] FROM 
docker.io/library/openjdk:8u212-jre-alpine@sha256:f362b165b870ef129cbe730f29065ff37399c0aa8bcab3e44b51c302938c9193
                                0.0s
+ => => resolve 
docker.io/library/openjdk:8u212-jre-alpine@sha256:f362b165b870ef129cbe730f29065ff37399c0aa8bcab3e44b51c302938c9193
                                            0.0s
+ => [internal] load build context                                              
                                                                                
              1.7s
+ => => transferring context: 22.69MB                                           
                                                                                
              1.7s
+ => [linux/arm64 1/3] FROM 
docker.io/library/openjdk:8u212-jre-alpine@sha256:f362b165b870ef129cbe730f29065ff37399c0aa8bcab3e44b51c302938c9193
                                0.0s
+ => [linux/arm/v7 1/3] FROM 
docker.io/library/openjdk:8u212-jre-alpine@sha256:f362b165b870ef129cbe730f29065ff37399c0aa8bcab3e44b51c302938c9193
                               0.0s
+ => CACHED [linux/arm64 2/3] ADD _TMP_/apache-karaf-4.2.9.tar.gz /opt          
                                                                                
              0.0s
+ => CACHED [linux/arm64 3/3] RUN set -x &&   ln -s /opt/apache-karaf* 
/opt/apache-karaf                                                               
                       0.0s
+ => CACHED [linux/amd64 2/3] ADD _TMP_/apache-karaf-4.2.9.tar.gz /opt          
                                                                                
              0.0s
+ => CACHED [linux/amd64 3/3] RUN set -x &&   ln -s /opt/apache-karaf* 
/opt/apache-karaf                                                               
                       0.0s
+ => CACHED [linux/arm/v7 2/3] ADD _TMP_/apache-karaf-4.2.9.tar.gz /opt         
                                                                                
              0.0s
+ => CACHED [linux/arm/v7 3/3] RUN set -x &&   ln -s /opt/apache-karaf* 
/opt/apache-karaf                                                               
                      0.0s
+ => exporting to image                                                         
                                                                                
             11.4s
+ => => exporting layers                                                        
                                                                                
              0.0s
+ => => exporting manifest 
sha256:205fe4347d83e0183ff479360733d6294a8d060127d5a87ae0e06e1f9b18f08e         
                                                                   0.0s
+ => => exporting config 
sha256:94a9fb41574916225852575d3f1eda6f267d3e83dfc81e262e8a766b5b36e92f         
                                                                     0.0s
+ => => exporting manifest 
sha256:acb94fccec1b975a62b7385cf227e01afb5875d74c24a5bef4546381fd2a483e         
                                                                   0.0s
+ => => exporting config 
sha256:d2b0989d52cd13f19a02f7e88544f1e184bc592178608fd79c88d635f751707a         
                                                                     0.0s
+ => => exporting manifest 
sha256:47c72f3cb18db75f63c21da1e475958580f3d9c935930e1e8b04ccc7ad0e8a37         
                                                                   0.0s
+ => => exporting config 
sha256:13d3f0dc19bec1fec60767a4f5d19750f02401efa0aabc7f83fc318a96eaf660         
                                                                     0.0s
+ => => exporting manifest list 
sha256:341588c548bfe56818c6435d3301fee6e2e6b4b06e5bb94b15102c0ca86a90e9         
                                                              0.0s
+ => => pushing layers                                                          
                                                                                
              3.7s
+ => => pushing manifest for docker.io/amusarra/karaf:4.2.9
+```
+
 ## Run
 
 * Run Karaf with interactive mode
diff --git a/assemblies/docker/build.sh b/assemblies/docker/build.sh
index 3e79174..0277448 100755
--- a/assemblies/docker/build.sh
+++ b/assemblies/docker/build.sh
@@ -21,11 +21,14 @@
 usage() {
   cat <<HERE
 Usage:
-  build.sh --from-local-dist [--archive <archive>] [--image-name <image>]
-  build.sh --from-release --karaf-version <x.x.x> [--image-name <image>]
+  build.sh --from-local-dist [--archive <archive>] [--image-name <image>] 
[--build-multi-platform <comma-separated platforms>]
+  build.sh --from-release --karaf-version <x.x.x> [--image-name <image>] 
[--build-multi-platform <comma-separated platforms>]
   build.sh --help
 
   If the --image-name flag is not used the built image name will be 'karaf'.
+  Check the supported build platforms; you can verify with this command: 
`docker buildx ls`
+  The supported platforms (OS/Arch) depend on the build's base image, in this 
case 
[`openjdk:8u212-jre-alpine`](https://hub.docker.com/_/openjdk?tab=tags&page=1&name=8u212-jre-alpine).
+  
 HERE
   exit 1
 }
@@ -52,6 +55,10 @@ key="$1"
     KARAF_VERSION="$2"
     shift
     ;;
+    --build-multi-platform)
+    BUILD_MULTI_PLATFORM="$2"
+    shift
+    ;;
     --help)
     usage
     ;;
@@ -105,4 +112,22 @@ else
 
 fi
 
-docker build --build-arg karaf_dist="${KARAF_DIST}" -t "${IMAGE_NAME}" .
+if [ -n "${BUILD_MULTI_PLATFORM}" ]; then
+  echo "Checking if buildx installed..."
+  VERSION_BUILD_X=`docker buildx version` > /dev/null 2>&1
+
+  if [ $? -eq 0 ]; then
+    echo "Found buildx {${VERSION_BUILD_X}} on your docker system"
+    echo "Starting build of the docker image for the platform 
${BUILD_MULTI_PLATFORM}"
+    
+    BUILD_X="buildx"
+    BUILD_X_FLAG="--push"
+    BUILD_X_PLATFORM="--platform ${BUILD_MULTI_PLATFORM}"
+  else
+    echo "Error: buildx not installed with your docker system"
+    exit -1
+  fi
+
+fi
+
+docker ${BUILD_X} build ${BUILD_X_PLATFORM} --build-arg 
karaf_dist="${KARAF_DIST}" ${BUILD_X_FLAG} -t "${IMAGE_NAME}" .

Reply via email to