Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

making build -D working with podman #3796

Merged
merged 30 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
da29366
added podman to switches
judovana Apr 26, 2024
04b28dc
Adjusted signalHandler to countwith podman/docker
judovana Apr 26, 2024
6b43591
reworked BUILD_CONFIG[DOCKER] to contain only sudo information
judovana Apr 26, 2024
ce82463
using the BUILD_CONFIG[DOCKER] BUILD_CONFIG[USE_DOCKER] combo proeprly
judovana Apr 28, 2024
9e653f3
On podman, set --userns=keep-id
judovana May 7, 2024
743f470
porecreate all necessary dirs
judovana May 7, 2024
480aa29
Added warinbg to `docker build` command when used with podman
judovana May 7, 2024
e3af8d2
Using absolute path instead of "."
judovana May 7, 2024
092d192
docker-build.sh jsut-> just
judovana May 8, 2024
fa34c0d
Removed unused parameter of buildOpenJDKViaDocker
judovana May 8, 2024
3d2a7a5
use which podman without [] and to dev/null
judovana May 9, 2024
20f6965
Revert "Using absolute path instead of ".""
judovana May 9, 2024
4db5724
Fixed issue with missing test for mk-ca-bundle.pl
judovana May 9, 2024
04f44ab
Always generate configure-and-build.sh
judovana May 9, 2024
56df908
Removed more hardcoded dockers
judovana May 13, 2024
a1a3d57
Do not set boot jdk for docekr builds (it is removed later anyway)
judovana May 14, 2024
e566202
Added few more missing dirs
judovana May 15, 2024
18ef020
Fixed boot jdk check against new docker/podman/false
judovana May 15, 2024
f1d8611
replacing missed ${BUILD_CONFIG[DOCKER]} by ${BUILD_CONFIG[DOCKER]} "…
judovana May 20, 2024
ae65c64
instead of workspace/build/src creatig directly /workspace/build
judovana May 24, 2024
67f3187
Remoed accident tab
judovana May 24, 2024
bab4397
Added support for building local dir/src tarball in contianer
judovana May 24, 2024
73c43c5
Removed wrongly added ASSEMBLE_EXPLODED_IMAGE=true to container builds
judovana May 24, 2024
160b762
used -n instead of '! -z '
judovana May 24, 2024
51ccc93
Highlighted sudo for dcoekr
judovana Jun 17, 2024
35201e2
Added missing bracket
judovana Jun 18, 2024
e383554
Fixed typo
judovana Jun 19, 2024
f1b9336
Mentioned issue with --custom-cacerts on podman
judovana Jun 24, 2024
43af711
renamed USE_DOCKER->CONTAINER_COMMAND DOCKER->CONTAINER_AS_ROOT
judovana Jun 24, 2024
10e228d
Improved warning about --custom-cacerts
judovana Jun 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ as we can generate valid dockerfile for it):

```bash
./makejdk-any-platform.sh --docker --clean-docker-build jdk8u
./makejdk-any-platform.sh --docker --clean-docker-build --build-variant openj9 jdk11u
./makejdk-any-platform.sh --podman --clean-docker-build --build-variant openj9 jdk11u
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to make this -D now?

Suggested change
./makejdk-any-platform.sh --podman --clean-docker-build --build-variant openj9 jdk11u
./makejdk-any-platform.sh -D --clean-docker-build --build-variant openj9 jdk11u

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had left -D to autodetect. Id there is podman, it will be used. If not, docekr will be used. Reason for this fallback is that if you have podman, you have also docker aliases. But if you have docker, you do no thave podman aliases.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep understood - I just wasn't sure why this example was explicitly switched to --podman instead of showing the "autodetect" version

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I jsut wanted to keep all three there. If they should be reuced, jsut say.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a slight preference fur using the generic -D, although I quite like the multiple examples too, so no real preference with your explaination :-)

```

We test these dockerfiles on a regular basis in the
Expand Down Expand Up @@ -144,8 +144,8 @@ specify the location for the built binary, e.g. /path/.
This is typically used in conjunction with -T to create a custom path
/ file name for the resulting binary.

-D, --docker
build OpenJDK in a docker container.
-D, --docker, --podman
build OpenJDK in a docker/podman container. -D will autodetect, using podman if found, docker otherwise.

--cross-compile
use this if you are cross compiling - it will skip the java -version checks at the end
Expand Down Expand Up @@ -253,7 +253,7 @@ specify the JVM variant (server or client), defaults to server.

Example usage:

./makejdk-any-platform --docker jdk8u
./makejdk-any-platform -D jdk8u
./makejdk-any-platform -T MyOpenJDK10.tar.gz jdk10

```
Expand Down
6 changes: 4 additions & 2 deletions configureBuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ doAnyBuildVariantOverrides() {
# Set the working directory for this build
setWorkingDirectory() {
if [ -z "${BUILD_CONFIG[WORKSPACE_DIR]}" ]; then
if [[ "${BUILD_CONFIG[USE_DOCKER]}" == "true" ]]; then
if [[ "${BUILD_CONFIG[CONTAINER_COMMAND]}" == "true" ]]; then
BUILD_CONFIG[WORKSPACE_DIR]="/openjdk/"
else
BUILD_CONFIG[WORKSPACE_DIR]="$PWD/workspace"
Expand Down Expand Up @@ -410,5 +410,7 @@ configure_build() {
setWorkingDirectory
configureMacFreeFont
setMakeArgs
setBootJdk
if [ "${BUILD_CONFIG[CONTAINER_COMMAND]}" == false ] ; then
setBootJdk
fi
}
2 changes: 1 addition & 1 deletion cyclonedx-lib/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@
<arg value="--name"/>
<arg value="openjdk_built_config"/>
<arg value="--value"/>
<arg value="# ============================\n# OPENJDK BUILD CONFIGURATION:\n# ============================\nBUILD_CONFIG[ADOPT_PATCHES]=\true\\nBUILD_CONFIG[ASSEMBLE_EXPLODED_IMAGE]=\false\\nBUILD_CONFIG[BRANCH]=\dev\\nBUILD_CONFIG[BUILD_FULL_NAME]=\linux-x86_64--server-release\\nBUILD_CONFIG[BUILD_VARIANT]=\hotspot\\nBUILD_CONFIG[CLEAN_DOCKER_BUILD]=\false\/>\nBUILD_CONFIG[CLEAN_GIT_REPO]=\true\nBUILD_CONFIG[CLEAN_LIBS]=\false\\nBUILD_CONFIG[CONTAINER_NAME]=\openjdk_container\\nBUILD_CONFIG[COPY_MACOSX_FREE_FONT_LIB_FOR_JDK_FLAG]=\false\\nBUILD_CONFIG[COPY_MACOSX_FREE_FONT_LIB_FOR_JRE_FLAG]=\false\\nBUILD_CONFIG[CREATE_DEBUG_IMAGE]=\true\\nBUILD_CONFIG[CREATE_SOURCE_ARCHIVE]=\false\\nBUILD_CONFIG[CROSSCOMPILE]=\false\\nBUILD_CONFIG[CUSTOM_CACERTS]=\true\\nBUILD_CONFIG[DEBUG_DOCKER]=\false\\nBUILD_CONFIG[DEBUG_IMAGE_PATH]=\debug-image\\nBUILD_CONFIG[DISABLE_ADOPT_BRANCH_SAFETY]=\false\\nBUILD_CONFIG[DOCKER]=\docker\\nBUILD_CONFIG[DOCKER_FILE_PATH]=\\nBUILD_CONFIG[DOCKER_SOURCE_VOLUME_NAME]=\openjdk-source-volume-jdk17-hotspot\\nBUILD_CONFIG[FREETYPE]=\false\\nBUILD_CONFIG[FREETYPE_DIRECTORY]=\\nBUILD_CONFIG[FREETYPE_FONT_BUILD_TYPE_PARAM]=\\nBUILD_CONFIG[FREETYPE_FONT_VERSION]=\2.9.1\\nBUILD_CONFIG[GRADLE_USER_HOME_DIR]=\\nBUILD_CONFIG[JDK_BOOT_DIR]=\/usr/lib/jvm/jdk-16\ \nBUILD_CONFIG[JDK_PATH]=\jdk\\nBUILD_CONFIG[JRE_PATH]=\jre\\nBUILD_CONFIG[JVM_VARIANT]=\server\\nBUILD_CONFIG[KEEP_CONTAINER]=\false\\nBUILD_CONFIG[MACOSX_CODESIGN_IDENTITY]=\\nBUILD_CONFIG[MAKE_ARGS_FOR_ANY_PLATFORM]=\product-images legacy-jre-image\\nBUILD_CONFIG[MAKE_COMMAND_NAME]=\make\\nBUILD_CONFIG[MAKE_EXPLODED]=\false\\nBUILD_CONFIG[NUM_PROCESSORS]=\1\\nBUILD_CONFIG[OPENJDK_BUILD_NUMBER]=\\nBUILD_CONFIG[OPENJDK_BUILD_REPO_BRANCH]=\master\\nBUILD_CONFIG[OPENJDK_BUILD_REPO_URI]=\https://github.com/adoptium/temurin-build.git\\nBUILD_CONFIG[OPENJDK_CORE_VERSION]=\jdk17\\nBUILD_CONFIG[OPENJDK_FEATURE_NUMBER]=\17\\nBUILD_CONFIG[OPENJDK_FOREST_NAME]=\jdk17\\nBUILD_CONFIG[OPENJDK_SOURCE_DIR]=\src\nBUILD_CONFIG[OPENJDK_UPDATE_VERSION]=\\nBUILD_CONFIG[OS_ARCHITECTURE]=\x86_64\\nBUILD_CONFIG[OS_FULL_VERSION]=\Linux 5.8.0-34-generic : CentOS release 6.10 (Final)\\nBUILD_CONFIG[OS_KERNEL_NAME]=\linux\\nBUILD_CONFIG[PATCHES]=\\nBUILD_CONFIG[RELEASE]=\true\\nBUILD_CONFIG[REPOSITORY]=\https://github.com/adoptium/jdk17\\nBUILD_CONFIG[REUSE_CONTAINER]=\true\\nBUILD_CONFIG[SHALLOW_CLONE_OPTION]=\\nBUILD_CONFIG[SIGN]=\false\\nBUILD_CONFIG[TAG]=\jdk-17+35_adopt\\nBUILD_CONFIG[TARGET_DIR]=\target/\\nBUILD_CONFIG[TARGET_FILE_NAME]=\OpenJDK17-jdk_x64_linux_hotspot_17_35.tar.gz\\nBUILD_CONFIG[TEST_IMAGE_PATH]=\test\\nBUILD_CONFIG[TMP_CONTAINER_NAME]=\openjdk-copy-src\\nBUILD_CONFIG[TMP_SPACE_BUILD]=\false\\nBUILD_CONFIG[USER_SUPPLIED_CONFIGURE_ARGS]=\ --disable-warnings-as-errors --enable-ccache --enable-dtrace\\nBUILD_CONFIG[USER_SUPPLIED_MAKE_ARGS]=\\nBUILD_CONFIG[USE_DOCKER]=\false\\nBUILD_CONFIG[USE_JEP319_CERTS]=\true\\nBUILD_CONFIG[USE_SSH]=\false\\nBUILD_CONFIG[VENDOR]=\Eclipse Adoptium\\nBUILD_CONFIG[WORKING_DIR]=\./build/\\nBUILD_CONFIG[WORKSPACE_DIR]=\/home/jenkins/workspace/build-scripts/jobs/jdk17/jdk17-linux-x64-hotspot/workspace\"/>
<arg value="# ============================\n# OPENJDK BUILD CONFIGURATION:\n# ============================\nBUILD_CONFIG[ADOPT_PATCHES]=\true\\nBUILD_CONFIG[ASSEMBLE_EXPLODED_IMAGE]=\false\\nBUILD_CONFIG[BRANCH]=\dev\\nBUILD_CONFIG[BUILD_FULL_NAME]=\linux-x86_64--server-release\\nBUILD_CONFIG[BUILD_VARIANT]=\hotspot\\nBUILD_CONFIG[CLEAN_DOCKER_BUILD]=\false\/>\nBUILD_CONFIG[CLEAN_GIT_REPO]=\true\nBUILD_CONFIG[CLEAN_LIBS]=\false\\nBUILD_CONFIG[CONTAINER_NAME]=\openjdk_container\\nBUILD_CONFIG[COPY_MACOSX_FREE_FONT_LIB_FOR_JDK_FLAG]=\false\\nBUILD_CONFIG[COPY_MACOSX_FREE_FONT_LIB_FOR_JRE_FLAG]=\false\\nBUILD_CONFIG[CREATE_DEBUG_IMAGE]=\true\\nBUILD_CONFIG[CREATE_SOURCE_ARCHIVE]=\false\\nBUILD_CONFIG[CROSSCOMPILE]=\false\\nBUILD_CONFIG[CUSTOM_CACERTS]=\true\\nBUILD_CONFIG[DEBUG_DOCKER]=\false\\nBUILD_CONFIG[DEBUG_IMAGE_PATH]=\debug-image\\nBUILD_CONFIG[DISABLE_ADOPT_BRANCH_SAFETY]=\false\\nBUILD_CONFIG[CONTAINER_AS_ROOT]=\docker\\nBUILD_CONFIG[DOCKER_FILE_PATH]=\\nBUILD_CONFIG[DOCKER_SOURCE_VOLUME_NAME]=\openjdk-source-volume-jdk17-hotspot\\nBUILD_CONFIG[FREETYPE]=\false\\nBUILD_CONFIG[FREETYPE_DIRECTORY]=\\nBUILD_CONFIG[FREETYPE_FONT_BUILD_TYPE_PARAM]=\\nBUILD_CONFIG[FREETYPE_FONT_VERSION]=\2.9.1\\nBUILD_CONFIG[GRADLE_USER_HOME_DIR]=\\nBUILD_CONFIG[JDK_BOOT_DIR]=\/usr/lib/jvm/jdk-16\ \nBUILD_CONFIG[JDK_PATH]=\jdk\\nBUILD_CONFIG[JRE_PATH]=\jre\\nBUILD_CONFIG[JVM_VARIANT]=\server\\nBUILD_CONFIG[KEEP_CONTAINER]=\false\\nBUILD_CONFIG[MACOSX_CODESIGN_IDENTITY]=\\nBUILD_CONFIG[MAKE_ARGS_FOR_ANY_PLATFORM]=\product-images legacy-jre-image\\nBUILD_CONFIG[MAKE_COMMAND_NAME]=\make\\nBUILD_CONFIG[MAKE_EXPLODED]=\false\\nBUILD_CONFIG[NUM_PROCESSORS]=\1\\nBUILD_CONFIG[OPENJDK_BUILD_NUMBER]=\\nBUILD_CONFIG[OPENJDK_BUILD_REPO_BRANCH]=\master\\nBUILD_CONFIG[OPENJDK_BUILD_REPO_URI]=\https://github.com/adoptium/temurin-build.git\\nBUILD_CONFIG[OPENJDK_CORE_VERSION]=\jdk17\\nBUILD_CONFIG[OPENJDK_FEATURE_NUMBER]=\17\\nBUILD_CONFIG[OPENJDK_FOREST_NAME]=\jdk17\\nBUILD_CONFIG[OPENJDK_SOURCE_DIR]=\src\nBUILD_CONFIG[OPENJDK_UPDATE_VERSION]=\\nBUILD_CONFIG[OS_ARCHITECTURE]=\x86_64\\nBUILD_CONFIG[OS_FULL_VERSION]=\Linux 5.8.0-34-generic : CentOS release 6.10 (Final)\\nBUILD_CONFIG[OS_KERNEL_NAME]=\linux\\nBUILD_CONFIG[PATCHES]=\\nBUILD_CONFIG[RELEASE]=\true\\nBUILD_CONFIG[REPOSITORY]=\https://github.com/adoptium/jdk17\\nBUILD_CONFIG[REUSE_CONTAINER]=\true\\nBUILD_CONFIG[SHALLOW_CLONE_OPTION]=\\nBUILD_CONFIG[SIGN]=\false\\nBUILD_CONFIG[TAG]=\jdk-17+35_adopt\\nBUILD_CONFIG[TARGET_DIR]=\target/\\nBUILD_CONFIG[TARGET_FILE_NAME]=\OpenJDK17-jdk_x64_linux_hotspot_17_35.tar.gz\\nBUILD_CONFIG[TEST_IMAGE_PATH]=\test\\nBUILD_CONFIG[TMP_CONTAINER_NAME]=\openjdk-copy-src\\nBUILD_CONFIG[TMP_SPACE_BUILD]=\false\\nBUILD_CONFIG[USER_SUPPLIED_CONFIGURE_ARGS]=\ --disable-warnings-as-errors --enable-ccache --enable-dtrace\\nBUILD_CONFIG[USER_SUPPLIED_MAKE_ARGS]=\\nBUILD_CONFIG[CONTAINER_COMMAND]=\false\\nBUILD_CONFIG[USE_JEP319_CERTS]=\true\\nBUILD_CONFIG[USE_SSH]=\false\\nBUILD_CONFIG[VENDOR]=\Eclipse Adoptium\\nBUILD_CONFIG[WORKING_DIR]=\./build/\\nBUILD_CONFIG[WORKSPACE_DIR]=\/home/jenkins/workspace/build-scripts/jobs/jdk17/jdk17-linux-x64-hotspot/workspace\"/>
<arg value="--jsonFile"/>
<arg value="${testSBOMFile}"/>
</java>
Expand Down
83 changes: 64 additions & 19 deletions docker-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
#
################################################################################

# the ${BUILD_CONFIG[CONTAINER_AS_ROOT]} can not be quoted. It is sudo (or simialrly) or nothing. "" is not an option.
# simialrly the ${cpuset} and ${userns}
# shellcheck disable=SC2206
# shellcheck disable=SC2046
# shellcheck disable=SC2086

set -eu

# Create a data volume called ${BUILD_CONFIG[DOCKER_SOURCE_VOLUME_NAME]},
Expand All @@ -30,21 +36,24 @@ set -eu
createPersistentDockerDataVolume()
{
set +e
${BUILD_CONFIG[DOCKER]} volume inspect "${BUILD_CONFIG[DOCKER_SOURCE_VOLUME_NAME]}" > /dev/null 2>&1
${BUILD_CONFIG[CONTAINER_AS_ROOT]} "${BUILD_CONFIG[CONTAINER_COMMAND]}" volume inspect "${BUILD_CONFIG[DOCKER_SOURCE_VOLUME_NAME]}" > /dev/null 2>&1
local data_volume_exists=$?
set -e

if [[ "${BUILD_CONFIG[CLEAN_DOCKER_BUILD]}" == "true" || "$data_volume_exists" != "0" ]]; then

# shellcheck disable=SC2154
echo "Removing old volumes and containers"
# shellcheck disable=SC2046
${BUILD_CONFIG[DOCKER]} rm -f $(${BUILD_CONFIG[DOCKER]} ps -a --no-trunc -q -f volume="${BUILD_CONFIG[DOCKER_SOURCE_VOLUME_NAME]}") || true
${BUILD_CONFIG[DOCKER]} volume rm -f "${BUILD_CONFIG[DOCKER_SOURCE_VOLUME_NAME]}" || true
${BUILD_CONFIG[CONTAINER_AS_ROOT]} "${BUILD_CONFIG[CONTAINER_COMMAND]}" rm -f $(${BUILD_CONFIG[CONTAINER_AS_ROOT]} "${BUILD_CONFIG[CONTAINER_COMMAND]}" ps -a --no-trunc -q -f volume="${BUILD_CONFIG[DOCKER_SOURCE_VOLUME_NAME]}") || true
${BUILD_CONFIG[CONTAINER_AS_ROOT]} "${BUILD_CONFIG[CONTAINER_COMMAND]}" volume rm -f "${BUILD_CONFIG[DOCKER_SOURCE_VOLUME_NAME]}" || true

# shellcheck disable=SC2154
echo "Creating tmp container"
${BUILD_CONFIG[DOCKER]} volume create --name "${BUILD_CONFIG[DOCKER_SOURCE_VOLUME_NAME]}"
if echo "${BUILD_CONFIG[CONTAINER_COMMAND]}" | grep docker ; then
${BUILD_CONFIG[CONTAINER_AS_ROOT]} "${BUILD_CONFIG[CONTAINER_COMMAND]}" volume create --name "${BUILD_CONFIG[DOCKER_SOURCE_VOLUME_NAME]}"
else
${BUILD_CONFIG[CONTAINER_AS_ROOT]} "${BUILD_CONFIG[CONTAINER_COMMAND]}" volume create "${BUILD_CONFIG[DOCKER_SOURCE_VOLUME_NAME]}"
fi
fi
}

Expand All @@ -64,12 +73,25 @@ buildDockerContainer()

writeConfigToFile

${BUILD_CONFIG[DOCKER]} build -t "${BUILD_CONFIG[CONTAINER_NAME]}" -f "${dockerFile}" . --build-arg "OPENJDK_CORE_VERSION=${BUILD_CONFIG[OPENJDK_CORE_VERSION]}" --build-arg "HostUID=${UID}"
${BUILD_CONFIG[CONTAINER_AS_ROOT]} "${BUILD_CONFIG[CONTAINER_COMMAND]}" build -t "${BUILD_CONFIG[CONTAINER_NAME]}" -f "${dockerFile}" . --build-arg "OPENJDK_CORE_VERSION=${BUILD_CONFIG[OPENJDK_CORE_VERSION]}" --build-arg "HostUID=${UID}"
}

# Execute the (Adoptium) OpenJDK build inside the Docker Container
buildOpenJDKViaDocker()
{
local hostDir
hostDir="$(pwd)"
local pipelinesdir="${hostDir}"/workspace/pipelines
local workspacedir="${hostDir}"/workspace # we must ensure build user have correct permissions here
local targetdir="${hostDir}"/workspace/target
local targetbuilddir="${hostDir}"/workspace/build
local configdir="${hostDir}"/workspace/config
local localsourcesdir=

if [ "${BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE]}" = "true" ] ; then
# OPENJDK_LOCAL_SOURCE_ARCHIVE_ABSPATH can be file, you can nto mount file
localsourcesdir=$(dirname "${BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE_ABSPATH]}")
fi

# TODO This could be extracted overridden by the user if we support more
# architectures going forwards
Expand All @@ -80,7 +102,8 @@ buildOpenJDKViaDocker()
if [ "${BUILD_CONFIG[BUILD_VARIANT]}" == "openj9" ]; then
build_variant_flag="--openj9"
fi
docker/dockerfile-generator.sh --version "${BUILD_CONFIG[OPENJDK_FEATURE_NUMBER]}" --path "${BUILD_CONFIG[DOCKER_FILE_PATH]}" "$build_variant_flag"
docker/dockerfile-generator.sh --version "${BUILD_CONFIG[OPENJDK_FEATURE_NUMBER]}" --path "${BUILD_CONFIG[DOCKER_FILE_PATH]}" "$build_variant_flag" \
--dirs "${workspacedir} ${targetdir} ${targetbuilddir} ${configdir} ${localsourcesdir}" --command "${BUILD_CONFIG[CONTAINER_AS_ROOT]} ${BUILD_CONFIG[CONTAINER_COMMAND]}"

# shellcheck disable=SC1090,SC1091
source "${BUILD_CONFIG[DOCKER_FILE_PATH]}/dockerConfiguration.sh"
Expand Down Expand Up @@ -129,7 +152,7 @@ buildOpenJDKViaDocker()
BUILD_CONFIG[DEBUG_IMAGE_PATH]=$openjdk_debug_image_path
BUILD_CONFIG[STATIC_LIBS_IMAGE_PATH]=$static_libs_dir

if [ -z "$(command -v docker)" ]; then
if [ -z "$(command -v "${BUILD_CONFIG[CONTAINER_COMMAND]}")" ]; then
# shellcheck disable=SC2154
echo "Error, please install docker and ensure that it is in your path and running!"
exit
Expand All @@ -144,15 +167,15 @@ buildOpenJDKViaDocker()
if [[ "${BUILD_CONFIG[REUSE_CONTAINER]}" == "true" ]] ; then
# shellcheck disable=SC2086
# If we can't find the previous Docker container then build a new one
if [ "$(${BUILD_CONFIG[DOCKER]} ps -a | grep -c \"${BUILD_CONFIG[CONTAINER_NAME]}\")" == 0 ]; then
if [ "$(${BUILD_CONFIG[CONTAINER_AS_ROOT]} ${BUILD_CONFIG[CONTAINER_COMMAND]} ps -a | grep -c \"${BUILD_CONFIG[CONTAINER_NAME]}\")" == 0 ]; then
echo "No docker container for reuse was found, so creating '${BUILD_CONFIG[CONTAINER_NAME]}' "
buildDockerContainer
fi
else
# shellcheck disable=SC2154
echo "Since you specified --ignore-container, we are removing the existing container (if it exists) and building you a new one{$good}"
# Find the previous Docker container and remove it (if it exists)
${BUILD_CONFIG[DOCKER]} ps -a | awk '{ print $1,$2 }' | grep "${BUILD_CONFIG[CONTAINER_NAME]}" | awk '{print $1 }' | xargs -I {} "${BUILD_CONFIG[DOCKER]}" rm -f {}
${BUILD_CONFIG[CONTAINER_AS_ROOT]} "${BUILD_CONFIG[CONTAINER_COMMAND]}" ps -a | awk '{ print $1,$2 }' | grep "${BUILD_CONFIG[CONTAINER_NAME]}" | awk '{print $1 }' | xargs -I {} ${BUILD_CONFIG[CONTAINER_AS_ROOT]} "${BUILD_CONFIG[CONTAINER_COMMAND]}" rm -f {}

# Build a new container
buildDockerContainer
Expand All @@ -161,9 +184,6 @@ buildOpenJDKViaDocker()
# Show the user all of the config before we build
displayParams

local hostDir
hostDir="$(pwd)"

echo "Target binary directory on host machine: ${hostDir}/target"
mkdir -p "${hostDir}/workspace/target"

Expand All @@ -183,11 +203,36 @@ buildOpenJDKViaDocker()
fi

# Command without gitSshAccess or dockerMode arrays
if [ -e "${hostDir}"/pipelines ] ; then
local pipelinesdir="${hostDir}"/pipelines
else
mkdir -p "${pipelinesdir}"
fi
if echo "${BUILD_CONFIG[CONTAINER_COMMAND]}" | grep docker ; then
local cpuset="--cpuset-cpus=${cpuSet}"
else
local cpuset=""
fi
if echo "${BUILD_CONFIG[CONTAINER_COMMAND]}" | grep podman ; then
local userns="--userns=keep-id"
else
local userns=""
fi
local mountflag=Z #rw? maybe this should be bound to root/rootles content of BUILD_CONFIG[CONTAINER_AS_ROOT] rather then just podman/docker in USE_DOCKER?
mkdir -p "${hostDir}"/workspace/build # shouldnt be already there?
local localsourcesdirmount=
if [ -n "${localsourcesdir}" ] ; then
localsourcesdirmount="-v ${localsourcesdir}:${localsourcesdir}:${mountflag}" #read only? Is copied anwya
fi
echo "If you get permissions denied on ${targetdir} or ${pipelinesdir} try to turn off selinux"
local commandString=(
"--cpuset-cpus=${cpuSet}"
${cpuset}
${userns}
${localsourcesdirmount}
-v "${BUILD_CONFIG[DOCKER_SOURCE_VOLUME_NAME]}:/openjdk/build"
-v "${hostDir}"/workspace/target:/"${BUILD_CONFIG[WORKSPACE_DIR]}"/"${BUILD_CONFIG[TARGET_DIR]}":Z
-v "${hostDir}"/pipelines:/openjdk/pipelines:Z
-v "${targetdir}":/"${BUILD_CONFIG[WORKSPACE_DIR]}"/"${BUILD_CONFIG[TARGET_DIR]}":"${mountflag}"
-v "${pipelinesdir}":/openjdk/pipelines:"${mountflag}"
-v "${configdir}":/"${BUILD_CONFIG[WORKSPACE_DIR]}"/"config":"${mountflag}"
-e "DEBUG_DOCKER_FLAG=${BUILD_CONFIG[DEBUG_DOCKER]}"
-e "BUILD_VARIANT=${BUILD_CONFIG[BUILD_VARIANT]}"
"${dockerEntrypoint[@]:+${dockerEntrypoint[@]}}")
Expand All @@ -204,14 +249,14 @@ buildOpenJDKViaDocker()
fi

# Run the command string in Docker
${BUILD_CONFIG[DOCKER]} run --name "${BUILD_CONFIG[OPENJDK_CORE_VERSION]}-${BUILD_CONFIG[BUILD_VARIANT]}" "${commandString[@]}"
${BUILD_CONFIG[CONTAINER_AS_ROOT]} "${BUILD_CONFIG[CONTAINER_COMMAND]}" run --name "${BUILD_CONFIG[OPENJDK_CORE_VERSION]}-${BUILD_CONFIG[BUILD_VARIANT]}" "${commandString[@]}"

# Tell user where the resulting binary can be found on the host system
echo "The finished image can be found in ${hostDir}/workspace/target on the host system"
echo "The finished image can be found in ${targetdir} on the host system"

# If we didn't specify to keep the container then remove it
if [[ "${BUILD_CONFIG[KEEP_CONTAINER]}" == "false" ]] ; then
echo "Removing container ${BUILD_CONFIG[OPENJDK_CORE_VERSION]}-${BUILD_CONFIG[BUILD_VARIANT]}"
${BUILD_CONFIG[DOCKER]} ps -a | awk '{ print $1,$(NF) }' | grep "${BUILD_CONFIG[OPENJDK_CORE_VERSION]}-${BUILD_CONFIG[BUILD_VARIANT]}" | awk '{print $1 }' | xargs -I {} "${BUILD_CONFIG[DOCKER]}" rm {}
${BUILD_CONFIG[CONTAINER_AS_ROOT]} "${BUILD_CONFIG[CONTAINER_COMMAND]}" ps -a | awk '{ print $1,$(NF) }' | grep "${BUILD_CONFIG[OPENJDK_CORE_VERSION]}-${BUILD_CONFIG[BUILD_VARIANT]}" | awk '{print $1 }' | xargs -I {} ${BUILD_CONFIG[CONTAINER_AS_ROOT]} ${BUILD_CONFIG[CONTAINER_COMMAND]} rm {}
fi
}
Loading
Loading