Trying to write a custom buildpack along with Java paketo buildpack #267
Replies: 2 comments
-
It could be this part. The Maven buildpack, when it runs, will copy the output and save that to a layer. It then deletes everything because you don't want source code in the final image and restored the saved files from the layer to The net result is that the image now contains your built files, not the source files. If you're trying to access something from the source files after Maven runs, it won't exist unless it's been included in the built files and if it was in the built files then it'll be in a different location (because In your case, it's saving multiple JAR files so you'll have a collection of JAR files in If you want it to not delete stuff, there's an include/exclude setting you can use. See The other buildpacks in the Java buildpack do expect things to be in certain locations to work properly. If you're depending on executable-jar or apache-tomcat or another buildpack to make your app actually run, then you need to be careful to keep things where they are expected. If your buildpack is going to handle all of that, then you can do whatever you want. You could tell Maven to keep everything and then have your buildpack be in charge of what is removed from the final image. Just understand that whatever's left in Hope that helps! |
Beta Was this translation helpful? Give feedback.
-
Thanks @dmikusa , yep that helped me I included the files using BP_INCLUDE_FILES and used BP_MAVEN_BUILT_ARTIFACT to mention every jars which eventually ended up in final image |
Beta Was this translation helpful? Give feedback.
-
#!/usr/bin/env bash
echo "---> Keycloak Buildpack"
set -euo pipefail
1. GET ARGS
layersdir=$1
2. CREATE THE LAYER DIRECTORY
keycloak_layer="${layersdir}"/keycloak
mkdir -p "${keycloak_layer}"
3. MAKE keycloak AVAILABLE DURING LAUNCH
echo -e '[types]\nlaunch = true' > "${layersdir}/keycloak.toml"
4. INSTALL KEYCLOAK
curl -L https://github.com/keycloak/keycloak/releases/download/24.0.1/keycloak-24.0.1.tar.gz -o "${layersdir}/keycloak-24.0.1.tar.gz"
tar -xzf "${layersdir}/keycloak-24.0.1.tar.gz" -C "${keycloak_layer}"
6. Set environment variables
export KC_HEALTH_ENABLED=true
export KC_METRICS_ENABLED=true
export KC_DB=postgres
7. Copy generated JAR files from previous Buildpack to Keycloak folders
find ./addons/target -regex './addons/target/keycloak-addons-[0-9]+.[0-9]+.[0-9]+-[0-9]+T[0-9]+-[0-9a-f]+.jar' | grep -v 'sources' | xargs -I{} cp {} "${keycloak_layer}/keycloak-24.0.1/providers/keycloak-addons.jar"
find ./scripts/target -regex './scripts/target/keycloak-scripts-[0-9]+.[0-9]+.[0-9]+-[0-9]+T[0-9]+-[0-9a-f]+.jar' | grep -v 'sources' | xargs -I{} cp {} "${keycloak_layer}/keycloak-24.0.1/providers/keycloak-scripts.jar"
find ./idp-mapper/target -regex './idp-mapper/target/idp-mapper-[0-9]+.[0-9]+.[0-9]+-[0-9]+T[0-9]+-[0-9a-f]+.jar' | grep -v 'sources' | xargs -I{} cp {} "${keycloak_layer}/keycloak-24.0.1/providers/idp-mapper.jar"
cp ./themes/open-blue /opt/keycloak/themes/open-blue-theme
cp ./target/keycloak-server-copy/* "${keycloak_layer}/keycloak-24.0.1/providers/
8. Build scripts with specified variables
cd "${keycloak_layer}"
./keycloak-24.0.1/bin/kc.sh build --http-relative-path /auth --features=scripts
exit 0
I followed https://buildpacks.io/docs/for-buildpack-authors/tutorials/basic-buildpack/07_make-buildpack-configurable/ this documentaion to write this buildpack
Then in builder.toml file
[[order]]
[[order.group]]
id = "paketo-buildpacks/java"
version = "10.5.0"
[[order.group]]
id = "custom-buildpack/keycloak"
version = "0.0.4"
[builder] [INFO]
[builder] [INFO] keycloak ..................................... SUCCESS [02:16 min]
[builder] [INFO] Keycloak Addons .................................... SUCCESS [01:36 min]
[builder] [INFO] Keycloak Scripts ................................... SUCCESS [ 0.162 s]
[builder] [INFO] Keycloak-Okta IdP Group Mapper ..................... SUCCESS [ 0.694 s]
[builder] [INFO] ------------------------------------------------------------------------
[builder] [INFO] BUILD SUCCESS
[builder] [INFO] ------------------------------------------------------------------------
[builder] [INFO] Total time: 04:35 min
[builder] [INFO] Finished at: 2024-03-26T13:10:01Z
[builder] [INFO] ------------------------------------------------------------------------
[builder]
[builder] Removing source code
[builder] Restoring multiple artifacts
[builder] % Total % Received % Xferd Average Speed Time Time Time Current
[builder] Dload Upload Total Spent Left Speed
[builder] 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
[builder] 100 168M 100 168M 0 0 6904k 0 0:00:24 0:00:24 --:--:-- 8540k
[builder] cp: cannot stat './themes/open-blue': No such file or directory
[builder] ERROR: failed to build: exit status 1
ERROR: failed to build: executing lifecycle. This may be the result of using an untrusted builder: failed with status code: 51**
Beta Was this translation helpful? Give feedback.
All reactions