Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CUSTCOM-130 Add payara-web Docker Image #4628

Merged
merged 3 commits into from
Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions appserver/extras/docker-images/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<modules>
<module>server-full</module>
<module>server-web</module>
<module>server-node</module>
<module>micro</module>
<module>tests</module>
Expand Down
25 changes: 25 additions & 0 deletions appserver/extras/docker-images/server-web/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>fish.payara.extras</groupId>
<artifactId>docker-images</artifactId>
<version>5.202-SNAPSHOT</version>
</parent>
<artifactId>server-web-docker-image</artifactId>
<packaging>pom</packaging>
<name>Payara Docker Images - Server Web</name>

<properties>
<dockerRepositoryName>payara/server-web</dockerRepositoryName>
</properties>

<dependencies>
<dependency>
<groupId>fish.payara.distributions</groupId>
<artifactId>payara-web</artifactId>
<type>zip</type>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
FROM @docker.java.image@

# Default payara ports to expose
# 4848: admin console
# 9009: debug port (JPDA)
# 8080: http
# 8181: https
EXPOSE 4848 9009 8080 8181

# Initialize the configurable environment variables
ENV HOME_DIR=/opt/payara\
PAYARA_DIR=/opt/payara/appserver\
SCRIPT_DIR=/opt/payara/scripts\
CONFIG_DIR=/opt/payara/config\
DEPLOY_DIR=/opt/payara/deployments\
PASSWORD_FILE=/opt/payara/passwordFile\
# Payara Server Domain options
DOMAIN_NAME=@docker.payara.domainName@\
ADMIN_USER=admin\
ADMIN_PASSWORD=admin \
# Utility environment variables
JVM_ARGS=\
PAYARA_ARGS=\
DEPLOY_PROPS=\
POSTBOOT_COMMANDS=/opt/payara/config/post-boot-commands.asadmin\
PREBOOT_COMMANDS=/opt/payara/config/pre-boot-commands.asadmin
ENV PATH="${PATH}:${PAYARA_DIR}/bin"

ARG TINI_VERSION=v0.18.0

# Download tini
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini \
https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini.asc /

RUN true \
# Install dependencies
&& apt-get update \
&& apt-get install -y coreutils gpg \
&& rm -rf /var/lib/apt/lists/* \
# Create and set the Payara user and working directory owned by the new user
&& groupadd --gid 1000 payara \
&& useradd -u 1000 -M -s /bin/bash -d ${HOME_DIR} payara -g payara \
&& echo payara:payara | chpasswd \
&& mkdir -p ${DEPLOY_DIR} \
&& mkdir -p ${CONFIG_DIR} \
&& mkdir -p ${SCRIPT_DIR} \
&& chown -R payara: ${HOME_DIR} \
# Verify tini
&& gpg --batch --keyserver "hkp://ipv4.pool.sks-keyservers.net" --recv-keys 595E85A6B1B4779EA4DAAEC70B588DFF0527A9B7 \
&& gpg --batch --verify /tini.asc /tini \
&& chmod +x /tini \
&& true

USER payara
WORKDIR ${HOME_DIR}

COPY --chown=payara:payara maven/artifacts/payara5 ${PAYARA_DIR}/
COPY --chown=payara:payara maven/bin/* ${SCRIPT_DIR}/

RUN true \
# Configure the password file for configuring Payara
&& echo "AS_ADMIN_PASSWORD=\nAS_ADMIN_NEWPASSWORD=${ADMIN_PASSWORD}" > /tmp/tmpfile \
&& echo "AS_ADMIN_PASSWORD=${ADMIN_PASSWORD}" >> ${PASSWORD_FILE} \
# Configure the payara domain
&& ${PAYARA_DIR}/bin/asadmin --user ${ADMIN_USER} --passwordfile=/tmp/tmpfile change-admin-password --domain_name=${DOMAIN_NAME} \
&& ${PAYARA_DIR}/bin/asadmin --user=${ADMIN_USER} --passwordfile=${PASSWORD_FILE} start-domain ${DOMAIN_NAME} \
&& ${PAYARA_DIR}/bin/asadmin --user=${ADMIN_USER} --passwordfile=${PASSWORD_FILE} enable-secure-admin \
&& for MEMORY_JVM_OPTION in \
$(${PAYARA_DIR}/bin/asadmin --user=${ADMIN_USER} --passwordfile=${PASSWORD_FILE} list-jvm-options | grep "Xm[sx]"); \
do\
${PAYARA_DIR}/bin/asadmin --user=${ADMIN_USER} --passwordfile=${PASSWORD_FILE} delete-jvm-options $MEMORY_JVM_OPTION;\
done \
# FIXME: when upgrading this container to Java 10+, this needs to be changed to
# '-XX:+UseContainerSupport' and '-XX:MaxRAMPercentage'
&& ${PAYARA_DIR}/bin/asadmin --user=${ADMIN_USER} --passwordfile=${PASSWORD_FILE} create-jvm-options \
'-XX\:+UnlockExperimentalVMOptions:-XX\:+IgnoreUnrecognizedVMOptions:-XX\:+UseCGroupMemoryLimitForHeap:-XX\:MaxRAMFraction=1' \
&& ${PAYARA_DIR}/bin/asadmin --user=${ADMIN_USER} --passwordfile=${PASSWORD_FILE} \
set-log-attributes com.sun.enterprise.server.logging.GFFileHandler.logtoFile=false \
&& ${PAYARA_DIR}/bin/asadmin --user=${ADMIN_USER} --passwordfile=${PASSWORD_FILE} stop-domain ${DOMAIN_NAME} \
# Cleanup after initialization
&& rm -rf \
/tmp/tmpFile \
${PAYARA_DIR}/glassfish/domains/${DOMAIN_NAME}/osgi-cache \
${PAYARA_DIR}/glassfish/domains/${DOMAIN_NAME}/logs \
&& true

ENTRYPOINT ["/tini", "--"]
CMD "${SCRIPT_DIR}/entrypoint.sh"
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<!--
~ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
~
~ Copyright (c) [2020] Payara Foundation and/or its affiliates. All rights reserved.
~
~ The contents of this file are subject to the terms of either the GNU
~ General Public License Version 2 only ("GPL") or the Common Development
~ and Distribution License("CDDL") (collectively, the "License"). You
~ may not use this file except in compliance with the License. You can
~ obtain a copy of the License at
~ https://github.com/payara/Payara/blob/master/LICENSE.txt
~ See the License for the specific
~ language governing permissions and limitations under the License.
~
~ When distributing the software, include this License Header Notice in each
~ file and include the License file at glassfish/legal/LICENSE.txt.
~
~ GPL Classpath Exception:
~ The Payara Foundation designates this particular file as subject to the "Classpath"
~ exception as provided by the Payara Foundation in the GPL Version 2 section of the License
~ file that accompanied this code.
~
~ Modifications:
~ If applicable, add the following below the License Header, with the fields
~ enclosed by brackets [] replaced by your own identifying information:
~ "Portions Copyright [year] [name of copyright owner]"
~
~ Contributor(s):
~ If you wish your version of this file to be governed by only the CDDL or
~ only the GPL Version 2, indicate your decision by adding "[Contributor]
~ elects to include this software in this distribution under the [CDDL or GPL
~ Version 2] license." If you don't indicate a single choice of license, a
~ recipient has the option to distribute your version of this file under
~ either the CDDL, the GPL Version 2 or to extend the choice of license to
~ its licensees as provided above. However, if you add GPL Version 2 code
~ and therefore, elected the GPL Version 2 license, then the option applies
~ only if the new code is made subject to such option by the copyright
~ holder.
-->

<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<dependencySets>
<dependencySet>
<outputDirectory>artifacts/</outputDirectory>
<scope>provided</scope>
<unpack>true</unpack>
<unpackOptions>
<excludes>
<exclude>payara5/glassfish/domains/domain1/**</exclude>
</excludes>
</unpackOptions>
<outputFileNameMapping>${artifact.artifactId}.${artifact.extension}</outputFileNameMapping>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>src/main/docker/bin</directory>
<outputDirectory>bin</outputDirectory>
<fileMode>0755</fileMode>
</fileSet>
</fileSets>
</assembly>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

for f in ${SCRIPT_DIR}/init_* ${SCRIPT_DIR}/init.d/*; do
case "$f" in
*.sh) echo "[Entrypoint] running $f"; . "$f" ;;
*) echo "[Entrypoint] ignoring $f" ;;
esac
echo
done

exec ${SCRIPT_DIR}/startInForeground.sh $PAYARA_ARGS
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash
################################################################################
#
# A script to append deploy commands to the post boot command file at
# $PAYARA_HOME/scripts/post-boot-commands.asadmin file. All applications in the
# $DEPLOY_DIR (either files or folders) will be deployed.
# The $POSTBOOT_COMMANDS file can then be used with the start-domain using the
# --postbootcommandfile parameter to deploy applications on startup.
#
# Usage:
# ./generate_deploy_commands.sh
#
# Optionally, any number of parameters of the asadmin deploy command can be
# specified as parameters to this script.
# E.g., to deploy applications with implicit CDI scanning disabled:
#
# ./generate_deploy_commands.sh --properties=implicitCdiEnabled=false
#
# Environment variables used:
# - $PREBOOT_COMMANDS - the pre boot command file.
# - $POSTBOOT_COMMANDS - the post boot command file.
#
# Note that many parameters to the deploy command can be safely used only when
# a single application exists in the $DEPLOY_DIR directory.
################################################################################

# Check required variables are set
if [ -z $DEPLOY_DIR ]; then echo "Variable DEPLOY_DIR is not set."; exit 1; fi
if [ -z $PREBOOT_COMMANDS ]; then echo "Variable PREBOOT_COMMANDS is not set."; exit 1; fi
if [ -z $POSTBOOT_COMMANDS ]; then echo "Variable POSTBOOT_COMMANDS is not set."; exit 1; fi

# Create pre and post boot command files if they don't exist
touch $POSTBOOT_COMMANDS
touch $PREBOOT_COMMANDS

deploy() {

if [ -z $1 ]; then
echo "No deployment specified";
exit 1;
fi

DEPLOY_STATEMENT="deploy $DEPLOY_PROPS $1"
if grep -q $1 $POSTBOOT_COMMANDS; then
echo "post boot commands already deploys $1";
else
echo "Adding deployment target $1 to post boot commands";
echo $DEPLOY_STATEMENT >> $POSTBOOT_COMMANDS;
fi
}

# RAR files first
for deployment in $(find $DEPLOY_DIR -mindepth 1 -maxdepth 1 -name "*.rar");
do
deploy $deployment;
done

# Then every other WAR, EAR, JAR or directory
for deployment in $(find $DEPLOY_DIR -mindepth 1 -maxdepth 1 ! -name "*.rar" -a -name "*.war" -o -name "*.ear" -o -name "*.jar" -o -type d);
do
deploy $deployment;
done
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/bash
##########################################################################################################
#
# This script is to execute Payara Server in foreground, mainly in a docker environment.
# It allows to avoid running 2 instances of JVM, which happens with the start-domain --verbose command.
#
# Usage:
# Running
# startInForeground.sh <arguments>
# is equivalent to running
# asadmin start-domain <arguments>
#
# It's possible to use any arguments of the start-domain command as arguments to startInForeground.sh
#
# Environment variables used:
# - $ADMIN_USER - the username to use for the asadmin utility.
# - $PASSWORD_FILE - the password file to use for the asadmin utility.
# - $PREBOOT_COMMANDS - the pre boot command file.
# - $POSTBOOT_COMMANDS - the post boot command file.
# - $DOMAIN_NAME - the name of the domain to start.
# - $JVM_ARGS - extra JVM options to pass to the Payara Server instance.
# - $AS_ADMIN_MASTERPASSWORD - the master password for the Payara Server instance.
#
# This script executes the asadmin tool which is expected at ~/appserver/bin/asadmin.
#
##########################################################################################################

# Check required variables are set
if [ -z $ADMIN_USER ]; then echo "Variable ADMIN_USER is not set."; exit 1; fi
if [ -z $PASSWORD_FILE ]; then echo "Variable PASSWORD_FILE is not set."; exit 1; fi
if [ -z $PREBOOT_COMMANDS ]; then echo "Variable PREBOOT_COMMANDS is not set."; exit 1; fi
if [ -z $POSTBOOT_COMMANDS ]; then echo "Variable POSTBOOT_COMMANDS is not set."; exit 1; fi
if [ -z $DOMAIN_NAME ]; then echo "Variable DOMAIN_NAME is not set."; exit 1; fi

# The following command gets the command line to be executed by start-domain
# - print the command line to the server with --dry-run, each argument on a separate line
# - remove -read-string argument
# - surround each line except with parenthesis to allow spaces in paths
# - remove lines before and after the command line and squash commands on a single line

# Create pre and post boot command files if they don't exist
touch $POSTBOOT_COMMANDS
touch $PREBOOT_COMMANDS

OUTPUT=`${PAYARA_DIR}/bin/asadmin --user=${ADMIN_USER} --passwordfile=${PASSWORD_FILE} start-domain --dry-run --prebootcommandfile=${PREBOOT_COMMANDS} --postbootcommandfile=${POSTBOOT_COMMANDS} $@ $DOMAIN_NAME`
STATUS=$?
if [ "$STATUS" -ne 0 ]
then
echo ERROR: $OUTPUT >&2
exit 1
fi

COMMAND=`echo "$OUTPUT"\
| sed -n -e '2,/^$/p'\
| sed "s|glassfish.jar|glassfish.jar $JVM_ARGS |g"`

echo Executing Payara Server with the following command line:
echo $COMMAND | tr ' ' '\n'
echo

# Run the server in foreground - read master password from variable or file or use the default "changeit" password

set +x
if test "$AS_ADMIN_MASTERPASSWORD"x = x -a -f "$PASSWORD_FILE"
then
source "$PASSWORD_FILE"
fi
if test "$AS_ADMIN_MASTERPASSWORD"x = x
then
AS_ADMIN_MASTERPASSWORD=changeit
fi
echo "AS_ADMIN_MASTERPASSWORD=$AS_ADMIN_MASTERPASSWORD" > /tmp/masterpwdfile
exec ${COMMAND} < /tmp/masterpwdfile
6 changes: 6 additions & 0 deletions appserver/extras/docker-images/tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
<version>${project.version}</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>fish.payara.extras</groupId>
<artifactId>server-web-docker-image</artifactId>
<version>${project.version}</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>fish.payara.extras</groupId>
<artifactId>server-node-docker-image</artifactId>
Expand Down
Loading