Add jq to Docker image and improve UNIT_SOURCE handling

- Include jq in the Docker image for JSON processing.
- Refactor UNIT_SOURCE logic to cleanly update configuration using jq.
- Remove obsolete UNIT_SOURCE handling code.
This commit is contained in:
2025-08-23 01:59:57 +05:00
parent c33fcd1d7c
commit 94db6aa51d
6 changed files with 34 additions and 16 deletions

View File

@@ -19,7 +19,7 @@ COPY --from=unit_builder /var/lib/unit/ /var/lib/unit/
COPY docker/unit-config.json /docker-entrypoint.d/config.json COPY docker/unit-config.json /docker-entrypoint.d/config.json
RUN apk --no-cache add pcre2 libbz2 libpng libwebp libjpeg-turbo icu-libs freetype oniguruma libzip \ RUN apk --no-cache add pcre2 libbz2 libpng libwebp libjpeg-turbo icu-libs freetype oniguruma libzip jq \
&& apk add --no-cache --virtual .phpize-deps icu-dev libpng-dev bzip2-dev libwebp-dev libjpeg-turbo-dev freetype-dev oniguruma-dev libzip-dev pcre2-dev ${PHPIZE_DEPS} \ && apk add --no-cache --virtual .phpize-deps icu-dev libpng-dev bzip2-dev libwebp-dev libjpeg-turbo-dev freetype-dev oniguruma-dev libzip-dev pcre2-dev ${PHPIZE_DEPS} \
&& docker-php-ext-configure intl --enable-intl && \ && docker-php-ext-configure intl --enable-intl && \
docker-php-ext-configure bcmath --enable-bcmath && \ docker-php-ext-configure bcmath --enable-bcmath && \

View File

@@ -42,6 +42,20 @@ if [ "$role" = "app" ]; then
if /usr/bin/find "/docker-entrypoint.d/" -mindepth 1 -print -quit 2>/dev/null | /bin/grep -q .; then if /usr/bin/find "/docker-entrypoint.d/" -mindepth 1 -print -quit 2>/dev/null | /bin/grep -q .; then
echo "$0: /docker-entrypoint.d/ is not empty, applying initial configuration..." echo "$0: /docker-entrypoint.d/ is not empty, applying initial configuration..."
if [[ -n "${UNIT_SOURCE:-}" ]]; then
config="/docker-entrypoint.d/config.json"
tmp="$(mktemp)"
jq --arg src "${UNIT_SOURCE}" '
.listeners["*:9000"].forwarded.source =
( $src
| split(",")
| map( gsub("^\\s+|\\s+$"; "") ) # trim пробелы
| map( select(. != "") ) # убрать пустые
)
' "$config" > "$tmp"
mv "$tmp" "$config"
fi
echo "$0: Looking for certificate bundles in /docker-entrypoint.d/..." echo "$0: Looking for certificate bundles in /docker-entrypoint.d/..."
for f in $(/usr/bin/find /docker-entrypoint.d/ -type f -name "*.pem"); do for f in $(/usr/bin/find /docker-entrypoint.d/ -type f -name "*.pem"); do
echo "$0: Uploading certificates bundle: $f" echo "$0: Uploading certificates bundle: $f"
@@ -60,12 +74,6 @@ if [ "$role" = "app" ]; then
curl_put $f "config" curl_put $f "config"
done done
if [ ! -z ${UNIT_SOURCE+x} ]
then
echo $UNIT_SOURCE > /docker-entrypoint.d/unit_source.json
curl_put "/docker-entrypoint.d/unit_source.json" "config/listeners/*:9000/forwarded/source"
fi
echo "$0: Looking for shell scripts in /docker-entrypoint.d/..." echo "$0: Looking for shell scripts in /docker-entrypoint.d/..."
for f in $(/usr/bin/find /docker-entrypoint.d/ -type f -name "*.sh"); do for f in $(/usr/bin/find /docker-entrypoint.d/ -type f -name "*.sh"); do
echo "$0: Launching $f"; echo "$0: Launching $f";

View File

@@ -42,6 +42,20 @@ if [ "$role" = "app" ]; then
if /usr/bin/find "/docker-entrypoint.d/" -mindepth 1 -print -quit 2>/dev/null | /bin/grep -q .; then if /usr/bin/find "/docker-entrypoint.d/" -mindepth 1 -print -quit 2>/dev/null | /bin/grep -q .; then
echo "$0: /docker-entrypoint.d/ is not empty, applying initial configuration..." echo "$0: /docker-entrypoint.d/ is not empty, applying initial configuration..."
if [[ -n "${UNIT_SOURCE:-}" ]]; then
config="/docker-entrypoint.d/config.json"
tmp="$(mktemp)"
jq --arg src "${UNIT_SOURCE}" '
.listeners["*:9000"].forwarded.source =
( $src
| split(",")
| map( gsub("^\\s+|\\s+$"; "") ) # trim пробелы
| map( select(. != "") ) # убрать пустые
)
' "$config" > "$tmp"
mv "$tmp" "$config"
fi
echo "$0: Looking for certificate bundles in /docker-entrypoint.d/..." echo "$0: Looking for certificate bundles in /docker-entrypoint.d/..."
for f in $(/usr/bin/find /docker-entrypoint.d/ -type f -name "*.pem"); do for f in $(/usr/bin/find /docker-entrypoint.d/ -type f -name "*.pem"); do
echo "$0: Uploading certificates bundle: $f" echo "$0: Uploading certificates bundle: $f"
@@ -60,12 +74,6 @@ if [ "$role" = "app" ]; then
curl_put $f "config" curl_put $f "config"
done done
if [ ! -z ${UNIT_SOURCE+x} ]
then
echo $UNIT_SOURCE > /docker-entrypoint.d/unit_source.json
curl_put "/docker-entrypoint.d/unit_source.json" "config/listeners/*:9000/forwarded/source"
fi
echo "$0: Looking for shell scripts in /docker-entrypoint.d/..." echo "$0: Looking for shell scripts in /docker-entrypoint.d/..."
for f in $(/usr/bin/find /docker-entrypoint.d/ -type f -name "*.sh"); do for f in $(/usr/bin/find /docker-entrypoint.d/ -type f -name "*.sh"); do
echo "$0: Launching $f"; echo "$0: Launching $f";

View File

@@ -16,7 +16,7 @@ services:
- ./app/application:/var/www/html - ./app/application:/var/www/html
environment: environment:
CONTAINER_ROLE: app CONTAINER_ROLE: app
UNIT_SOURCE: '"172.16.0.0/12"' UNIT_SOURCE: "172.16.0.0/12"
queue: queue:
build: build:

View File

@@ -13,7 +13,7 @@ services:
env_file: app/.env env_file: app/.env
environment: environment:
CONTAINER_ROLE: app CONTAINER_ROLE: app
UNIT_SOURCE: '"172.16.0.0/12"' UNIT_SOURCE: "172.16.0.0/12"
volumes: volumes:
- ./app/storage/app:/var/www/html/storage/app - ./app/storage/app:/var/www/html/storage/app
- ./app/storage/logs:/var/www/html/storage/logs - ./app/storage/logs:/var/www/html/storage/logs

View File

@@ -1,4 +1,4 @@
version: '3.7' #version: '3.7'
services: services:
app: app:
build: build:
@@ -13,6 +13,8 @@ services:
- ${DOCKER_APP_PORT}:9000 - ${DOCKER_APP_PORT}:9000
volumes: volumes:
- ./app/application:/var/www/html - ./app/application:/var/www/html
environment:
CONTAINER_ROLE: app
queue: queue:
build: build: