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

Updated documentation for the docker image #8

Merged
merged 1 commit into from
Aug 31, 2023
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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ See https://www.eclipse.org/legal/epl-2.0/
* Don't forget to update the `GitCommit` line with the commit id
* Don't forget to add the `latest` tag to the latest version (as the first one) and remove it
from the previous version.
4. Visit the `docker-library/docs` repository and replace the contents of the `glassfish` directory with the contents of the `target/classes/docs` directory

### New Version in an Own Repository

Sometimes you need a customized version. OmniFish decided to push it's images to its own repository until Docker Hub decides to merge our PR.
Sometimes you need a customized version. OmniFish decided to push its images to its own repository until Docker Hub decides to merge our PR.

1. Update what you like
*. Especially check the Dockerfile's base image version, JDK version.
Expand All @@ -76,6 +77,8 @@ Sometimes you need a customized version. OmniFish decided to push it's images to
docker push myrepo/glassfish4myproject:7.0.3.CUST4MYPROJECT
docker logout
```
4. Repeat the steps 2 and 3 for the `latest` tag
5. Update the description of the Docker image in the repository with the contents of the file `target/classes/docs/content.md`

### Deprecation

Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<includes>
<include>Dockerfile</include>
<include>dockerlibfile-fragment.txt</include>
<include>README.md</include>
<include>docs/**</include>
</includes>
<filtering>true</filtering>
</resource>
Expand Down Expand Up @@ -125,9 +125,9 @@
<goals>
<goal>resources</goal>
</goals>
<phase>package</phase>
<phase>process-resources</phase>
<configuration>
<outputDirectory>${basedir}/${glassfish.version}</outputDirectory>
<outputDirectory>${basedir}/${docker.glassfish.tag}</outputDirectory>
</configuration>
</execution>
</executions>
Expand Down Expand Up @@ -161,7 +161,7 @@
</tags>
<cleanup>none</cleanup>
<noCache>false</noCache>
<dockerFile>${basedir}/${glassfish.version}/Dockerfile</dockerFile>
<dockerFile>${basedir}/${docker.glassfish.tag}/Dockerfile</dockerFile>
<filter>@</filter>
</build>
</image>
Expand Down
60 changes: 0 additions & 60 deletions src/main/resources/README.md

This file was deleted.

2 changes: 2 additions & 0 deletions src/main/resources/docs/README-short.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Eclipse GlassFish is a Jakarta EE Full Profile compatible implementation.

149 changes: 149 additions & 0 deletions src/main/resources/docs/content.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# Eclipse GlassFish Docker images (by OmniFish)

[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/OmniFish-EE/docker-library-glassfish

## Quick start

### Start GlassFish

Run GlassFish with the following command:

```
docker run -p 8080:8080 -p 4848:4848 @docker.glassfish.repository@
```

Or with a command for a specific tag (GlassFish version):

```
docker run -p 8080:8080 -p 4848:4848 @docker.glassfish.image@
```

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
```

## 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 @docker.glassfish.repository@
```

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 @docker.glassfish.repository@ 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 @docker.glassfish.repository@ 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 @docker.glassfish.repository@ 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 @docker.glassfish.repository@
```

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 @docker.glassfish.repository@ startserv --debug=true
5a11f2fe1a9dd1569974de913a181847aa22165b5015ab20b271b08a27426e72

docker logs 5a11f2fe1a9dd1569974de913a181847aa22165b5015ab20b271b08a27426e72
...

docker stop 5a11f2fe1a9dd1569974de913a181847aa22165b5015ab20b271b08a27426e72
```

## 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<>("@docker.glassfish.image@").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"));
}

}
```
1 change: 1 addition & 0 deletions src/main/resources/docs/github-repo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/OmniFish-EE/docker-library-glassfish
Loading