Skip to content

Commit eb3db53

Browse files
authored
Build WKO images for AMD and ARM (#4070)
* Build images for multiple architectures and manifest
1 parent 7c3e486 commit eb3db53

File tree

6 files changed

+53
-30
lines changed

6 files changed

+53
-30
lines changed

Dockerfile

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
# Copyright (c) 2017, 2023, Oracle and/or its affiliates.
22
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33
#
4-
# HOW TO BUILD THIS IMAGE
4+
# HOW TO BUILD AND PUSH THIS IMAGE
55
# -----------------------
66
# Run:
7-
# $ ./buildDockerImage.sh [-t <image-name>]
7+
# $ ./buildAndPushImage.sh -t <image-name>
88
#
99
# -------------------------
1010
FROM ghcr.io/oracle/oraclelinux:9-slim AS jre-build
1111

12-
ENV JAVA_URL="https://download.java.net/java/GA/jdk19.0.2/fdb695a9d9064ad6b064dc6df578380c/7/GPL/openjdk-19.0.2_linux-x64_bin.tar.gz"
12+
ENV JAVA_URL_X64="https://download.java.net/java/GA/jdk19.0.2/fdb695a9d9064ad6b064dc6df578380c/7/GPL/openjdk-19.0.2_linux-x64_bin.tar.gz"
13+
ENV JAVA_URL_AARCH64="https://download.java.net/java/GA/jdk19.0.2/fdb695a9d9064ad6b064dc6df578380c/7/GPL/openjdk-19.0.2_linux-aarch64_bin.tar.gz"
1314

1415
RUN set -eux; \
1516
microdnf -y install gzip tar; \
17+
MACHINE_TYPE=`uname -m`; \
18+
if [ ${MACHINE_TYPE} == 'x86_64' ]; then \
19+
JAVA_URL=$JAVA_URL_X64; \
20+
else \
21+
JAVA_URL=$JAVA_URL_AARCH64; \
22+
fi; \
1623
curl -fL -o /jdk.tar.gz "$JAVA_URL"; \
1724
mkdir -p /jdk; \
1825
tar --extract --file /jdk.tar.gz --directory /jdk --strip-components 1; \

buildDockerImage.sh renamed to buildAndPushImage.sh

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@
33
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44

55
usage() {
6-
cat << EOF
6+
cat >&2 << EOF
77
8-
Usage: buildDockerImage.sh [-t tag]
9-
Builds a container image for the Oracle WebLogic Kubernetes Operator.
8+
Usage: buildAndPushImage.sh -t tag
9+
Builds and pushes a container image for the Oracle WebLogic Kubernetes Operator.
1010
1111
Parameters:
1212
-t: image name and tag in 'name:tag' format
1313
14-
Copyright (c) 2020, 2022, Oracle and/or its affiliates.
14+
Copyright (c) 2020, 2023, Oracle and/or its affiliates.
1515
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
1616
1717
EOF
18-
exit 0
1918
}
2019

2120
# WebLogic Kubernetes Operator Image Name
@@ -28,12 +27,15 @@ while getopts "t:" optname; do
2827
name="$OPTARG"
2928
;;
3029
\? )
31-
usage
30+
usage; exit 0
3231
;;
3332
esac
3433
done
3534

36-
IMAGE_NAME=${name:-ghcr.io/oracle/weblogic-kubernetes-operator:4.0.5}
35+
if [ ! "$name" ]; then
36+
echo "-t must be provided"
37+
usage; exit 1
38+
fi
3739
SCRIPTPATH="$( cd "$(dirname "$0")" > /dev/null 2>&1 ; pwd -P )"
3840

3941
# Proxy settings
@@ -59,14 +61,34 @@ if [ "$PROXY_SETTINGS" != "" ]; then
5961
fi
6062

6163
# ################## #
62-
# BUILDING THE IMAGE #
64+
# BUILDING AND PUSHING THE IMAGE #
6365
# ################## #
64-
echo "Building image '$IMAGE_NAME' ..."
66+
echo "Building image '$name' ..."
6567

66-
# BUILD THE IMAGE (replace all environment variables)
68+
# BUILD AND PUSH THE IMAGE (replace all environment variables)
6769
BUILD_START=$(date '+%s')
68-
${WLSIMG_BUILDER:-docker} build $PROXY_SETTINGS -t $IMAGE_NAME -f $SCRIPTPATH/Dockerfile $SCRIPTPATH || {
69-
echo "There was an error building the image."
70+
${WLSIMG_BUILDER:-docker} build $PROXY_SETTINGS --pull --platform linux/amd64 --tag $name-amd64 -f $SCRIPTPATH/Dockerfile $SCRIPTPATH || {
71+
echo "There was an error building the amd64 image."
72+
exit 1
73+
}
74+
${WLSIMG_BUILDER:-docker} push $PROXY_SETTINGS $name-amd64 || {
75+
echo "There was an error pushing the amd64 image."
76+
exit 1
77+
}
78+
${WLSIMG_BUILDER:-docker} build $PROXY_SETTINGS --pull --platform linux/arm64 --tag $name-aarch64 -f $SCRIPTPATH/Dockerfile $SCRIPTPATH || {
79+
echo "There was an error building the aarch64 image."
80+
exit 1
81+
}
82+
${WLSIMG_BUILDER:-docker} push $PROXY_SETTINGS $name-aarch64 || {
83+
echo "There was an error pushing the aarch64 image."
84+
exit 1
85+
}
86+
${WLSIMG_BUILDER:-docker} manifest create $PROXY_SETTINGS $name --amend $name-amd64 --amend $name-aarch64 || {
87+
echo "There was an error building the manifest."
88+
exit 1
89+
}
90+
${WLSIMG_BUILDER:-docker} manifest push $PROXY_SETTINGS $name || {
91+
echo "There was an error pushing the manifest."
7092
exit 1
7193
}
7294
BUILD_END=$(date '+%s')
@@ -78,9 +100,9 @@ if [ $? -eq 0 ]; then
78100
cat << EOF
79101
WebLogic Kubernetes Operator Image is ready:
80102
81-
--> $IMAGE_NAME
103+
--> $name
82104
83-
Build completed in $BUILD_ELAPSED seconds.
105+
Build and push completed in $BUILD_ELAPSED seconds.
84106
85107
EOF
86108
else

documentation/4.0/content/developerguide/building.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ This will compile the source files, build JAR files containing the compiled clas
1818

1919
Contributions must conform to [coding and formatting standards]({{< relref "/developerguide/coding-standards.md" >}}).
2020

21-
#### Building the operator container image
21+
#### Building and pushing the operator container image
2222

2323
These commands should be executed in the project root directory:
2424

2525
```shell
26-
$ ./buildDockerImage.sh -t weblogic-kubernetes-operator:some-tag
26+
$ ./buildAndPushImage.sh -t weblogic-kubernetes-operator:some-tag
2727
```
2828

2929
Replace `<version>` with the version of the project found in the `pom.xml` file in the project root directory.

integration-tests/src/test/java/oracle/weblogic/kubernetes/TestConstants.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ public interface TestConstants {
5050
"../kubernetes/charts/weblogic-operator";
5151
public static final String IMAGE_NAME_OPERATOR =
5252
getNonEmptySystemProperty("wko.it.image.name.operator", "oracle/weblogic-kubernetes-operator");
53-
public static final String OPERATOR_IMAGE_BUILD_SCRIPT =
54-
"../buildDockerImage.sh";
5553
public static final String OPERATOR_SERVICE_NAME = "internal-weblogic-operator-svc";
5654
public static final String OPERATOR_GITHUB_CHART_REPO_URL =
5755
"https://oracle.github.io/weblogic-kubernetes-operator/charts";

integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/Operator.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020, 2022, Oracle and/or its affiliates.
1+
// Copyright (c) 2020, 2023, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package oracle.weblogic.kubernetes.actions.impl;
@@ -9,13 +9,13 @@
99
import oracle.weblogic.kubernetes.actions.impl.primitive.CommandParams;
1010
import oracle.weblogic.kubernetes.actions.impl.primitive.Helm;
1111
import oracle.weblogic.kubernetes.actions.impl.primitive.HelmParams;
12+
import oracle.weblogic.kubernetes.actions.impl.primitive.Image;
1213

1314
import static oracle.weblogic.kubernetes.TestConstants.BUILD_ID;
1415
import static oracle.weblogic.kubernetes.TestConstants.DOMAIN_IMAGES_REPO;
1516
import static oracle.weblogic.kubernetes.TestConstants.IMAGE_NAME_OPERATOR;
1617
import static oracle.weblogic.kubernetes.TestConstants.IMAGE_TAG_OPERATOR;
1718
import static oracle.weblogic.kubernetes.TestConstants.IMAGE_TAG_OPERATOR_FOR_JENKINS;
18-
import static oracle.weblogic.kubernetes.TestConstants.OPERATOR_IMAGE_BUILD_SCRIPT;
1919
import static oracle.weblogic.kubernetes.TestConstants.OPERATOR_RELEASE_NAME;
2020
import static oracle.weblogic.kubernetes.actions.impl.primitive.Kubernetes.getContainerImage;
2121
import static oracle.weblogic.kubernetes.actions.impl.primitive.Kubernetes.patchDeployment;
@@ -94,11 +94,7 @@ public static String getImageName() {
9494
* @return true on success
9595
*/
9696
public static boolean buildImage(String image) {
97-
String command = String.format("%s -t %s", OPERATOR_IMAGE_BUILD_SCRIPT, image);
98-
return Command
99-
.withParams(new CommandParams()
100-
.command(command))
101-
.execute();
97+
return Image.createImage("..", image, "");
10298
}
10399

104100
/**

validateCLI.docker.dat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ dockerFile
2626
dockerconfigjson
2727
/docker/
2828
/docker-images/
29-
"../buildDockerImage.sh"
30-
Usage: buildDockerImage.sh
29+
"../buildAndPushImage.sh"
30+
Usage: buildAndPushImage.sh
3131
docker-container\|ockerContainer\|DockerCluster
3232
contains."BEGIN DOCKERFILE".
3333
--docker-email

0 commit comments

Comments
 (0)