[Wildfly] 서버 설정

Dockerfile

FROM jboss/base-jdk:8

ENV DEBIAN_FRONTEND noninteractive

# Set the WILDFLY_VERSION env variable
ENV WILDFLY_VERSION 18.0.1.Final
ENV WILDFLY_SHA1 ef0372589a0f08c36b15360fe7291721a7e3f7d9
ENV JBOSS_HOME /opt/jboss/wildfly

USER root
RUN groupmod -g 2000 jboss && usermod -u 2000 jboss

RUN cd $HOME \
    && curl -O https://download.jboss.org/wildfly/$WILDFLY_VERSION/wildfly-$WILDFLY_VERSION.tar.gz \
    && sha1sum wildfly-$WILDFLY_VERSION.tar.gz | grep $WILDFLY_SHA1 \
    && tar xf wildfly-$WILDFLY_VERSION.tar.gz \
    && mv $HOME/wildfly-$WILDFLY_VERSION $JBOSS_HOME \
    && rm wildfly-$WILDFLY_VERSION.tar.gz \
    && chown -R jboss:0 ${JBOSS_HOME} \
    && chmod -R g+rw ${JBOSS_HOME}


COPY instance.conf /opt/jboss/instance.conf
COPY run-standalone.sh /opt/jboss/run-standalone.sh
RUN chown jboss:jboss -R /opt/jboss && chmod a+x /opt/jboss/run-standalone.sh

# RUN mkdir -p /opt/jboss/wildfly/standalone/log && \
#      ln -sf /dev/null /opt/jboss/wildfly/standalone/log/server.log
# RUN mkdir -p /opt/jboss/wildfly/standalone/log && chown -R jboss.jboss /opt/jboss/wildfly/standalone/log
# VOLUME /opt/jboss/wildfly/standalone/log

# Expose the ports we're interested in
EXPOSE 8080

# Ensure signals are forwarded to the JVM process correctly for graceful shutdown
ENV LAUNCH_JBOSS_IN_BACKGROUND true

USER jboss

# Set the default command to run on boot
# This will boot WildFly in the standalone mode and bind to all interface
# CMD ["/opt/jboss/run-standalone.sh", "-b", "0.0.0.0"]
# CMD ["/opt/jboss/run-standalone.sh"]

docker.compose.yml

version: '3'
services:
    was1:
        build:
            context: .
        image: was-s0101
        container_name: c-was-s0101
        restart: unless-stopped
        environment:
            MY_INSTANCE_NAME: s0101
        ports:
            - 8001:8080
        volumes:
            - /app/NAS/project/kmac:/NAS
            - /app/root/data/project/kmac/web-admin:/project/web-admin
            - /app/root/log/s0101:/project/logs
            - /app/root/data/wildfly/s0101/deployments:/opt/jboss/wildfly/standalone/deployments
        command: /opt/jboss/run-standalone.sh
        networks:
            - mybridge
networks:
    mybridge:
        external: true

scripts

원래 하고자 하는 내용은 이건데

$ docker-compose -f docker-compose.s0101.yml up -d
$ docker-compose -f docker-compose.s0101.yml up

실제로 요렇게 작성했다(보완필요)

instance_name=$1
extra_option=$2
# check clone folder
if [ "$instance_name" == "" ];then
    echo "Usage:"
    echo "$0 <instance_name> [extra-options]"
    echo "example: $0 s0101 "
    echo "         $0 s0101 -it bash"
    echo "         $0 s0101 -d"
    exit 1
fi

instance_config_file="docker-compose.${instance_name}.yml"
if [ ! -e $instance_config_file ]
then
    echo "No such file: $instance_config_file"
    exit 2
fi

mkdir -p /app/root/log/$instance_name
mkdir -p /app/root/data/wildfly/$instance_name

sudo chown app.root -R /app/root/log/$instance_name
sudo chown app.app -R /app/root/data/wildfly/$instance_name

    # -f docker-compose.yml \
    # -d \
instance_name=$instance_name \
  docker-compose \
    -f docker-compose.$instance_name.yml up \
    -d \
    --build $extra_option

WILDFLY 서버 설정

TODO

wildfly와 도커에 대한 고민

Wildfly 서버 설정

Wildfly 인스턴스

폴더 구조의 이해

standalone 모드를 기준으로 개발하는 것을 가정한다.

wildfly에서 공식 배포한 docker의 설정에서 기본 디렉토리는 아래와 같다. 컨테이너 내부의 디렉토리이다.

/opt/jboss/wildfly/standalone/
/opt/jboss/wildfly/standalone/log
/opt/jboss/wildfly/standalone/deployments
/opt/jboss/wildfly/standalone/configuration

deploy 하기

volumes:
  - /app/root/data/wildfly/s0101/deployments:/opt/jboss/wildfly/standalone/deployments
WAR 파일 업로드
$  scp build/libs/kmac.war app@192.168.x.x:/app/NAS/opt/wars/kmac/kmac.war
디플로이
$  cd /app/services/wildfly/scripts/s0101/kmac
$  ./deploy.sh

# 또는 undeploy
$  ./undeploy.sh

deploy.sh는 업로드한 war 파일을 /app/root/data/wildfly/s0101/deployments 폴더에 복사하는 스크립트다. 별거 없다.

redeploy 앨리어스 만들기

매번 폴더를 찾아서 deploy 하기는 번거로우니 아래와 같이 alias를 만든다.

alias redeploy1-kmac='/app/services/wildfly/scripts/s0101/kmac/deploy.sh'
alias redeploy2-kmac='/app/services/wildfly/scripts/s0102/kmac/deploy.sh'
alias redeploy-kmac='redeploy1-kmac'

로그 보기

volumes:
  - /app/root/log/s0101:/project/logs
  - ... 다른 매핑은 생략 ...
$ cat /app/services/wildfly/instance1.conf
LOG_DIR="/project/logs"
... 생략 ...
$  tail -f /app/root/log/s0101/server.log
$  cat ~/.bashrc
alias jlog1='tail -f /app/root/log/s0101/server.log'
alias jlog2='tail -f /app/root/log/s0102/server.log'
alias jlog='jlog1'