Skip to content

Commit

Permalink
Use "docker buildx" for multi-platform builds.
Browse files Browse the repository at this point in the history
This supports linux/amd64 and linux/arm64 for now.

Fixes #253 #287 #389
  • Loading branch information
afranken committed Jan 31, 2022
1 parent 465fa4f commit f6436a1
Show file tree
Hide file tree
Showing 6 changed files with 195 additions and 7 deletions.
22 changes: 22 additions & 0 deletions docker/build-docker-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh
#
# Copyright 2017-2022 Adobe.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.
#

BUILDER_NAME=$1
VERSIONED_TAG_NAME=$2
LATEST_TAG_NAME=$3

docker buildx build --load --tag "${VERSIONED_TAG_NAME}" --tag "${LATEST_TAG_NAME}" --builder "${BUILDER_NAME}" .
107 changes: 100 additions & 7 deletions docker/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,69 @@
<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>start-buildkit</id>
<phase>prepare-package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>sh</executable>
<arguments>
<argument>start-buildkit.sh</argument>
<argument>${docker-builder.image.name}</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>build-docker-image</id>
<phase>package</phase>
<goals>
<goal>build</goal>
<goal>exec</goal>
</goals>
<configuration>
<executable>sh</executable>
<arguments>
<argument>build-docker-image.sh</argument>
<argument>${docker-builder.image.name}</argument>
<!-- Versioned tag name -->
<argument>${docker.image.name}:${project.version}</argument>
<!-- Latest tag name -->
<argument>${docker.image.name}:latest</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>stop-builder-container</id>
<phase>install</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>sh</executable>
<arguments>
<argument>stop-buildkit.sh</argument>
<argument>${docker-builder.image.name}</argument>
</arguments>
</configuration>
</execution>
</executions>
<configuration>
<includeProjectDependencies>true</includeProjectDependencies>
<includePluginDependencies>false</includePluginDependencies>
</configuration>
<dependencies>
<dependency>
<groupId>com.adobe.testing</groupId>
<artifactId>s3mock</artifactId>
<classifier>exec</classifier>
<version>${project.version}</version>
<type>jar</type>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
Expand All @@ -133,15 +185,56 @@
<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<!-- Declare start/stop here again as we can't be sure if the regular stop goal was
executed before the "push-docker-image" goal. -->
<execution>
<id>start-buildkit</id>
<phase>prepare-package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>sh</executable>
<arguments>
<argument>start-buildkit.sh</argument>
<argument>${docker-builder.image.name}</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>push-docker-image</id>
<phase>install</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>sh</executable>
<arguments>
<argument>push-docker-image.sh</argument>
<argument>${docker-builder.image.name}</argument>
<!-- Versioned tag name -->
<argument>${docker.image.name}:${project.version}</argument>
<!-- Latest tag name -->
<argument>${docker.image.name}:latest</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>tag-docker-image-commit-id</id>
<id>stop-builder-container</id>
<phase>install</phase>
<goals>
<goal>push</goal>
<goal>exec</goal>
</goals>
<configuration>
<executable>sh</executable>
<arguments>
<argument>stop-buildkit.sh</argument>
<argument>${docker-builder.image.name}</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
Expand Down
22 changes: 22 additions & 0 deletions docker/push-docker-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh
#
# Copyright 2017-2022 Adobe.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.
#

BUILDER_NAME=$1
VERSIONED_TAG_NAME=$2
LATEST_TAG_NAME=$3

docker buildx build --platform linux/amd64,linux/arm64 --push --tag "${VERSIONED_TAG_NAME}" --tag "${LATEST_TAG_NAME}" --builder "${BUILDER_NAME}" .
23 changes: 23 additions & 0 deletions docker/start-buildkit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh
#
# Copyright 2017-2022 Adobe.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.
#

BUILDER_NAME=$1

if [ "$(docker buildx ls | grep ${BUILDER_NAME} | wc -l)" -eq 0 ]; then \
docker buildx create --driver docker-container --name "${BUILDER_NAME}" ; \
docker buildx inspect --bootstrap --builder "${BUILDER_NAME}" ; \
fi
22 changes: 22 additions & 0 deletions docker/stop-buildkit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh
#
# Copyright 2017-2022 Adobe.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.
#

BUILDER_NAME=$1

if [ "$(docker buildx ls | grep ${BUILDER_NAME} | wc -l)" -gt 0 ]; then \
docker buildx rm "${BUILDER_NAME}" ; \
fi
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<java.version>8</java.version>

<docker.image.name>adobe/s3mock</docker.image.name>
<docker-builder.image.name>s3mock-buildx</docker-builder.image.name>
<!-- Run Docker build by default -->
<skipDocker>false</skipDocker>

Expand Down Expand Up @@ -202,6 +203,11 @@
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<version>${maven-enforcer-plugin.version}</version>
Expand Down

0 comments on commit f6436a1

Please sign in to comment.