Skip to content

Commit

Permalink
fix: Expose the log level of the gateway server
Browse files Browse the repository at this point in the history
* Dockerfile-gateway
 * Fixes the UID to avoid warning that id should be > 1000
 * Configures use of a gateway.sh script as the CMD to allow for customising
   of node command line

* gateway.sh
 * Updates the log level in the env.product file
 * Due to permissions, cannot sed update in-place but send to /tmp then
   redirect back
 * Executes the node command line
  • Loading branch information
phantomjinx committed Oct 17, 2024
1 parent c25f14f commit a53192c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Dockerfile-gateway
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ FROM registry.access.redhat.com/ubi9/ubi-minimal:9.4
#
# The user id
#
ENV NODE_USER 999
ENV NODE_USER 9999

ENV NODE_MAJOR_VERSION 20
ENV GATEWAY_DIR=/opt/hawtio-online-gateway
Expand All @@ -33,14 +33,20 @@ RUN microdnf -y install --setopt=tsflags=nodocs nodejs && microdnf clean all

COPY --from=builder /hawtio-online-gateway/dist ${GATEWAY_DIR}/
COPY docker/gateway/env.product ${GATEWAY_DIR}/
COPY docker/gateway/gateway.sh ${GATEWAY_DIR}/

#
# Finalize permissions for nginx files
# Finalize permissions for gateway files
#
RUN useradd -ms /bin/sh -u ${NODE_USER} gateway
RUN chown -R ${NODE_USER} ${GATEWAY_DIR}
RUN chmod 755 ${GATEWAY_DIR}/gateway.sh

# Allow the environment to be updated by arbitrary image user
RUN chmod 666 ${GATEWAY_DIR}/env.product

USER ${NODE_USER}

EXPOSE 3000

CMD ["node", "--enable-source-maps", "--env-file=/opt/hawtio-online-gateway/env.product", "/opt/hawtio-online-gateway/gateway-api.js"]
CMD ["/opt/hawtio-online-gateway/gateway.sh"]
18 changes: 18 additions & 0 deletions docker/gateway/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,24 @@ No additional effort should be required to install the gateway image from the [d

Should there be a need to create a custom, development, version then the environment variable, `CUSTOM_GATEWAY_IMAGE` can be populated to change the image. However, bear in mind that the version of this image should always be the same as the hawtio online image so populating `CUSTOM_VERSION` will also require a latter image with that version.

### Logging of the Deployment

By default, the logging level of the gateway container log is set to 'info'. Should more
information be required then this can be modified to either 'debug' or 'trace' by adding
the environment variable `HAWTIO_ONLINE_GATEWAY_LOG_LEVEL` to the deployment:

- `kubectl/oc edit deployment hawtio-online`: Open the deployment resource for editing
- Add the environment variable `HAWTIO_ONLINE_GATEWAY_LOG_LEVEL` with the preferred level
to the `hawtio-online-gateway` container:
```
- env:
- name: HAWTIO_ONLINE_RBAC_ACL
...
- name: HAWTIO_ONLINE_GATEWAY_LOG_LEVEL
value: trace
```
- Save the edit and await the re-deployment of the pod.

## Development

The project file for the gateway provides the following commands that will aid in development and testing of the image:
Expand Down
19 changes: 19 additions & 0 deletions docker/gateway/gateway.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh

# Fail on error and undefined vars
set -eu

export HAWTIO_ONLINE_GATEWAY_LOG_LEVEL="${HAWTIO_ONLINE_GATEWAY_LOG_LEVEL:-info}"

HAWTIO_ONLINE_GATEWAY_ENV_FILE="/opt/hawtio-online-gateway/env.product"

if [ -f "${HAWTIO_ONLINE_GATEWAY_ENV_FILE}" ]; then
cp ${HAWTIO_ONLINE_GATEWAY_ENV_FILE} /tmp
sed -i -e "s/^LOG_LEVEL.*/LOG_LEVEL=${HAWTIO_ONLINE_GATEWAY_LOG_LEVEL}/" /tmp/env.product
cat /tmp/env.product > ${HAWTIO_ONLINE_GATEWAY_ENV_FILE}
fi

node \
--enable-source-maps \
--env-file=${HAWTIO_ONLINE_GATEWAY_ENV_FILE} \
/opt/hawtio-online-gateway/gateway-api.js

0 comments on commit a53192c

Please sign in to comment.