Skip to content
This repository has been archived by the owner on Nov 6, 2024. It is now read-only.

Commit

Permalink
修复 ResourceConfig 无法在 Docker 容器里被自动扫描的问题 (#40)
Browse files Browse the repository at this point in the history
* Do not use jetty:jdk17 Docker image

* Add documentation
  • Loading branch information
QubitPi authored Apr 18, 2024
1 parent 8d1152d commit 5a4cb7e
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 9 deletions.
32 changes: 28 additions & 4 deletions athena-examples/athena-example-books/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,37 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
FROM jetty:jdk17
FROM ubuntu:22.04

LABEL maintainer="Jiaqi (Jack) Liu"
LABEL maintainer-email="jack20220723@gmail.com"

ARG ATHENA_VERSION=1.0-SNAPSHOT
ARG WS_VERSION=1.0-SNAPSHOT

ENV JETTY_WEBAPPS_DIR /var/lib/jetty/webapps
ENV JAVA_HOME /usr/lib/jvm/java-17-openjdk-amd64

COPY ./target/athena-example-books-$ATHENA_VERSION.war $JETTY_WEBAPPS_DIR/ROOT.war
ENV JETTY_VERSION 11.0.15
ENV JETTY_BASE /jetty-base
ENV JETTY_HOME /jetty-home-$JETTY_VERSION
ENV JETTY_WEBAPPS_DIR $JETTY_BASE/webapps

RUN apt update
RUN apt upgrade -y
RUN apt install software-properties-common -y
RUN apt install wget

# Install JDK 17 - https://www.rosehosting.com/blog/how-to-install-java-17-lts-on-ubuntu-20-04/
RUN apt update -y
RUN apt install openjdk-17-jdk -y

# Install and configure Jetty (for JDK 17) container
RUN wget https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-home/$JETTY_VERSION/jetty-home-$JETTY_VERSION.tar.gz
RUN tar -xzvf jetty-home-$JETTY_VERSION.tar.gz
RUN rm jetty-home-$JETTY_VERSION.tar.gz
RUN mkdir jetty-base
RUN cd jetty-base && java -jar $JETTY_HOME/start.jar --add-module=annotations,server,http,deploy,servlet,webapp,resources,jsp

COPY ./target/athena-example-books-$WS_VERSION.war $JETTY_WEBAPPS_DIR/ROOT.war

COPY ./Dockerfile-startup.sh /Dockerfile-startup.sh
CMD [ "/Dockerfile-startup.sh" ]
20 changes: 20 additions & 0 deletions athena-examples/athena-example-books/Dockerfile-startup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
set -x
set -e

# Copyright Paion Data
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

cd $JETTY_BASE
java -jar $JETTY_HOME/start.jar
10 changes: 6 additions & 4 deletions athena-examples/athena-example-books/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,16 @@
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${version.maven.war.plugin}</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
athena__example_config_key="example-value"
athena__resource_binder=com.paiondata.athena.example.books.application.BooksBinderFactory
athena__data_source_provider=com.paiondata.athena.example.books.application.BooksBinderFactory$MySQLDataSourceProvider
53 changes: 53 additions & 0 deletions docs/docs/contributing/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,59 @@ mvn clean install -f athena-core
Pull requests and release builds leverage GitHub Action. PR builds simply run the complete build along with code
coverage.

Running Webservice in Standalone Jetty
--------------------------------------

### Download Jetty

For JDK **17**, which is the version JWT runs on, it's been tested that Jetty _11.0.15_ worked. Hence, we will use
["11.0.15" release](https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-home/11.0.15/jetty-home-11.0.15.tar.gz) as
an example:

![Error loading download-jetty.png](img/download-jetty.png)

Put the `tar.gz` file into a location of your choice as the installation path and extract the Jetty binary using

```bash
tar -xzvf jetty-home-11.0.15.tar.gz
```

The extracted directory *jetty-home-11.0.15* is the Jetty distribution. We call this directory **$JETTY_HOME**, which
should not be modified.

### Setting Up Standalone Jetty

Our [WAR file](#building) will be dropped to a directory where Jetty can pick up and run. We call this directory
**$JETTY_BASE**, which is usually different from the _$JETTY_HOME_. The _$JETTY_BASE_ also contains container runtime
configs. In short, the Standalone Jetty container will be setup with

```bash
export JETTY_HOME=/path/to/jetty-home-11.0.15
mkdir -p /path/to/jetty-base
cd /path/to/jetty-base
java -jar $JETTY_HOME/start.jar --add-module=annotations,server,http,deploy,servlet,webapp,resources,jsp
```

where `/path/to/` is the _absolute_ path to the directory containing the `jetty-home-11.0.15` directory

The `--add-module=annotations,server,http,deploy,servlet,webapp,resources,jsp` is how we configure the Jetty
container.

Lastly, drop the [WAR file](#building) into **/path/to/jetty-base/webapps** directory and rename the WAR file to
**ROOT.war**:

```bash
mv /path/to/war-file /path/to/jetty-base/webapps/ROOT.war
```

### Running Webservice

```bash
java -jar $JETTY_HOME/start.jar
```

The webservice will run on port **8080**, and you will see the data you inserted

Release Versions
----------------

Expand Down
Binary file added docs/docs/contributing/img/download-jetty.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>${version.servlet}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.ws.rs</groupId>
Expand Down Expand Up @@ -560,6 +561,9 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${version.maven.war.plugin}</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>

<plugin>
Expand Down

0 comments on commit 5a4cb7e

Please sign in to comment.