-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from eclipse-ee4j/gf7019
Updated dependencies + release GlassFish 7.0.19
- Loading branch information
Showing
11 changed files
with
686 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
FROM eclipse-temurin:17.0.13_11-jdk | ||
|
||
LABEL org.opencontainers.image.base.name="eclipse-temurin:17.0.13_11-jdk" | ||
LABEL org.opencontainers.image.source="https://github.com/eclipse-ee4j/glassfish.docker" | ||
LABEL org.opencontainers.image.url="https://github.com/eclipse-ee4j/glassfish.docker/wiki" | ||
|
||
LABEL org.opencontainers.image.title="Eclipse GlassFish" | ||
LABEL org.opencontainers.image.description="The Official Eclipse GlassFish Docker Image" | ||
LABEL org.opencontainers.image.version="7.0.19" | ||
|
||
LABEL org.opencontainers.image.authors="glassfish-dev@eclipse.org" | ||
LABEL org.opencontainers.image.vendor="Eclipse Foundation" | ||
LABEL org.opencontainers.image.licenses="EPL-2.0" | ||
|
||
EXPOSE 4848 9009 8080 8181 7676 8686 3700 3820 3920 6666 | ||
|
||
# You should use own credentials and own files! These are just defaults. | ||
ARG AS_ADMIN_PASSWORD=admin \ | ||
PATH_GF_PASSWORD_FILE_FOR_CHANGE=/password-change.txt \ | ||
UID=1000 \ | ||
GID=1000 | ||
ENV PATH_GF_HOME=/opt/glassfish7 \ | ||
AS_ADMIN_USER=admin \ | ||
AS_ADMIN_PASSWORDFILE=/password.txt | ||
ENV AS_USER=${AS_ADMIN_USER} \ | ||
AS_PASSWORD_FILE=${AS_ADMIN_PASSWORDFILE} \ | ||
AS_TRACE=false \ | ||
AS_TRACE_LOGGING=false \ | ||
AS_TRACE_BOOTSTRAP=false \ | ||
AS_STOP_TIMEOUT=9500 \ | ||
GLASSFISH_DOWNLOAD_SHA512=905c8a795ecf1178aea711e75353587ef66a8097f1e633ca55233c99bb46cecfeaf0f06eb4f9311452846b10715d8a4bd1d254ab6015bd89f92e0057c704c3ad \ | ||
GLASSFISH_VERSION=7.0.19 \ | ||
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}" | ||
|
||
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh | ||
|
||
RUN true \ | ||
&& set -x \ | ||
&& apt update \ | ||
&& apt upgrade -y \ | ||
&& apt install -y gpg unzip \ | ||
&& curl -fL "https://repo1.maven.org/maven2/org/glassfish/main/distributions/glassfish/${GLASSFISH_VERSION}/glassfish-${GLASSFISH_VERSION}.zip.asc" -o glassfish.zip.asc \ | ||
&& curl -fL "https://repo1.maven.org/maven2/org/glassfish/main/distributions/glassfish/${GLASSFISH_VERSION}/glassfish-${GLASSFISH_VERSION}.zip" -o glassfish.zip \ | ||
&& export GNUPGHOME="$(mktemp -d)" \ | ||
&& gpg --batch --keyserver keyserver.ubuntu.com --recv-keys D4A77129F00F736293BE5A51AFC18A2271EDDFE1 \ | ||
&& gpg --batch --verify glassfish.zip.asc glassfish.zip \ | ||
&& rm glassfish.zip.asc \ | ||
&& echo "$GLASSFISH_DOWNLOAD_SHA512 glassfish.zip" | sha512sum --strict --check \ | ||
&& mkdir -p "${PATH_GF_HOME}" \ | ||
&& unzip -q glassfish.zip -d "${PATH_GF_HOME}/.." \ | ||
&& rm glassfish.zip \ | ||
&& userdel -r ubuntu \ | ||
&& groupadd -g ${GID} glassfish \ | ||
&& useradd -r -l -u ${UID} -g ${GID} -d "${PATH_GF_HOME}" -s /bin/bash glassfish \ | ||
&& echo "Generating password file at ${AS_PASSWORD_FILE} ..." \ | ||
&& set +x \ | ||
&& 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}" \ | ||
&& unset AS_ADMIN_PASSWORD \ | ||
&& set -x \ | ||
&& env | sort \ | ||
&& AS_START_TIMEOUT=120000 asadmin start-domain \ | ||
&& curl -o /dev/null http://localhost:4848 \ | ||
&& asadmin --passwordfile ${PATH_GF_PASSWORD_FILE_FOR_CHANGE} change-admin-password \ | ||
&& asadmin stop-domain --kill \ | ||
&& AS_START_TIMEOUT=120000 asadmin start-domain \ | ||
&& curl -o /dev/null http://localhost:4848 \ | ||
&& asadmin set-log-attributes org.glassfish.main.jul.handler.GlassFishLogHandler.enabled=false \ | ||
&& asadmin set-log-attributes org.glassfish.main.jul.handler.SimpleLogHandler.level=FINEST \ | ||
&& asadmin enable-secure-admin \ | ||
&& asadmin stop-domain --kill \ | ||
&& 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"] | ||
CMD ["startserv"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/bin/bash | ||
set -e; | ||
|
||
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 | ||
touch "$CONTAINER_ALREADY_STARTED" && | ||
rm -rf glassfish/domains/domain1/autodeploy/.autodeploystatus || true | ||
fi | ||
|
||
if [ "$1" == 'startserv' ]; then | ||
exec "$@" | ||
fi | ||
|
||
on_exit () { | ||
EXIT_CODE=$? | ||
set +e; | ||
ps -lAf; | ||
asadmin stop-domain --force --kill; | ||
exit $EXIT_CODE; | ||
} | ||
trap on_exit EXIT | ||
|
||
env|sort && "$@" & wait |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Tags: 7.0.19, 7.0.19-jdk17, 7.0.19-jdk17-eclipse-temurin | ||
Architectures: amd64, arm64v8 | ||
Directory: 7.0.19 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Eclipse GlassFish is a Jakarta EE Full Profile compatible implementation. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,221 @@ | ||
# Eclipse GlassFish Docker images | ||
|
||
[Eclipse GlassFish](https://glassfish.org) is a Jakarta EE compatible implementation sponsored by the Eclipse Foundation. | ||
|
||
%%LOGO%% | ||
|
||
**Source code repository of the Docker image:** https://github.com/eclipse-ee4j/glassfish.docker | ||
|
||
## Quick start | ||
|
||
### Start GlassFish | ||
|
||
Run GlassFish with the following command: | ||
|
||
``` | ||
docker run -p 8080:8080 -p 4848:4848 glassfish | ||
``` | ||
|
||
Or with a command for a specific tag (GlassFish version): | ||
|
||
``` | ||
docker run -p 8080:8080 -p 4848:4848 glassfish:7.0.19 | ||
``` | ||
|
||
Open the following URLs in the browser: | ||
|
||
* **Welcome screen:** http://localhost:8080 | ||
* **Administration Console:** https://localhost:4848 - log in using `admin`/`admin` (User name/Password) | ||
|
||
### Stop GlassFish | ||
|
||
Stop GlassFish with the following command: | ||
|
||
``` | ||
docker stop CONTAINER_ID | ||
``` | ||
|
||
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 glassfish 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 glassfish runembedded --help | ||
``` | ||
|
||
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 glassfish 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. | ||
|
||
Follow these steps: | ||
|
||
1. Create an empty directory on your filesystem, e.g. `/deployment` | ||
2. Copy the application package to this directory - so that it's for example on the path `/deployment/application.war` | ||
3. Run the following command to start GlassFish in Docker with your application, where `/deployments` is path to the directory created in step 1: | ||
|
||
``` | ||
docker run -p 8080:8080 -p 4848:4848 -v /deployments:/opt/glassfish7/glassfish/domains/domain1/autodeploy glassfish | ||
``` | ||
|
||
Then you can open the application in the browser with: | ||
|
||
* http://localhost:9080/application | ||
|
||
The context root (`application`) is derived from the name of the application file (e.g. `application.war` would deployed under the `application` context root). If your application file has a different name, please adjust the contest root in the URL accordingly. | ||
|
||
## Debug GlassFish Server inside a Docker container | ||
|
||
You can modify the start command of the Docker container to `startserv --debug` to enable debug mode. You should also map the debug port 9009. | ||
|
||
``` | ||
docker run -p 9009:9009 -p 8080:8080 -p 4848:4848 glassfish startserv --debug | ||
``` | ||
|
||
Then connect your debugger to the port 9009 on `localhost`. | ||
|
||
If you need suspend GlassFish startup until you connect the debugger, use the `--suspend` argument instead: | ||
|
||
``` | ||
docker run -p 9009:9009 -p 8080:8080 -p 4848:4848 glassfish startserv --suspend | ||
``` | ||
|
||
## Examples of advanced usage | ||
|
||
Let's try something more complicated. | ||
|
||
* To modify startup arguments for GlassFish, just add `startserv` to the command line and then add any arguments supported by the `asadmin start-domain` command. The `startserv` script is an alias to the `asadmin start-domain` command but starts GlassFish in a more efficient way that is more suitable in Docker container. For example, to start in debug mode with a custom domain, run: | ||
|
||
```bash | ||
docker run glassfish startserv --debug mydomain | ||
``` | ||
|
||
* Environment variable `AS_TRACE=true` enables tracing of the GlassFish startup. It is useful when the server doesn't start without any useful logs. | ||
|
||
* `docker run` with the `--user` argument configures explicit user id for the container. It can be useful for K8S containers. | ||
|
||
* `docker run` with `-d` starts the container as a daemon, so the shell doesn't print logs and finishes. Docker then returns the container id which you can use for further commands. | ||
|
||
```bash | ||
docker run -d glassfish | ||
``` | ||
|
||
Example of running a Docker container in background, view the logs, and then stop it (with debug enabled, trace logging, and user `1000` convenient for Kubernetes ): | ||
|
||
```bash | ||
docker run -d -e AS_TRACE=true --user 1000 glassfish startserv --debug=true | ||
5a11f2fe1a9dd1569974de913a181847aa22165b5015ab20b271b08a27426e72 | ||
|
||
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 glassfish 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 glassfish 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 glassfish runembedded --help | ||
``` | ||
|
||
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 glassfish 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 remote 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 glassfish:7.0.19 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. | ||
|
||
If you want to run more complicated tests, the good path is to | ||
|
||
1. Write a singleton managing the GlassFish Docker Container or the whole test environment. | ||
2. Write your own Junit5 extension which would start the container before your test and ensure that everything stops after the test including failures. | ||
3. You can also implement direct access to the virtual network, containers, so you can change the environment configuration in between tests and simulate network failures, etc. | ||
|
||
```java | ||
@Testcontainers | ||
public class WelcomePageITest { | ||
|
||
@Container | ||
private final GenericContainer server = new GenericContainer<>("glassfish:7.0.19").withExposedPorts(8080); | ||
|
||
@Test | ||
void getRoot() throws Exception { | ||
URL url = new URL("http://localhost:" + server.getMappedPort(8080) + "/"); | ||
StringBuilder content = new StringBuilder(); | ||
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); | ||
try { | ||
connection.setRequestMethod("GET"); | ||
try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()))) { | ||
String inputLine; | ||
while ((inputLine = in.readLine()) != null) { | ||
content.append(inputLine); | ||
} | ||
} | ||
} finally { | ||
connection.disconnect(); | ||
} | ||
assertThat(content.toString(), stringContainsInOrder("Eclipse GlassFish", "index.html", "production-quality")); | ||
} | ||
|
||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
https://github.com/eclipse-ee4j/glassfish.docker |
Oops, something went wrong.