Skip to content

Commit 69da7f8

Browse files
authored
Feature/no gradle (#44)
Previously, we maintained a gradle.build file with dependency versions. These dependencies could be updated regularly. Since version 24 of Keycloak, the Keycloak team has been testing the integration of Aurora DB with a version of the AWS wrapper referenced here: keycloak/keycloak@eadd1c4 To align with what is tested by Keycloak and thus avoid compatibility issues, this PR makes a modification to the dependency construction. It retrieves the pom.xml of the Keycloak version, extracts the referenced version of the AWS wrapper, and then downloads the pom.xml of the latter and installs all transitive dependencies with Maven (this is done in the builder step). A utility script retrieves the version of the wrapper to download from the version of keycloak. This PR also includes the removal of the launcher workaround since bitnami/containers#63945 has been merged. fixes #43
1 parent 27d935d commit 69da7f8

File tree

7 files changed

+105
-80
lines changed

7 files changed

+105
-80
lines changed

.github/renovate.json5

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"groupSlug": "all-non-major-keycloak",
2424
"matchDatasources": ["docker"],
2525
"matchFileNames": ["keycloak-*/Dockerfile"],
26-
"matchUpdateTypes": ["minor", "patch", "digest", "pin", "pinDigest"],
26+
"versioning": "regex:^(?<major>\\d+)\\.(?<minor>\\d+)\\.(?<patch>\\d+)(:?-(?<compatibility>.+)(?<build>\\d+)-r(?<revision>\\d+))?$",
2727
"enabled": true,
2828
"addLabels": ["dependencies", "docker"]
2929
},
@@ -34,15 +34,5 @@
3434
"matchUpdateTypes": ["major"],
3535
"enabled": false
3636
}
37-
],
38-
"customManagers": [
39-
{
40-
"customType": "regex",
41-
"fileMatch": ["build.gradle$"],
42-
"matchStrings": [
43-
"renovate: datasource=(?<datasource>.*?) depName=(?<depName>.*?)( versioning=(?<versioning>.*?))?\\s.* (?<currentValue>.*)\\s"
44-
],
45-
"versioningTemplate": "{{#if versioning}}{{{versioning}}}{{else}}semver{{/if}}"
46-
}
4737
]
4838
}

.github/scripts/utils/find_latest_keycloak.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@
55
# Description: Finds the latest version of Keycloak from folders prefixed with "keycloak-" in the current directory.
66
# Usage: find_latest_keycloak.sh
77

8+
set -Eeuo pipefail
9+
810
ls -1d --color=never "$(pwd)"/keycloak-* | tail -n 1 | awk -F'[-/]' '{print $(NF-0)}'
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env bash
2+
3+
# Script: get_aws_jdbc_wrapper_version.sh
4+
# Description: Finds the AWS JDBC wrapper version of the Keycloak version from the pom.xml, <keycloak-version> must be formatted as major.minor.patch
5+
# Usage: get_aws_jdbc_wrapper_version.sh <keycloak-version>
6+
7+
set -Eeuo pipefail
8+
9+
display_help() {
10+
echo "Script: get_aws_jdbc_wrapper_version.sh"
11+
echo "Description: Finds the AWS JDBC wrapper version of the Keycloak version from the pom.xml"
12+
echo "Usage: get_aws_jdbc_wrapper_version.sh <keycloak-version>"
13+
}
14+
15+
# Check if there is exactly one argument provided
16+
if [[ $# -ne 1 ]]; then
17+
echo "Error: Incorrect number of arguments."
18+
display_help
19+
exit 1
20+
fi
21+
22+
keycloak_version="$1"
23+
24+
# Validate keycloak version format (major.minor.patch)
25+
if ! [[ "$keycloak_version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
26+
echo "Error: Invalid keycloak version format. It must be in the format of major.minor.patch."
27+
display_help
28+
exit 1
29+
fi
30+
31+
# Function to extract the first number from a version string
32+
get_major_version() {
33+
echo "$keycloak_version" | cut -d '.' -f1
34+
}
35+
36+
# Keycloak only started to reference the aws_jdbc_wrapper version starting with v24, defaulting a fixed version of the jdbc driver,
37+
# this check also allow bumping minimal aws_jdbc_wrapper version for critical fixes
38+
if [[ "$(get_major_version "$keycloak_version")" -lt "25" ]] ; then
39+
echo "2.3.5" # fix https://github.com/keycloak/keycloak/issues/27290
40+
exit 0
41+
fi
42+
43+
# Fetch the AWS JDBC wrapper version from the pom.xml file
44+
AWS_JDBC_VERSION="$(curl -s "https://raw.githubusercontent.com/keycloak/keycloak/$keycloak_version/pom.xml" | awk -F'[><]' '/<aws-jdbc-wrapper.version>/{print $3}')"
45+
46+
if [[ -z "$AWS_JDBC_VERSION" ]]; then
47+
echo "Error: Failed to retrieve AWS JDBC version." >&2
48+
exit 1
49+
fi
50+
51+
echo "$AWS_JDBC_VERSION"

.github/workflows/build-images.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ jobs:
8282
username: "${{ steps.secrets.outputs.DOCKERHUB_USER }}"
8383
password: "${{ steps.secrets.outputs.DOCKERHUB_PASSWORD }}"
8484

85+
- name: Compute build image variables
86+
id: compute-build-image-name-step
87+
run: |
88+
keycloak_full_version=$(grep "ARG BASE_IMAGE_NAME=.*$1" keycloak-${{ matrix.keycloak_version }}/Dockerfile | awk -F'[:=]' '{print $NF}' | tr -d '"' | awk -F'[:/-]' '{print $1}' || echo "Error: Image tag $1 not found in Dockerfile" && exit 1) && echo "$keycloak_full_version"
89+
echo "keycloak_full_version=${keycloak_full_version}"
90+
91+
aws_jdbc_wrapper_version="$(.github/scripts/utils/get_aws_jdbc_wrapper_version.sh "$keycloak_full_version" || echo "Error: Cannot get aws jdbc wrapper version for keycloak $keycloak_full_version" && exit 1)" && echo "$aws_jdbc_wrapper_version"
92+
echo "aws_jdbc_wrapper_version=${aws_jdbc_wrapper_version}" >> "$GITHUB_ENV"
93+
echo "aws_jdbc_wrapper_version=${aws_jdbc_wrapper_version}"
94+
8595
- name: Build image using Camunda docker build
8696
id: build-image-step
8797
uses: camunda/infra-global-github-actions/build-docker-image@36867af1a61c2e3cc064cbb6e4615e446b815511 # main
@@ -93,6 +103,8 @@ jobs:
93103
image_name: ${{ vars.CONTAINER_IMAGE_NAME_CI }}
94104
build_context: "./keycloak-${{ matrix.keycloak_version }}/"
95105
build_platforms: linux/amd64,linux/arm64
106+
build_args: |
107+
AWS_JDBC_WRAPPER_VERSION=${{ env.aws_jdbc_wrapper_version }}
96108
extra_tags: | # the ci- prefix ensures a build context, this image is treated as "temporary"
97109
type=sha,enable=true,priority=1000,prefix=ci-${{ matrix.keycloak_version }}-sha-,suffix=,format=short
98110
@@ -390,7 +402,7 @@ jobs:
390402
KEYCLOAK_JDBC_PARAMS: "${{ matrix.runner_desc.keycloak_db_jdbc_query }}"
391403
KC_DB_DRIVER: "${{ matrix.runner_desc.keycloak_db_driver }}"
392404

393-
KEYCLOAK_LOG_LEVEL: "DEBUG,software.amazon.jdbc:FINEST"
405+
KEYCLOAK_LOG_LEVEL: "INFO,software.amazon.jdbc:FINEST"
394406

395407
COMPOSE_POSTGRES_IMAGE: "public.ecr.aws/docker/library/postgres:${{ env.postgres_version }}"
396408
COMPOSE_POSTGRES_DEPLOY_REPLICAS: "${{ matrix.runner_desc.postgres_replicas }}"

DEVELOPER.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,17 @@ Welcome to the development reference for Keycloak by Camunda! This document prov
77
Building a local image is for development purposes only.
88
In production, the pipeline will handle this and build a multi-architecture image using Docker Buildx.
99

10-
Navigate to the `keycloak-<version>` (e.g. `keycloak-24`) directory and execute the following command:
10+
Navigate to the `keycloak-<version>` (e.g. `keycloak-24`) directory and execute the following commands:
1111

1212
```bash
13-
docker build . -t docker.io/camunda/keycloak:24
13+
# retrieve the aws jdbc wrapper version from the referenced keycloak version
14+
keycloak_full_version="$(grep "ARG BASE_IMAGE_NAME=.*$1" ./Dockerfile | awk -F'[:=]' '{print $NF}' | tr -d '"' | awk -F'[:/-]' '{print $1}')"
15+
echo "keycloak_full_version=$keycloak_full_version"
16+
17+
aws_jdbc_wrapper_version="$(../.github/scripts/utils/get_aws_jdbc_wrapper_version.sh $keycloak_full_version)"
18+
echo "aws_jdbc_wrapper_version=$aws_jdbc_wrapper_version"
19+
20+
docker build . -t "docker.io/camunda/keycloak:$keycloak_full_version" --build-arg "AWS_JDBC_WRAPPER_VERSION=$aws_jdbc_wrapper_version"
1421
```
1522

1623
This Dockerfile includes the necessary dependencies and configurations for AWS Advanced JDBC Wrapper.
@@ -40,7 +47,7 @@ When adding a new version of Keycloak, follow these steps:
4047
4. **Final Image Tags:**
4148
- The final image will have the following tags:
4249
- `camunda/keycloak:24` (mutable - triggered by any change in the base image of Keycloak)
43-
- `camunda/keycloak:24.0.1-1` (mutable - triggered by any change not part of the base image of Keycloak, e.g., gradle dependencies)
50+
- `camunda/keycloak:24.0.1-1` (mutable - triggered by any change not part of the base image of Keycloak)
4451
- `camunda/keycloak:24.0.1-1-${date in yyyy-mm-dd-xxx format}` (immutable, recommended for production usage)
4552

4653
Following these steps ensures a smooth integration of new Keycloak versions, consistent testing across the development environment, and easy access to the latest version. Happy coding!

keycloak-23/Dockerfile

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,48 @@
1-
ARG BASE_IMAGE_NAME="docker.io/bitnami/keycloak:23.0.7-debian-12-r3"
1+
ARG BASE_IMAGE_NAME="docker.io/bitnami/keycloak:23.0.7-debian-12-r4"
22
# List of all available images with associated sha: https://hub.docker.com/r/bitnami/keycloak/tags
33
# Note: use the global image digest to make this image platform agnostic (see: https://github.com/camunda/zeebe/pull/14186)
4-
ARG BASE_IMAGE_DIGEST="sha256:eabfbdd679042f40612388aed560e3e7f809c3d4a04e5755a7cac22c9270e5a5"
4+
ARG BASE_IMAGE_DIGEST="sha256:c4a2bf092d1afeac972d5f66db58e431d3fb53beedde18b7f54e45c37f5d1be5"
55

6-
FROM docker.io/gradle:jdk17-focal@sha256:17e0c6bec6cb2c7f4240315d7a957c6b9058a5c137c2f8b37760ac327111ce87 as lib
6+
# Building builder image
7+
# hadolint ignore=DL3006
8+
FROM ${BASE_IMAGE_NAME}@${BASE_IMAGE_DIGEST} as builder
9+
# use the .github/scripts/utils/get_aws_wrapper_version.sh keycloak-version script to get the value and pass it at build time
10+
ARG AWS_JDBC_WRAPPER_VERSION
711

8-
WORKDIR /home/gradle
12+
USER 0
913

10-
COPY build.gradle /home/gradle
14+
# install maven (silence alert about version pinning of maven)
15+
# hadolint ignore=DL3008
16+
RUN mkdir /home/keycloak && chown keycloak /home/keycloak && \
17+
apt-get update && apt-get install maven -y --no-install-recommends
1118

12-
RUN gradle copyDependencies
19+
USER 1001
1320

14-
# Building builder image
15-
# hadolint ignore=DL3006
16-
FROM ${BASE_IMAGE_NAME}@${BASE_IMAGE_DIGEST} as builder
21+
WORKDIR /home/keycloak
1722

18-
COPY --from=lib /home/gradle/lib /opt/bitnami/keycloak/providers
23+
# download the wrapper from github, then fetch the dependencies from maven
24+
ADD --chown=1001 "https://github.com/awslabs/aws-advanced-jdbc-wrapper/releases/download/${AWS_JDBC_WRAPPER_VERSION}/aws-advanced-jdbc-wrapper-${AWS_JDBC_WRAPPER_VERSION}.jar" "/opt/bitnami/keycloak/providers/aws-advanced-jdbc-wrapper-${AWS_JDBC_WRAPPER_VERSION}.jar"
25+
ADD --chown=1001 "https://repo1.maven.org/maven2/software/amazon/jdbc/aws-advanced-jdbc-wrapper/${AWS_JDBC_WRAPPER_VERSION}/aws-advanced-jdbc-wrapper-${AWS_JDBC_WRAPPER_VERSION}.pom" /home/keycloak/pom.xml
1926

20-
WORKDIR /opt/bitnami/keycloak
27+
RUN cat /home/keycloak/pom.xml && mvn install && \
28+
cp /home/keycloak/.m2/repository/software/amazon/awssdk/*/*/*.jar /opt/bitnami/keycloak/providers/
2129

2230
RUN /opt/bitnami/keycloak/bin/kc.sh build
2331

24-
2532
##### FINAL Keycloak IMAGE #####
33+
2634
# hadolint ignore=DL3006
2735
FROM ${BASE_IMAGE_NAME}@${BASE_IMAGE_DIGEST}
2836
# leave the values below unset to use the default value at the top of the file
2937
ARG BASE_IMAGE_NAME
3038
ARG BASE_IMAGE_DIGEST
3139

40+
# use the .github/scripts/utils/get_aws_wrapper_version.sh keycloak-version script to get the value and pass it at build time
41+
ARG AWS_JDBC_WRAPPER_VERSION
42+
43+
# Copy the previously built aws jdbc drivers
44+
COPY --from=builder /opt/bitnami/keycloak/ /opt/bitnami/keycloak/
45+
3246
# common, k8s, openshift and OCI labels:
3347
# OCI: https://github.com/opencontainers/image-spec/blob/main/annotations.md
3448
# OCP: https://docs.openshift.com/container-platform/4.10/openshift_images/create-images.html#defining-image-metadata
@@ -37,7 +51,8 @@ LABEL maintainer="Camunda" \
3751
summary="Keycloak bitnami with AWS wrapper" \
3852
io.k8s.description="Keycloak bitnami with AWS wrapper." \
3953
io.k8s.display-name="keycloak" \
40-
description="Keycloak bitnami with AWS wrapper." \
54+
description="Keycloak bitnami with AWS JDBC wrapper." \
55+
jdbc.aws-jdbc-wrapper.version="${AWS_JDBC_WRAPPER_VERSION}" \
4156
org.opencontainers.image.authors="Camunda" \
4257
org.opencontainers.image.vendor="Camunda" \
4358
org.opencontainers.image.documentation="https://hub.docker.com/camunda/keycloak/" \
@@ -58,19 +73,3 @@ LABEL maintainer="Camunda" \
5873
# org.opencontainers.image.revision
5974
# org.opencontainers.image.source
6075
# org.opencontainers.image.version
61-
62-
# Copy the previously built aws jdbc drivers
63-
COPY --from=builder /opt/bitnami/keycloak/ /opt/bitnami/keycloak/
64-
65-
# switch back to root to modify scripts
66-
USER 0
67-
68-
# Patch the image scripts to support custom JDBC driver until https://github.com/bitnami/charts/issues/18808#issuecomment-1866638783 is resolved
69-
# hadolint ignore=SC2016
70-
RUN sed -i '/KEYCLOAK_JDBC_PARAMS$/a\ KEYCLOAK_JDBC_DRIVER' /opt/bitnami/scripts/keycloak-env.sh && \
71-
sed -i '/^export KEYCLOAK_JDBC_PARAMS="${KEYCLOAK_JDBC_PARAMS:-}"/a \
72-
KEYCLOAK_JDBC_DRIVER="${KEYCLOAK_JDBC_DRIVER:-postgresql}"\nexport KEYCLOAK_JDBC_DRIVER="${KEYCLOAK_JDBC_DRIVER:-}"' /opt/bitnami/scripts/keycloak-env.sh && \
73-
sed -i 's/"jdbc:postgresql:/\"jdbc:${KEYCLOAK_JDBC_DRIVER}:/g' /opt/bitnami/scripts/libkeycloak.sh
74-
75-
# Switch back to unprivileged user
76-
USER 1001

keycloak-23/build.gradle

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)