Skip to content

Commit

Permalink
New docker image
Browse files Browse the repository at this point in the history
- exposed all ports as on local machine
- secured admin - user admin, password admin as default
- debug can be set by env property, see also other env options
- tini is not required, finally
- server.log disabled, using just --verbose and docker logs

Signed-off-by: David Matějček <david.matejcek@omnifish.ee>
  • Loading branch information
dmatej committed Jan 25, 2023
1 parent 4e6a267 commit 4532458
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 0 deletions.
119 changes: 119 additions & 0 deletions appserver/distributions/docker/pom.xml
@@ -0,0 +1,119 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2023 Contributors to Eclipse Foundation.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
http://www.eclipse.org/legal/epl-2.0.
This Source Code may also be made available under the following Secondary
Licenses when the conditions for such availability set forth in the
Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
version 2 with the GNU Classpath Exception, which is available at
https://www.gnu.org/software/classpath/license.html.
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
-->

<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>org.glassfish.main.distributions</groupId>
<artifactId>distributions</artifactId>
<version>7.0.1-SNAPSHOT</version>
</parent>

<artifactId>docker</artifactId>
<packaging>pom</packaging>

<name>Glassfish Full Profile Distribution - Docker</name>

<properties>
<glassfish.version>${project.version}</glassfish.version>
<docker.glassfish.repository>glassfish</docker.glassfish.repository>
<docker.glassfish.tag>${glassfish.version}</docker.glassfish.tag>
<docker.glassfish.image>${docker.glassfish.repository}:${docker.glassfish.tag}</docker.glassfish.image>
</properties>
<dependencies>
<dependency>
<groupId>org.glassfish.main.distributions</groupId>
<artifactId>glassfish</artifactId>
<version>${project.version}</version>
<type>zip</type>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.40.3</version>
<executions>
<execution>
<id>build-docker-image</id>
<goals>
<goal>build</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
<configuration>
<verbose>true</verbose>
<images>
<image>
<name>${docker.glassfish.repository}</name>
<build>
<tags>
<tag>${docker.glassfish.tag}</tag>
</tags>
<cleanup>none</cleanup>
<noCache>true</noCache>
<dockerFile>Dockerfile</dockerFile>
<filter>@</filter>
<assembly>
<mode>dir</mode>
<name>glassfish</name>
<inline xmlns="http://maven.apache.org/ASSEMBLY/2.1.1"
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>
<includes>
<include>org.glassfish.main.distributions:glassfish</include>
</includes>
<unpack>true</unpack>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>src/main/docker</directory>
<includes>
<include>run-glassfish.sh</include>
</includes>
<outputDirectory>glassfish7/bin</outputDirectory>
<fileMode>0770</fileMode>
</fileSet>
</fileSets>
</inline>
</assembly>
</build>
</image>
</images>
</configuration>
</plugin>
</plugins>
</build>
</project>
47 changes: 47 additions & 0 deletions appserver/distributions/docker/src/main/docker/Dockerfile
@@ -0,0 +1,47 @@
FROM eclipse-temurin:17-jdk

ADD glassfish /opt

EXPOSE 4848 9009 8080 8181 7676 8686 3700 3820 3920 6666

# You should use own credentials and own files! These are just defaults.
ARG PATH_GF_PASSWORD_FILE_FOR_CHANGE=/password-change.txt
ENV PATH_GF_HOME=/opt/glassfish7
ENV AS_USER=admin \
AS_ADMIN_PASSWORD=admin \
AS_PASSWORD_FILE=/password.txt \
AS_TRACE=false \
AS_TRACE_LOGGING=false \
AS_TRACE_BOOTSTRAP=false \
AS_DEBUG_PORT_ENABLED=false \
AS_STOP_TIMEOUT=9500 \
PATH_GF_BIN=${PATH_GF_HOME}/bin \
PATH_GF_SERVER_LOG="${PATH_GF_HOME}/glassfish/domains/domain1/logs/server.log"
ENV PATH="${PATH_GF_BIN}:${PATH}"

RUN true \
&& set -x \
&& mkdir -p "${PATH_GF_HOME}" \
&& useradd -l -u 1000 -d "${PATH_GF_HOME}" -s /bin/bash glassfish \
&& echo glassfish:glassfish | chpasswd \
&& echo "Generating password file at ${AS_PASSWORD_FILE} ..." \
&& echo "AS_ADMIN_PASSWORD=${AS_ADMIN_PASSWORD}" > "${AS_PASSWORD_FILE}" \
&& echo "AS_ADMIN_PASSWORD=" > "${PATH_GF_PASSWORD_FILE_FOR_CHANGE}" \
&& echo "AS_ADMIN_NEWPASSWORD=${AS_ADMIN_PASSWORD}" >> "${PATH_GF_PASSWORD_FILE_FOR_CHANGE}" \
&& echo "" >> "${PATH_GF_PASSWORD_FILE_FOR_CHANGE}" \
&& env | sort \
&& asadmin start-domain \
&& asadmin --user ${AS_USER} --passwordfile ${PATH_GF_PASSWORD_FILE_FOR_CHANGE} change-admin-password \
&& asadmin stop-domain --kill \
&& asadmin start-domain \
&& asadmin --user ${AS_USER} --passwordfile ${AS_PASSWORD_FILE} set-log-attributes org.glassfish.main.jul.handler.GlassFishLogHandler.enabled=false \
&& asadmin --user ${AS_USER} --passwordfile ${AS_PASSWORD_FILE} set-log-attributes org.glassfish.main.jul.handler.SimpleLogHandler.level=FINEST \
&& asadmin --user ${AS_USER} --passwordfile ${AS_PASSWORD_FILE} enable-secure-admin \
&& asadmin --user ${AS_USER} --passwordfile ${AS_PASSWORD_FILE} stop-domain \
&& rm -f ${PATH_GF_SERVER_LOG} ${PATH_GF_PASSWORD_FILE_FOR_CHANGE} \
&& chown -R glassfish:glassfish "${PATH_GF_HOME}" \
&& ls -la ${PATH_GF_BIN} \
&& echo "Installation was successful."
USER glassfish
WORKDIR ${PATH_GF_HOME}
ENTRYPOINT ["run-glassfish.sh"]
12 changes: 12 additions & 0 deletions appserver/distributions/docker/src/main/docker/run-glassfish.sh
@@ -0,0 +1,12 @@
#!/bin/bash
set -e;
on_exit () {
EXIT_CODE=$?
set +e;
ps -lAf;
asadmin stop-domain --force --kill;
exit $EXIT_CODE;
}
trap on_exit EXIT

env|sort && asadmin start-domain --debug=${AS_DEBUG_PORT_ENABLED} --verbose
9 changes: 9 additions & 0 deletions appserver/distributions/pom.xml
Expand Up @@ -58,6 +58,15 @@
<module>glassfish-common</module>
</modules>

<profiles>
<profile>
<id>docker</id>
<modules>
<module>docker</module>
</modules>
</profile>
</profiles>

<properties>
<findbugs.skip>true</findbugs.skip>
<stage.dir.name>stage</stage.dir.name>
Expand Down

0 comments on commit 4532458

Please sign in to comment.