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

Support for GlassFish Embedded #16

Merged
merged 1 commit into from
Oct 3, 2024
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
2 changes: 2 additions & 0 deletions src/main/resources/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ RUN true \
&& rm -f ${PATH_GF_SERVER_LOG} ${PATH_GF_PASSWORD_FILE_FOR_CHANGE} \
&& chown -R glassfish:glassfish "${PATH_GF_HOME}" \
&& chmod +x /usr/local/bin/docker-entrypoint.sh \
&& mkdir ${PATH_GF_HOME}/autodeploy \
&& echo "Installation was successful."

USER glassfish
WORKDIR ${PATH_GF_HOME}
ENTRYPOINT ["docker-entrypoint.sh"]
Expand Down
14 changes: 13 additions & 1 deletion src/main/resources/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
#!/bin/bash
set -e;

if [ "$1" != 'asadmin' -a "$1" != 'startserv' ]; then
if [ "$1" != 'asadmin' -a "$1" != 'startserv' -a "$1" != 'runembedded' ]; then
exec "$@"
fi

if [ "$1" == 'runembedded' ]; then
shift 1
if [[ "$SUSPEND" == true ]]
then
JVM_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=9009 $JVM_OPTS"
elif [[ "$DEBUG" == true ]]
then
JVM_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=9009 $JVM_OPTS"
fi
exec java $JVM_OPTS -jar glassfish/lib/embedded/glassfish-embedded-static-shell.jar "$@"
fi

CONTAINER_ALREADY_STARTED="CONTAINER_ALREADY_STARTED_PLACEHOLDER"
if [ ! -f "$CONTAINER_ALREADY_STARTED" ]
then
Expand Down
74 changes: 73 additions & 1 deletion src/main/resources/docs/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

%%LOGO%%

**Source code repository of the Docker image:** https://github.com/OmniFish-EE/docker-library-glassfish
**Source code repository of the Docker image:** https://github.com/eclipse-ee4j/glassfish.docker

## Quick start

Expand Down Expand Up @@ -41,6 +41,29 @@ CONTAINER_ID can be found from the output of the following command:
docker ps
```

### Start GlassFish Embedded

Run GlassFish Embedded runnable JAR (static shell) with the following command:

```
docker run -it -p 8080:8080 @docker.glassfish.repository@ runembedded
```

This will run GlassFish static shell JAR from the GlassFish installation, which is equivalent to running a standalone GlassFish Embedded JAR. If no applications are deployed, GlassFish Embedded will start an interactive prompt to input commands. For this to work in Docker, the `-it` arguments are needed.

To display usage instructions, run:

```
docker run -it -p 8080:8080 @docker.glassfish.repository@ runembedded
```

To deploy an application, copy the application into the Docker image or mount the directory that contains it, and then pass the path to it as an argument. For example, if the application myapp.war is copied to the default `/opt/glassfish7` directory:

```
docker run -p 8080:8080 @docker.glassfish.repository@ runembedded myapp.war
```


## Run an application with GlassFish in Docker

You can run an application located in your filesystem with GlassFIsh in a Docker container.
Expand Down Expand Up @@ -109,6 +132,55 @@ docker logs 5a11f2fe1a9dd1569974de913a181847aa22165b5015ab20b271b08a27426e72
docker stop 5a11f2fe1a9dd1569974de913a181847aa22165b5015ab20b271b08a27426e72
```

## Running GlassFish Embedded

### Run an application

To deploy an application with GlassFish Embedded, copy the application into the Docker image or mount the directory that contains it, and then pass the path to it as an argument. For example, if the application myapp.war is copied to the default `/opt/glassfish7` directory:

```
docker run -p 8080:8080 @docker.glassfish.repository@ runembedded myapp.war
```

You can also just copy applications into the /opt/glassfish7/autodeploy directory or mount a directory with applications to it. All applications in that directory will be automatically deployed. For example, if you have applications on a local directory `/deployments`:

```
docker run -p 8080:8080 -v /deployments:/opt/glassfish7/autodeploy @docker.glassfish.repository@ runembedded
```


### Configure GlassFish Embedded

You can configure GlassFish Embedded by command line aguments after the command runembedded, or by a configuration file. Several options are supported, for example set a different HTTP port or disable HTTP listener, set path to a custom domain configuration, run asadmin commands at startup, deploy applications.

You can also just create a configuration file called `glassfish.properties` in the default directory `/opt/glassfish7`, with all the options, including commands to execute and applications to deploy. Or specify path to a different configuration file with the `--properties` option.

To display usage instructions, run:

```
docker run -it -p 8080:8080 @docker.glassfish.repository@ runembedded
```

This Docker image also supports adding custom Java VM arguments, with the JVM_OPTS environments variable. FOr example, you can specify `-XX:MaxRAMPercentage=75` to set maximum heap size to 75% of RAM:

```
docker run -it -e JVM_OPTS=="-XX:MaxRAMPercentage=75" -p 8080:8080 @docker.glassfish.repository@ runembedded
```


### Debug with GlassFish Embedded

To enable debugging, you can either add a custom debugging instruction for the JVM with the `JVM_OPTS` variable, or you can set one of the following environment variables to `true`:

* `DEBUG` - enables remove debugger on port 9009, doesn't suspend the server
* `SUSPEND` - suspends the server right at the startup and continues when a debugger connects on port 9009

Example:

```
docker run -e SUSPEND=true -p 8080:8080 @docker.glassfish.image@ runembedded
```

## TestContainers

This is probably the simplest possible test with [GlassFish](https://glassfish.org/) and [TestContainers](https://www.testcontainers.org/). It automatically starts the GlassFish Docker Container and then stops it after the test. The test here is quite trivial - downloads the welcome page and verifies if it contains expected phrases.
Expand Down