Wednesday, August 28, 2019

Throntail logging - json formatter

java -jar demo-thorntail.jar -Dthorntail.logging.json-formatters.JSON=json-foramtter -Dthorntail.logging.console-handlers.CONSOLE.named-formatter=JSON

Saturday, April 20, 2019

Wildfly + Graylog + Docker

Dockerfile
FROM jboss/wildfly
MAINTAINER Andrzej Szywala 
ADD gelf-module $JBOSS_HOME/modules/system/layers/base/
ADD execute.sh $JBOSS_HOME/execute.sh
ADD gelf.cli $JBOSS_HOME/gelf.cli

ENV GRAYLOG_URL=""
ENV GRAYLOG_PORT=""
ENV APP="hellojee"
ENV APPVER="1.0"

RUN cp $JBOSS_HOME/standalone/configuration/standalone.xml $JBOSS_HOME/standalone/configuration/standalone-gelf.xml
RUN cp $JBOSS_HOME/standalone/configuration/standalone-ha.xml $JBOSS_HOME/standalone/configuration/standalone-ha-gelf.xml
RUN cp $JBOSS_HOME/standalone/configuration/standalone-full.xml $JBOSS_HOME/standalone/configuration/standalone-full-gelf.xml
RUN cp $JBOSS_HOME/standalone/configuration/standalone-full-ha.xml $JBOSS_HOME/standalone/configuration/standalone-full-ha-gelf.xml

ENV CONFIG_XML standalone-full-ha-gelf.xml
RUN $JBOSS_HOME/bin/jboss-cli.sh --file=$JBOSS_HOME/gelf.cli
ENV CONFIG_XML standalone-full-gelf.xml
RUN $JBOSS_HOME/bin/jboss-cli.sh --file=$JBOSS_HOME/gelf.cli
ENV CONFIG_XML standalone-gelf.xml
RUN $JBOSS_HOME/bin/jboss-cli.sh --file=$JBOSS_HOME/gelf.cli
ENV CONFIG_XML standalone-ha-gelf.xml
RUN $JBOSS_HOME/bin/jboss-cli.sh --file=$JBOSS_HOME/gelf.cli
# WFLYCTL0056: Could not rename /opt/coig/wildfly/standalone/configuration/standalone_xml_history/current to /opt/coig/wildfly/standalone/configuration/standalone_xml_history/20180415-085446266: java.nio.file.DirectoryNotEmptyException: /opt/coig/wildfly/standalone/configuration/standalone_xml_history/current
RUN rm -R $JBOSS_HOME/standalone/configuration/standalone_xml_history
ENTRYPOINT $JBOSS_HOME/execute.sh
gelf.cli
embed-server --server-config=${env.CONFIG_XML}
batch 
/subsystem=logging/custom-handler="GelfLogger":add(class="biz.paluch.logging.gelf.wildfly.WildFlyGelfLogHandler", module="biz.paluch.logging",properties={"host"=>"${env.GRAYLOG_URL}","port"=>"${env.GRAYLOG_PORT}","version"=>"1.1","facility"=>"java-test","extractStackTrace"=>"true","filterStackTrace"=>"true","mdcProfiling"=>"true","timestampPattern"=>"yyyy-MM-dd HH:mm:ss,SSSS","maximumMessageSize"=>"8192", "additionalFields"=>"APP=${env.APP},APPVER=${env.APPVER}"})
/subsystem=logging/root-logger=ROOT:add-handler(name=GelfLogger)
/subsystem=logging/root-logger=ROOT:remove-handler(name=CONSOLE)
/subsystem=logging/root-logger=ROOT:remove-handler(name=FILE)
# Execute the batch
run-batch
stop-embedded-server
quit
execute.sh
#!/bin/bash
JBOSS_CLI=$JBOSS_HOME/bin/jboss-cli.sh
JBOSS_CONFIG=${JBOSS_CONFIG:-"standalone.xml"}

exec $JBOSS_HOME/bin/standalone.sh -b `hostname -i` -c $JBOSS_CONFIG 
exit $?
Build image
docker build -t gelf .
Run image
docker run -it -e "GRAYLOG_URL=udp:graylog.example.com" -e "GRAYLOG_PORT=12203" -e "JBOSS_CONFIG=standalone-gelf.xml" -p 8080:8080 gelf
Sources: https://github.com/andrzejszywala/docker-images/tree/master/gelf

Sunday, April 14, 2019

Access log in Wildfly on Docker

Dockerfile
FROM jboss/wildfly
MAINTAINER Andrzej Szywala 
ADD acl.cli $JBOSS_HOME/acl.cli
ADD execute.sh $JBOSS_HOME/execute.sh

RUN cp $JBOSS_HOME/standalone/configuration/standalone.xml $JBOSS_HOME/standalone/configuration/standalone-acl.xml
RUN cp $JBOSS_HOME/standalone/configuration/standalone-ha.xml $JBOSS_HOME/standalone/configuration/standalone-ha-acl.xml
RUN cp $JBOSS_HOME/standalone/configuration/standalone-full.xml $JBOSS_HOME/standalone/configuration/standalone-full-acl.xml
RUN cp $JBOSS_HOME/standalone/configuration/standalone-full-ha.xml $JBOSS_HOME/standalone/configuration/standalone-full-ha-acl.xml

ENV CONFIG_XML standalone-full-ha-acl.xml
RUN $JBOSS_HOME/bin/jboss-cli.sh --file=$JBOSS_HOME/acl.cli
ENV CONFIG_XML standalone-full-acl.xml
RUN $JBOSS_HOME/bin/jboss-cli.sh --file=$JBOSS_HOME/acl.cli
ENV CONFIG_XML standalone-acl.xml
RUN $JBOSS_HOME/bin/jboss-cli.sh --file=$JBOSS_HOME/acl.cli
ENV CONFIG_XML standalone-ha-acl.xml
RUN $JBOSS_HOME/bin/jboss-cli.sh --file=$JBOSS_HOME/acl.cli
# WFLYCTL0056: Could not rename /opt/coig/wildfly/standalone/configuration/standalone_xml_history/current to /opt/coig/wildfly/standalone/configuration/standalone_xml_history/20180415-085446266: java.nio.file.DirectoryNotEmptyException: /opt/coig/wildfly/standalone/configuration/standalone_xml_history/current
RUN rm -R $JBOSS_HOME/standalone/configuration/standalone_xml_history
ENTRYPOINT $JBOSS_HOME/execute.sh
acl.cli
embed-server --server-config=${env.CONFIG_XML}
batch 
/subsystem=undertow/server=default-server/host=default-host/setting=access-log:add(use-server-log=true)
# Execute the batch
run-batch
stop-embedded-server
quit
execute.sh
#!/bin/bash
JBOSS_CLI=$JBOSS_HOME/bin/jboss-cli.sh
JBOSS_CONFIG=${JBOSS_CONFIG:-"standalone.xml"}

exec $JBOSS_HOME/bin/standalone.sh -b `hostname -i` -c $JBOSS_CONFIG 
exit $?
Build image
docker build -t acl .
Run image
docker run -it -e "JBOSS_CONFIG=standalone-acl.xml" -p 8080:8080 acl
https://github.com/andrzejszywala/docker-images/tree/master/gelf

Tuesday, March 19, 2019

Smaller Wildfly image with Galeon

First lets create Docker image in standard way:
FROM jboss/wildfly
RUN curl -Ls https://github.com/andrzejszywala/hellojee/raw/master/hellojee.war -o /opt/jboss/wildfly/standalone/deployments/hellojee.war
Build image
docker build -t hello_wildfly .
docker image ls
REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
hello_wildfly            latest              cc8926d06bf0        25 minutes ago      745MB
Now lets use Galeon to create smaller wildfly
# In first stage prepare wildfly 
FROM adoptopenjdk/openjdk11:alpine-slim as WILDFLY_BUILD
ENV GALEON_VERSION 3.0.2.Final 
RUN apk --update add --no-cache --virtual .build-deps unzip curl bash
RUN curl -Ls https://github.com/wildfly/galleon/releases/download/$GALEON_VERSION/galleon-$GALEON_VERSION.zip -o /tmp/galeon.zip
RUN unzip /tmp/galeon.zip -d /tmp
RUN /tmp/galleon*/bin/galleon.sh install wildfly:current --layers=cdi,jaxrs,jpa,h2-database --dir=/tmp/wildfly 
RUN curl -Ls https://github.com/andrzejszywala/hellojee/raw/master/hellojee.war -o /tmp/wildfly/standalone/deployments/hellojee.war

# Second stage builds final image 
FROM adoptopenjdk/openjdk11:alpine-slim 
ENV LAUNCH_JBOSS_IN_BACKGROUND true
EXPOSE 8080
# Copy wildfly with application from temporary image
COPY --from=WILDFLY_BUILD /tmp/wildfly /opt/wildfy
CMD ["/opt/wildfy/bin/standalone.sh", "-b", "0.0.0.0"]
Build image
docker build -t hello_galeon .
docker image ls
REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
hello_galeon             latest              a719b9633749        13 minutes ago      365MB
As you can see image is half the size.