-
Notifications
You must be signed in to change notification settings - Fork 468
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: Use consistent java versions using sdkman (#28868)
### Proposed Changes * Change java base image to use sdkman to get java version. Use SDKMAN_JAVA_VERSION build arg to specify SDKMAN version and implementation. * Create manual workflow specifically for creating java base image based upon SDKMAN version string being tagged and pushed with that version. * Modify maven to pick up version specified in ~/.sdkmanrc and use that by default to specify which upstream java base image to used. * Cleanup places where java version is specified in maven pom files to default to a single location in parent/pom.xml. Set default value in environments/environment.properties so it can be modified locally be developers easily and changed in one place. setting java.compat.version=11 * Use independent version for compatibility of build allowing Java 21 to be upgraded to but still allowing plugins to be build with Java 11 with easy switch later. * Cleanup DockerFiles with some AI help. Note: * This change does not actually update to java 21 yet. We should do internal test to upgrade to latest point release of java 11 first. e.g. 11.0.22-ms -> 11.0.23-ms * This change does not modify the version used in the ci build workflows. We will follow up a change to enable consistent use of the .sdkmanrc in the workflows after this PR.
- Loading branch information
Showing
11 changed files
with
155 additions
and
86 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,57 @@ | ||
name: Build SDKMan Base java image | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
sdkman_java_version: | ||
description: 'SDKMAN version string run "sdk list java" for options' | ||
required: true | ||
multi_arch: | ||
description: 'Multi-arch flag, true: linux/amd64,linux/arm64 or false: linux/amd64' | ||
type: boolean | ||
required: false | ||
default: true | ||
push: | ||
description: 'Push flag' | ||
type: boolean | ||
required: false | ||
default: true | ||
jobs: | ||
build_image: | ||
name: Build Docker Base Image | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- name: Checkout core | ||
uses: actions/checkout@v4 | ||
- name: Set Common Vars | ||
run: | | ||
PLATFORMS='linux/amd64' | ||
[[ "${{ github.event.inputs.multi_arch }}" == 'true' ]] && PLATFORMS='linux/amd64,linux/arm64' | ||
echo "PLATFORMS=${PLATFORMS}" >> $GITHUB_ENV | ||
- name: Set up QEMU | ||
uses: docker/[email protected] | ||
with: | ||
platforms: amd64,arm64 | ||
if: github.event.inputs.multi_arch == 'true' | ||
- id: docker-setup-buildx | ||
name: Docker Setup Buildx | ||
uses: docker/[email protected] | ||
with: | ||
platforms: ${{ env.PLATFORMS }} | ||
driver-opts: | | ||
image=moby/buildkit:v0.12.2 | ||
if: github.event.inputs.multi_arch == 'true' | ||
- name: Docker Hub login | ||
uses: docker/[email protected] | ||
with: | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKER_TOKEN }} | ||
- name: Build and push | ||
uses: docker/[email protected] | ||
with: | ||
context: ./docker/java-base | ||
push: ${{ github.event.inputs.push }} | ||
tags: ${{ github.event.inputs.tags }} | ||
platforms: ${{ env.PLATFORMS }} | ||
build-args: | ||
SDKMAN_JAVA_VERSION=${{ github.event.inputs.sdkman_java_version }} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,73 @@ | ||
# ---------------------------------------------- | ||
# Stage 2: Construct our container using the minimal-java image | ||
# and copying the prebuilt dotcms | ||
# Stage 1: Construct our container using the minimal-java image and copying the prebuilt dotcms | ||
# ---------------------------------------------- | ||
FROM dotcms/java-base:ms-jdk-11 as container-base | ||
|
||
ARG SDKMAN_JAVA_VERSION="11.0.22-ms" | ||
FROM dotcms/java-base:${SDKMAN_JAVA_VERSION} AS container-base | ||
WORKDIR /srv | ||
|
||
ENV DEBIAN_FRONTEND=noninteractive | ||
|
||
# Installing basic packages | ||
RUN apt update \ | ||
&& apt upgrade -y | ||
|
||
# Cleanup | ||
RUN apt purge --allow-remove-essential -y \ | ||
&& apt autoremove -y \ | ||
&& apt clean \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Defining default non-root user UID, GID, and name | ||
ARG USER_UID="65001" | ||
ARG USER_GID="65001" | ||
ARG USER_GROUP="dotcms" | ||
ARG USER_NAME="dotcms" | ||
|
||
RUN groupadd -f -g $USER_GID $USER_GROUP | ||
# Creating default non-user | ||
# the useradd | ||
RUN useradd -l -d /srv -g $USER_GID -u $USER_UID $USER_NAME | ||
|
||
RUN mkdir -p /srv/utils /srv/templates /srv/config /srv/home | ||
# Ensure group and user are created with proper permissions | ||
RUN groupadd -g "$USER_GID" "$USER_GROUP" && \ | ||
useradd -l -d /srv -u "$USER_UID" -g "$USER_GROUP" -s /bin/bash "$USER_NAME" && \ | ||
mkdir -p /srv/utils /srv/templates /srv/config /srv/home /data/shared/assets /data/shared/felix/load /data/shared/felix/undeployed /data/local/dotsecure/license && \ | ||
chown -R "$USER_NAME:$USER_GROUP" /data && \ | ||
chown -R "$USER_NAME:$USER_GROUP" /srv | ||
|
||
# Copy our build | ||
COPY --chown=$USER_NAME:$USER_GROUP maven /srv/ | ||
COPY --chown=$USER_NAME:$USER_GROUP ROOT/ / | ||
|
||
RUN ln -s $(ls -d /srv/dotserver/tomcat-*) /srv/dotserver/tomcat | ||
|
||
# Make scripts runable | ||
RUN find /srv/ -type f -name "*.sh" -exec chmod a+x {} \; && \ | ||
RUN ln -s $(ls -d /srv/dotserver/tomcat-*) /srv/dotserver/tomcat && \ | ||
# Make scripts runnable | ||
find /srv/ -type f -name "*.sh" -exec chmod a+x {} \; && \ | ||
# Make plugin merging directories writable | ||
find /srv/templates -type d -exec chmod 770 {} \; && \ | ||
# Make dotcms user owner | ||
mkdir -p /data/shared/assets && \ | ||
mkdir -p /data/shared/felix/load && \ | ||
mkdir -p /data/shared/felix/undeployed && \ | ||
mkdir -p /data/local/dotsecure/license && \ | ||
chown -R $USER_NAME:$USER_NAME /data | ||
find /srv/templates -type d -exec chmod 770 {} \; | ||
|
||
# ---------------------------------------------- | ||
# Stage 3: Flatten everything to 1 layer | ||
# Stage 2: Final stage for minimal runtime image | ||
# ---------------------------------------------- | ||
FROM scratch | ||
|
||
LABEL com.dotcms.contact "[email protected]" | ||
LABEL com.dotcms.vendor "dotCMS LLC" | ||
LABEL com.dotcms.description "dotCMS Content Management System" | ||
FROM ubuntu:20.04 | ||
|
||
LABEL com.dotcms.contact="[email protected]" \ | ||
com.dotcms.vendor="dotCMS LLC" \ | ||
com.dotcms.description="dotCMS Content Management System" | ||
|
||
# Install basic packages and tini | ||
RUN apt update && \ | ||
apt upgrade -y && \ | ||
apt install -y --no-install-recommends \ | ||
wget \ | ||
gnupg \ | ||
tini && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
# Install PostgreSQL client and pg_dump | ||
RUN apt update && \ | ||
apt install -y --no-install-recommends postgresql-common && \ | ||
/usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y && \ | ||
apt install -y --no-install-recommends postgresql-client-16 && \ | ||
apt purge -y postgresql-common gnupg && \ | ||
/usr/bin/pg_dump --version || exit 1 && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
ARG USER_UID="65001" | ||
ARG USER_GID="65001" | ||
ARG USER_GROUP="dotcms" | ||
ARG USER_NAME="dotcms" | ||
|
||
# Ensure the group and user are created in the final image as well | ||
RUN groupadd -g "$USER_GID" "$USER_GROUP" && \ | ||
useradd -l -d /srv -u "$USER_UID" -g "$USER_GROUP" -s /bin/bash "$USER_NAME" | ||
|
||
COPY --from=container-base / / | ||
COPY --from=container-base /java /java | ||
COPY --from=container-base /srv /srv | ||
COPY --from=container-base /data /data | ||
|
||
# Switching to non-root user to install SDKMAN! | ||
USER $USER_UID:$USER_GID | ||
ENV JAVA_HOME="/java" | ||
ENV PATH=$PATH:/java/bin | ||
|
@@ -82,4 +87,4 @@ EXPOSE 8081 | |
# Connect from proxy, HTTPS/443, secure | ||
EXPOSE 8082 | ||
# Direct connect for HTTPS, secure | ||
EXPOSE 8443 | ||
EXPOSE 8443 |
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
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
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