18 Nisan 2022 Pazartesi

Docker ve Wildfly

Örnek - Kullanmayın
Kullanmayın çünkü "jboss/wildfly" artık "quay.io" olarak değişti. Şöyle yaparız
FROM jboss/wildfly
ADD my-app.war /opt/jboss/wildfly/standalone/deployments/
ve şöyle yaparız
docker build --tag=my-app . && docker run -it my-app
Örnek - quay.io 
Şöyle yaparız. -b ile bind seçenekleri belirtiliyor.
FROM quay.io/wildfly/wildfly:26.0.0.Final
COPY my-standalone.xml /opt/jboss/wildfly/standalone/configuration/
#Deploy
COPY ./target/*.war /opt/jboss/wildfly/standalone/deployments/

# Run with custom configuration
CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0", "-bmanagement", "0.0.0.0",
  "-c","my-standalone.xml"]
Bu image için kullanılan DockerFile GitHub'da burada. Burada FROM jboss/base-jdk:11 görülebilir.
jboss/base-jdk:11 için kullanılan DockerFile GitHub'da burada. FROM jboss/base:latest görülebilir
jboss/base için kullanılan DockerFile GitHub'da burada. FROM centos:7 görülebilir

Örnek -  quay.io  + runtime
Şöyle yaparız
FROM quay.io/wildfly/wildfly-runtime-jdk11
COPY --chown=jboss:root target/server $JBOSS_HOME
RUN chmod -R ug+rwX $JBOSS_HOME
Örnek - Admin Kullanıcısı
Şöyle yaparız
FROM quay.io/wildfly/wildfly
#Create user
RUN /opt/jboss/wildfly/bin/add-user.sh admin Admin#70365 --silent

CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0", "-bmanagement", "0.0.0.0"]
Örnek - Olmayan bir Wildfly Sürümünü İndir ve JDK Kur
Şöyle yaparız. Burada JDK 17 de kuruluyor
#Bring centos
FROM redhat/ubi8

# Create a user and group used to launch processes
# The user ID 1000 is the default for the first "regular" user on Fedora/RHEL,
# so there is a high chance that this ID will be equal to the current user
# making it easier to use volumes (no permission issues)
RUN groupadd -r jboss -g 1000 && useradd -u 1000 -r -g jboss -m -d /opt/jboss -s /sbin/nologin -c "JBoss user" jboss && \
    chmod 755 /opt/jboss

# Set the working directory to jboss' user home directory
WORKDIR /opt/jboss

# Install JDK 17
RUN yum -y install java-17-openjdk-devel && yum clean all

# Switch back to jboss user
USER jboss

# Set the JAVA_HOME variable to make it clear where Java is located
ENV JAVA_HOME /usr/lib/jvm/java

##Install Wildfly
# Set the WILDFLY_VERSION env variable
ENV WILDFLY_VERSION 25.0.0.Final
ENV WILDFLY_SHA1 238e67f48f1bd1e79f2d845cba9194dcd54b4d89
ENV JBOSS_HOME /opt/jboss/wildfly

USER root

# Add the WildFly distribution to /opt, and make wildfly the owner of the extracted tar content
# Make sure the distribution is available from a well-known place
RUN cd $HOME \
    && curl -L -O https://github.com/wildfly/wildfly/releases/download/$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}

# Create folders for batch processing
RUN bash -c 'mkdir -p /advdata/TspFt/BatchProcessingRoot/rwbat/{input,tmp,output,classicInput,classicTmp,classicOutput}'
RUN chown -R jboss /advdata/TspFt/BatchProcessingRoot/rwbat/

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

USER jboss

# Expose the ports in which we're interested
EXPOSE 8080
EXPOSE 9990


#Deploy
ADD  modules/system/layers/base/com /opt/jboss/wildfly/modules/system/layers/base/com/
COPY standalone-full.xml /opt/jboss/wildfly/standalone/configuration
COPY ./build/libs/rwGuiEar.ear /opt/jboss/wildfly/standalone/deployments/

#Create user
RUN /opt/jboss/wildfly/bin/add-user.sh admin Admin#70365 --silent

# Set the default command to run on boot
# This will boot WildFly in standalone mode and bind to all interfaces
CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0", "-bmanagement", "0.0.0.0", "-c","standalone-full.xml"]
Eğer deploy işlemini bir artifactory sunucusundan yapıyorsak şöyle yaparız
...

USER root
RUN curl http://artifactory.foo.com/artifactory/release-local/mysql-connector-java-8.0.17.jar > /opt/jboss/wildfly/modules/system/layers/base/com/mysql/main/mysql-connector-java-8.0.17.jar

USER jboss
COPY files/standalone-full.xml /opt/jboss/wildfly/standalone/configuration
RUN curl http://artifactory.foo.com/release/rwGuiEar.ear > /opt/jboss/wildfly/standalone/deployments/rwGuiEar.ear

...
Çalıştırmak için şöyle yaparız. Burada yerelde çalışan vitesstestserver isimli container, wildfly25 ile aynı ağa alınıyor
# Create a network
docker network create myNetwork

# build image
docker build -t wildfly25 .
docker run -d --rm --network myNetwork --name wildfly25
  -p 8080:8080 -p 9990:9990 wildfly25

# Connect a running container to a network
docker network connect myNetwork vitesstestserver
veya vitesstestserver'ı başlatırken ağa almak için şöyle yaparız
docker build -t vitesstestserver .
docker run --rm --name vitesstestserver --network myNetwork
  -p 33577:33577 vitesstestserver
Bağlanmak için şöyle yaparız
http://localhost:8080/rwgui/
Örnek - /usr/sbin/sshd kullanan Redhat/ubi8
Burada wildfly + ssh kuruluyor. Şöyle yaparız
#Bring OS
FROM redhat/ubi8

# Create a user and group that is used to launch processes
# The user ID 1000 is the default for the first "regular" user on Fedora/RHEL,
# so there is a high chance that this ID will be equal to the current user
# making it easier to use volumes (no permission issues)
RUN groupadd -r jboss -g 1000 && useradd -u 1000 -r -g jboss -m -d /opt/jboss -c "JBoss user" jboss && \
    chmod 755 /opt/jboss


# Set the working directory to jboss user's home directory
WORKDIR /opt/jboss

# Install SSH Server, JDK 17
RUN yum -y install \
    sudo \
    openssh-server \
    openssh-clients \
    java-17-openjdk-devel && yum clean all

USER jboss
RUN ssh-keygen -A

USER root
RUN ssh-keygen -A

# Set passwords
RUN echo root:login-1 | chpasswd
RUN echo jboss:login-1 | chpasswd

# Set the JAVA_HOME variable to make it clear where Java is located
ENV JAVA_HOME /usr/lib/jvm/java

##Install Wildfly
# Set the WILDFLY_VERSION env variable
ENV WILDFLY_VERSION 25.0.0.Final
ENV WILDFLY_SHA1 238e67f48f1bd1e79f2d845cba9194dcd54b4d89
ENV JBOSS_HOME /opt/jboss/wildfly

ADD start.sh /
RUN chmod +x /start.sh

# Add the WildFly distribution to /opt/jboss, and make jboss user the owner of the extracted tar content
# Make sure the distribution is available from a well-known place
RUN cd $HOME \
    && curl -L -O https://github.com/wildfly/wildfly/releases/download/$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}

# Create folders for batch processing
RUN bash -c 'mkdir -p /advdata/TspFt/BatchProcessingRoot/rwbat/{input,tmp,output,classicInput,classicTmp,classicOutput}'
RUN chown -R jboss /advdata/TspFt/BatchProcessingRoot/rwbat/

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

USER jboss

# Expose the ports in which we're interested
EXPOSE 22
EXPOSE 8080
EXPOSE 9990


#Deploy local files
ADD  modules/system/layers/base/com /opt/jboss/wildfly/modules/system/layers/base/com/
COPY standalone-full.xml /opt/jboss/wildfly/standalone/configuration
COPY ./build/libs/rwGuiEar.ear /opt/jboss/wildfly/standalone/deployments/

#Create user on wildfly for management
RUN /opt/jboss/wildfly/bin/add-user.sh admin login-1 --silent

# Run as root
USER root

# Set the default command to run on boot
CMD ["/start.sh"]
start.sh şöyle
#!/bin/bash
/usr/sbin/sshd -D &

# This will boot WildFly in standalone mode and bind to all interfaces
sudo -u jboss /opt/jboss/wildfly/bin/standalone.sh -b 0.0.0.0 -bmanagement 0.0.0.0 -c standalone-full.xml
Örnek 
4 tane ubi image var.
micro, minimal, standard, ve init.

micro için açıklama şöyle
The ubi-micro is the smallest possible UBI image, obtained by excluding a package manager and all of its dependencies which are normally included in a container image. This minimizes the attack surface of container images based on the ubi-micro image and is suitable for minimal applications, even if you use UBI Standard, Minimal, or Init for other applications. The container image without the Linux distribution packaging is called a Distroless container image.
Açıklaması şöyle
In the following Dockerfile, we utilize the ubi-init (multi-service) image, which supports systemd and has the CMD /sbin/init as the default to start the systemd init service. 
Şöyle yaparız
FROM ubi8/ubi-init

ARG ADMIN_PUBLIC_KEY
ARG TESTER2_PUBLIC_KEY

RUN yum -y install openssh-server openssh-clients 
  && yum clean all && systemctl enable sshd;
...
EXPOSE 2022

CMD ["/sbin/init"]
Örnek - service komutunu kullanan Ubuntu
Şöyle yaparız. Burada ssh için "UsePAM yes" kullanılıyor.
#Bring OS
FROM ubuntu

# Create a user and group that is used to launch processes
# The user ID 1000 is the default for the first "regular" user on Fedora/RHEL,
# so there is a high chance that this ID will be equal to the current user
# making it easier to use volumes (no permission issues)
RUN groupadd -r jboss -g 1000 && useradd -u 1000 -r -g jboss -m -d /opt/jboss -c "JBoss user" jboss && \
    chmod 755 /opt/jboss


# Set the working directory to jboss user's home directory
WORKDIR /opt/jboss

# Install SSH Server, JDK 17
RUN apt-get update && apt-get install -y \
    sudo \
    curl \
    openssh-server \
    openssh-client \
    openjdk-17-jdk && apt-get clean all


# Set passwords
RUN echo root:login-1 | chpasswd
RUN echo jboss:login-1 | chpasswd

# Set the JAVA_HOME variable to make it clear where Java is located
ENV JAVA_HOME /usr/lib/jvm/java-1.17.0-openjdk-amd64

##Install Wildfly
# Set the WILDFLY_VERSION env variable
ENV WILDFLY_VERSION 25.0.0.Final
ENV WILDFLY_SHA1 238e67f48f1bd1e79f2d845cba9194dcd54b4d89
ENV JBOSS_HOME /opt/jboss/wildfly

ADD docker/ubuntu/start.sh /
RUN chmod +x /start.sh

# Add the WildFly distribution to /opt/jboss, and make jboss user the owner of the extracted tar content
# Make sure the distribution is available from a well-known place
RUN cd $HOME \
    && curl -L -O https://github.com/wildfly/wildfly/releases/download/$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}

# Create folders for batch processing
RUN bash -c 'mkdir -p /advdata/TspFt/BatchProcessingRoot/rwbat/{input,tmp,output,classicInput,classicTmp,classicOutput}'
RUN chown -R jboss /advdata/TspFt/BatchProcessingRoot/rwbat/

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

USER jboss

# Expose the ports in which we're interested
EXPOSE 22
EXPOSE 8080
EXPOSE 9990


#Deploy local files
ADD  docker/modules/system/layers/base/com /opt/jboss/wildfly/modules/system/layers/base/com/
COPY docker/standalone-full.xml /opt/jboss/wildfly/standalone/configuration
COPY build/libs/rwGuiEar.ear /opt/jboss/wildfly/standalone/deployments/

#Create user on wildfly for management
RUN /opt/jboss/wildfly/bin/add-user.sh admin login-1 --silent

# Run as root
USER root

# Set the default command to run on boot
CMD ["/start.sh"]
start.sh şöyledir
service ssh restart

# This will boot WildFly in standalone mode and bind to all interfaces
sudo -u jboss /opt/jboss/wildfly/bin/standalone.sh -b 0.0.0.0 -bmanagement 0.0.0.0 -c standalone-full.xml


Hiç yorum yok:

Yorum Gönder

Bean Validation @GroupSequence Anotasyonu

Örnek Elimizde şöyle bir kod olsun public class SampleRequest {   @NotNull   LocalDate startDate;   @NotNull   LocalDate endDate;   @AssertT...