-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add OpenSearch/Dashboards Multi-Arch Docker Images (#98)
* Add JAVA_HOME fixes for the docker opensearch images Signed-off-by: Peter Zhu <[email protected]> * Docker multi-arch script setup 1st commit Signed-off-by: Peter Zhu <[email protected]> * Tweak arch retrieval methods in dockerfiles here Signed-off-by: Peter Zhu <[email protected]> * Resolve the param checks and complete the README Signed-off-by: Peter Zhu <[email protected]> * Update comments by removing duplicate ones Signed-off-by: Peter Zhu <[email protected]> * Replace || with && for arch and product checks Signed-off-by: Peter Zhu <[email protected]>
- Loading branch information
1 parent
680bdc6
commit aed7794
Showing
5 changed files
with
258 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
## OpenSearch/Dashboards Docker Build README | ||
|
||
### Summary | ||
We support building OpenSearch/Dashboards docker images with [multi-CPU architecture support](https://docs.docker.com/desktop/multi-arch/). | ||
We also support old school single CPU architecture build as well. | ||
Users are welcome to choose either type of the image to build on their local development environment, or directly pulling existing images published on Docker Hub: | ||
|
||
[OpenSearch Docker Repository](https://hub.docker.com/r/opensearchproject/opensearch/) | ||
|
||
[OpenSearch-Dashboards Docker Repository](https://hub.docker.com/r/opensearchproject/opensearch-dashboards/) | ||
|
||
``` | ||
docker pull opensearchproject/opensearch:latest | ||
docker pull opensearchproject/opensearch-dashboards:latest | ||
``` | ||
|
||
### Building docker images | ||
We provide two scripts to build docker images. | ||
For single-arch image you need to install just the Docker Engine on your host machine. | ||
For multi-arch image (currently support x64/arm64) you need to install Docker Desktop. | ||
|
||
* Install Docker through the official docker webpage: https://docs.docker.com/get-docker/ | ||
|
||
* After installation, verify whether or not you have Docker Engine by running: | ||
``` | ||
docker build --help | ||
``` | ||
|
||
* Verify if you have Docker Desktop by running: | ||
``` | ||
docker buildx --help | ||
``` | ||
|
||
* You need to run both script within the `opensearch-build/release/docker` folder. Running them | ||
within other path would cause the scripts to fail. | ||
|
||
* Build single-arch image with these command: | ||
* OpenSearch 1.0.0 x64: | ||
``` | ||
./build-image-single-arch.sh -v 1.0.0 -f ./dockerfiles/opensearch.al2.dockerfile -p opensearch -a x64 | ||
``` | ||
* OpenSearch 1.0.0 arm64 with local tarball: | ||
``` | ||
./build-image-single-arch.sh -v 1.0.0 -f ./dockerfiles/opensearch.al2.dockerfile -p opensearch -a arm64 -t opensearch-1.0.0.tar.gz | ||
``` | ||
* OpenSearch-Dashboards 1.0.0 x64: | ||
``` | ||
./build-image-single-arch.sh -v 1.0.0 -f ./dockerfiles/opensearch-dashboards.al2.dockerfile -p opensearch-dashboards -a x64 | ||
``` | ||
* OpenSearch-Dashboards 1.0.0 arm64 with local tarball: | ||
``` | ||
./build-image-single-arch.sh -v 1.0.0 -f ./dockerfiles/opensearch-dashboards.al2.dockerfile -p opensearch-dashboards -a arm64 -t opensearch-dashboards-1.0.0.tar.gz | ||
``` | ||
* Build multi-arch image with this commands (only support x64 + arm64 in one image for now), the image will immediately uploaded to a docker registry so you need to provide docker repo name: | ||
* OpenSearch 1.0.0: | ||
``` | ||
./build-image-multi-arch.sh -v 1.0.0 -f ./dockerfiles/opensearch.al2.dockerfile -p opensearch -a "x64,arm64" -r "<Docker Hub RepoName>/<Docker Image Name>:<Tag Name>" | ||
``` | ||
* OpenSearch-Dashboards 1.0.0 with local tarball(s): | ||
``` | ||
./build-image-multi-arch.sh -v 1.0.0 -f ./dockerfiles/opensearch-dashboards.al2.dockerfile -p opensearch-dashboards -a "x64,arm64" -r "<Docker Hub RepoName>/<Docker Image Name>:<Tag Name>" -t "opensearch-1.0.0.tar.gz,opensearch-dashboards-1.0.0.tar.gz" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
# Import libs | ||
. ../../lib/shell/file_management.sh | ||
|
||
# Variable | ||
OLDIFS=$IFS | ||
BUILDER_NUM=`date +%s` | ||
BUILDER_NAME="multiarch_${BUILDER_NUM}" | ||
DIR="" | ||
|
||
function usage() { | ||
echo "" | ||
echo "This script is used to build the OpenSearch Docker image with single architecture (x64 or arm64). It prepares the files required by the Dockerfile in a temporary directory, then builds and tags the Docker image." | ||
echo "--------------------------------------------------------------------------" | ||
echo "Usage: $0 [args]" | ||
echo "" | ||
echo "Required arguments:" | ||
echo -e "-v VERSION\tSpecify the OpenSearch version number that you are building, e.g. '1.0.0' or '1.0.0-beta1'. This will be used to label the Docker image. If you do not use the '-o' option then this tool will download a public OPENSEARCH release matching this version." | ||
echo -e "-f DOCKERFILE\tSpecify the dockerfile full path, e.g. dockerfile/opensearch.al2.dockerfile." | ||
echo -e "-p PRODUCT\tSpecify the product, e.g. opensearch or opensearch-dashboards, make sure this is the name of your config folder and the name of your .tgz defined in dockerfile." | ||
echo -e "-a ARCHITECTURE\tSpecify the multiple architecture you want to add to the multi-arch image, separate by comma, e.g. 'x64,arm64'." | ||
echo -e "-r REPOSITORY\tSpecify the docker repository name in the format of '<Docker Hub RepoName>/<Docker Image Name>:<Tag Name>', due to multi-arch image either save in cache or directly upload to Docker Hub Repo, no local copies." | ||
echo "" | ||
echo "Optional arguments:" | ||
echo -e "-t TARBALL\tSpecify multiple opensearch or opensearch-dashboards tarballs, use the same order as the input for '-a' param, e.g. 'opensearch-1.0.0-linux-x64.tar.gz,opensearch-1.0.0-linux-arm64.tar.gz'. You still need to specify the version - this tool does not attempt to parse the filename." | ||
echo -e "-h\t\tPrint this message." | ||
echo "--------------------------------------------------------------------------" | ||
} | ||
|
||
function cleanup_docker_buildx() { | ||
# Cleanup docker buildx | ||
echo -e "\n* Cleanup docker buildx" | ||
docker buildx use default | ||
docker buildx rm $BUILDER_NAME > /dev/null 2>&1 | ||
} | ||
|
||
function cleanup_all() { | ||
cleanup_docker_buildx | ||
File_Delete $DIR | ||
} | ||
while getopts ":ht:v:f:p:a:r:" arg; do | ||
case $arg in | ||
h) | ||
usage | ||
exit 1 | ||
;; | ||
t) | ||
TARBALL=`realpath $OPTARG` | ||
;; | ||
v) | ||
VERSION=$OPTARG | ||
;; | ||
f) | ||
DOCKERFILE=$OPTARG | ||
;; | ||
p) | ||
PRODUCT=$OPTARG | ||
;; | ||
a) | ||
ARCHITECTURE=$OPTARG | ||
;; | ||
r) | ||
REPOSITORY=$OPTARG | ||
;; | ||
:) | ||
echo "-${OPTARG} requires an argument" | ||
usage | ||
exit 1 | ||
;; | ||
?) | ||
echo "Invalid option: -${arg}" | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
# Validate the required parameters to present | ||
if [ -z "$VERSION" ] || [ -z "$DOCKERFILE" ] || [ -z "$PRODUCT" ] || [ -z "$ARCHITECTURE" ] || [ -z "$REPOSITORY" ]; then | ||
echo "You must specify '-v VERSION', '-f DOCKERFILE', '-p PRODUCT', '-a ARCHITECTURE', '-r REPOSITORY'" | ||
usage | ||
exit 1 | ||
else | ||
echo $VERSION $DOCKERFILE $PRODUCT $ARCHITECTURE | ||
IFS=', ' read -r -a ARCHITECTURE_ARRAY <<< "$ARCHITECTURE" | ||
IFS=', ' read -r -a TARBALL_ARRAY <<< "$TARBALL" | ||
fi | ||
|
||
if [ "$PRODUCT" != "opensearch" ] && [ "$PRODUCT" != "opensearch-dashboards" ] | ||
then | ||
echo "Enter either 'opensearch' or 'opensearch-dashboards' as product name for -p parameter" | ||
exit 1 | ||
fi | ||
|
||
if [ "$ARCHITECTURE" != "x64" ] && [ "$ARCHITECTURE" != "arm64" ] | ||
then | ||
echo "We only support 'x64' and 'arm64' as architecture name for -a parameter" | ||
exit 1 | ||
fi | ||
|
||
# Warning docker desktop | ||
if (! docker buildx version) | ||
then | ||
echo -e "\n* You MUST have Docker Desktop to use buildx for multi-arch images." | ||
exit 1 | ||
fi | ||
|
||
# Prepare docker buildx | ||
trap cleanup_all TERM INT EXIT | ||
DIR=`Temp_Folder_Create` | ||
echo New workspace $DIR | ||
echo -e "\n* Prepare docker buildx" | ||
docker buildx use default | ||
docker buildx create --name $BUILDER_NAME --use | ||
docker buildx inspect --bootstrap | ||
|
||
# Check buildx status | ||
echo -e "\n* Check buildx status" | ||
docker buildx ls | grep $BUILDER_NAME | ||
docker ps | grep $BUILDER_NAME | ||
|
||
|
||
# Copy configs | ||
cp -v config/${PRODUCT}/* $DIR/ | ||
cp -v ../../scripts/opensearch-onetime-setup.sh $DIR/ | ||
|
||
# Copy TGZ | ||
if [ -z "$TARBALL" ]; then | ||
for index in ${!ARCHITECTURE_ARRAY[@]} | ||
do | ||
arch_uname=`echo ${ARCHITECTURE_ARRAY[$index]} | sed 's/x64/x86_64/g;s/arm64/aarch64/g'` | ||
URL="https://artifacts.opensearch.org/releases/bundle/${PRODUCT}/${VERSION}/${PRODUCT}-${VERSION}-linux-${ARCHITECTURE_ARRAY[$index]}.tar.gz" | ||
echo -e "\nDownloading ${PRODUCT} arch ${ARCHITECTURE_ARRAY[$index]} version ${VERSION} from ${URL}" | ||
curl -f $URL -o ${DIR}/${PRODUCT}-${arch_uname}.tgz || exit 1 | ||
done | ||
ls -l $DIR | ||
else | ||
for index in ${!ARCHITECTURE_ARRAY[@]} | ||
do | ||
arch_uname=`echo ${ARCHITECTURE_ARRAY[$index]} | sed 's/x64/x86_64/g;s/arm64/aarch64/g'` | ||
echo -e "\nCopying ${PRODUCT} arch ${ARCHITECTURE_ARRAY[$index]} version ${VERSION} from ${TARBALL_ARRAY[$index]}" | ||
cp -v ${TARBALL_ARRAY[$index]} ${DIR}/${PRODUCT}-${arch_uname}.tgz | ||
done | ||
ls -l $DIR | ||
fi | ||
|
||
# Build multi-arch images | ||
PLATFORMS=`echo "${ARCHITECTURE_ARRAY[@]/#/linux/}" | sed 's/x64/amd64/g;s/ /,/g'` && echo PLATFORMS $PLATFORMS | ||
docker buildx build --platform $PLATFORMS --build-arg VERSION=$VERSION --build-arg BUILD_DATE=`date -u +%Y-%m-%dT%H:%M:%SZ` -t $REPOSITORY -f $DOCKERFILE --push $DIR | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters