From e299a176587d2601dbd581727d0199c710d7e29f Mon Sep 17 00:00:00 2001 From: Stefan - Zipkid - Goethals Date: Wed, 11 Dec 2024 11:51:00 +0100 Subject: [PATCH 1/3] Fix indent consistency --- puppetserver/conf.d/puppetserver.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/puppetserver/conf.d/puppetserver.conf b/puppetserver/conf.d/puppetserver.conf index df036c1c..a548dc52 100644 --- a/puppetserver/conf.d/puppetserver.conf +++ b/puppetserver/conf.d/puppetserver.conf @@ -75,7 +75,7 @@ http-client: { # Provide a reasonable default here. Use case is mounting a valid projects volume to have PS serve files from there even if # CM did not actually put them there. bolt: { - projects-dir: "/etc/puppetlabs/code/projects" + projects-dir: "/etc/puppetlabs/code/projects" } # settings related to profiling the puppet Ruby code From 736adcb78f4904332fb1b27546bea040519b4bbb Mon Sep 17 00:00:00 2001 From: Stefan - Zipkid - Goethals Date: Thu, 12 Dec 2024 08:23:08 +0100 Subject: [PATCH 2/3] Ony write file if env var is set. --- puppetserver/Dockerfile | 2 +- puppetserver/docker-entrypoint.d/89-csr_attributes.sh | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/puppetserver/Dockerfile b/puppetserver/Dockerfile index f88a5554..e7e724e2 100644 --- a/puppetserver/Dockerfile +++ b/puppetserver/Dockerfile @@ -65,7 +65,7 @@ ENV PUPPETSERVER_JAVA_ARGS="-Xms1024m -Xmx1024m" \ PUPPETSERVER_ENABLE_ENV_CACHE_DEL_API=true \ ENVIRONMENTPATH=/etc/puppetlabs/code/environments \ HIERACONFIG='$confdir/hiera.yaml' \ - CSR_ATTRIBUTES='{}' \ + CSR_ATTRIBUTES="" \ PUPPET_DEB=puppet${PUPPET_RELEASE}-release-${UBUNTU_CODENAME}.deb COPY docker-entrypoint.sh \ diff --git a/puppetserver/docker-entrypoint.d/89-csr_attributes.sh b/puppetserver/docker-entrypoint.d/89-csr_attributes.sh index 4ed87146..162b7348 100755 --- a/puppetserver/docker-entrypoint.d/89-csr_attributes.sh +++ b/puppetserver/docker-entrypoint.d/89-csr_attributes.sh @@ -2,5 +2,7 @@ set -e -echo "CSR Attributes: ${CSR_ATTRIBUTES}" -/opt/puppetlabs/puppet/bin/ruby /docker-entrypoint.d/89-csr_attributes.rb +if [ -n "${CSR_ATTRIBUTES}" ]; then + echo "CSR Attributes: ${CSR_ATTRIBUTES}" + /opt/puppetlabs/puppet/bin/ruby /docker-entrypoint.d/89-csr_attributes.rb +fi From 64f56e534d77a568a5586e9d67f835f4c298cb2b Mon Sep 17 00:00:00 2001 From: Stefan - Zipkid - Goethals Date: Thu, 12 Dec 2024 08:23:59 +0100 Subject: [PATCH 3/3] Add custom script location for scripts that need to run before the default entrypoint scripts. --- README.md | 3 ++- puppetserver/docker-entrypoint.sh | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a7d82f4b..16aee59b 100644 --- a/README.md +++ b/README.md @@ -121,7 +121,7 @@ The following environment variables are supported: | __PUPPETSERVER_ENABLE_ENV_CACHE_DEL_API__ | Enable the puppet admin api endpoint via certificates to allow clearing environment caches

Defaults to `true` | | __ENVIRONMENTPATH__ | Set an environmentpath

Defaults to `/etc/puppetlabs/code/environments` | | __HIERACONFIG__ | Set a hiera_config entry in puppet.conf file

Defaults to `$confdir/hiera.yaml` | -| __CSR_ATTRIBUTES__ | Provide a JSON string of the csr_attributes.yaml content. e.g. `CSR_ATTRIBUTES='{"custom_attributes": { "challengePassword": "foobar" }, "extension_requests": { "pp_project": "foo" } }'`

Defaults to empty JSON object `{}`
Please note that within a compose file, you must provide all environment variables as Hash and not as Array!
environment:
`CSR_ATTRIBUTES: '{"extension_request": {...}}'` | +| __CSR_ATTRIBUTES__ | Provide a JSON string of the csr_attributes.yaml content. e.g. `CSR_ATTRIBUTES='{"custom_attributes": { "challengePassword": "foobar" }, "extension_requests": { "pp_project": "foo" } }'`

Please note that within a compose file, you must provide all environment variables as Hash and not as Array!
environment:
`CSR_ATTRIBUTES: '{"extension_request": {...}}'` | ## Initialization Scripts @@ -129,6 +129,7 @@ If you would like to do additional initialization, add a directory called `/dock You can also create sub-directories in `/docker-custom-entrypoint.d/` for scripts that have to run at different stages. +- `/docker-custom-entrypoint.d/pre-default/` - scripts that run before the default entrypoint scripts from this repo run. - `/docker-custom-entrypoint.d/` - scripts that run after the default entrypoint scripts, but before the puppetserver service is started. - `/docker-custom-entrypoint.d/post-startup/` - scripts that run after the puppetserver service is started. - `/docker-custom-entrypoint.d/sigterm-handler/` - scripts that run when the container receives a SIGTERM signal. diff --git a/puppetserver/docker-entrypoint.sh b/puppetserver/docker-entrypoint.sh index be155292..bb574ff9 100755 --- a/puppetserver/docker-entrypoint.sh +++ b/puppetserver/docker-entrypoint.sh @@ -19,10 +19,25 @@ echoerr "Entrypoint PID $$" ## Pre execution handler pre_execution_handler() { + if [ -d /docker-custom-entrypoint.d/ ]; then + if [ -d /docker-custom-entrypoint.d/pre-default/ ]; then + find /docker-custom-entrypoint.d/pre-default/ -type f -name "*.sh" \ + -exec chmod +x {} \; + sync + for f in /docker-custom-entrypoint.d/pre-default/*.sh; do + if [[ -f "$f" && -x $(realpath "$f") ]]; then + echo "Running $f" + "$f" + fi + done + fi + fi + for f in /docker-entrypoint.d/*.sh; do echo "Running $f" "$f" done + if [ -d /docker-custom-entrypoint.d/ ]; then find /docker-custom-entrypoint.d/ -type f -name "*.sh" \ -exec chmod +x {} \;