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

Jetty doesn't recognize Oskari /webapps/ or war #320

Open
2018-lonely-droid opened this issue Dec 17, 2024 · 2 comments
Open

Jetty doesn't recognize Oskari /webapps/ or war #320

2018-lonely-droid opened this issue Dec 17, 2024 · 2 comments

Comments

@2018-lonely-droid
Copy link

2018-lonely-droid commented Dec 17, 2024

Hey... I can't figure out this issue... I am new to java, and I am trying to containerize oskari.
I have all the source code in my local repo. I want all the src to be local, and not pull from github. I changed the package.json accordingly. Here is my dockerfile:

# Use Alpine Linux as the base image
FROM alpine:3.18

# Install OpenJDK 8, Node.js 18, and other necessary tools
RUN apk add --no-cache \
    openjdk8 \
    nodejs~=18 \
    npm \
    curl \
    wget \
    maven

# Set environment variables
ENV JETTY_HOME /usr/local/jetty
ENV JETTY_BASE /var/lib/jetty
ENV POSTGRES_DRIVER_VERSION 42.7.4

# Install Jetty
RUN mkdir -p $JETTY_HOME $JETTY_BASE \
    && curl -SL "https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-distribution/9.4.44.v20210927/jetty-distribution-9.4.44.v20210927.tar.gz" | tar -xzf - --strip-components=1 -C $JETTY_HOME

# Initialize Jetty HOME
RUN java -jar $JETTY_HOME/start.jar --create-startd --add-to-start=server,http,deploy,jsp,jstl,ext,resources,websocket

# Jetty BASE - Add PostgreSQL driver
RUN mkdir -p $JETTY_BASE/lib/ext \
    && wget -O $JETTY_BASE/lib/ext/postgresql-${POSTGRES_DRIVER_VERSION}.jar [https://jdbc.postgresql.org/download/postgresql-${POSTGRES_DRIVER_VERSION}.jar](https://jdbc.postgresql.org/download/postgresql-$%7BPOSTGRES_DRIVER_VERSION%7D.jar)

# Jetty BASE - Copy application files
COPY ./oskari-frontend-src $JETTY_BASE/oskari-frontend-src
COPY ./sample-application $JETTY_BASE/sample-application

# Jetty BASE - Install dependencies for oskari-frontend-src
WORKDIR $JETTY_BASE/oskari-frontend-src
RUN npm install

# Jetty BASE - Build frontend (sample application) with frontend source (oskari-frontend-src)
WORKDIR $JETTY_BASE/sample-application
RUN npm install && npm run build:dev

# Build backend with backend source to create war file
COPY ./sample-server-extension /tmp/sample-server-extension
WORKDIR /tmp/sample-server-extension
RUN mvn clean install

# Jetty BASE - Copy configuration files
RUN mkdir -p $JETTY_BASE/webapps $JETTY_BASE/resources
RUN cp webapp-map/target/oskari-map.war $JETTY_BASE/webapps/oskari-map.war
COPY ./sample-server-extension/oskari-front.xml $JETTY_BASE/webapps/
COPY ./sample-server-extension/oskari-map.xml $JETTY_BASE/webapps/
COPY ./sample-server-extension/oskari-ext.properties $JETTY_BASE/resources/

# Expose port 8080
EXPOSE 8080

# Set the working directory to JETTY_BASE
WORKDIR $JETTY_BASE

# Start Jetty with the specified command and parameters
CMD ["java", "-jar", "/usr/local/jetty/start.jar", "jetty.base=/var/lib/jetty", "jetty.home=/usr/local/jetty", "jetty.http.port=8080"]

From what I understand, I am installing all the dependencies, then building a war file. I place the war file in the root of the webapps directory for jetty, (which I assume is what makes http 8080 reachable with app code), and this is what I get when I run the container on ecs fargate:

java -jar $JETTY_HOME/start.jar --help # for more information
ERROR : Nothing to start, exiting ...
Usage: java -jar $JETTY_HOME/start.jar [options] [properties] [configs]

I was using tomcat before, but the documentation includes the jetty zip. What am I missing here? Why would jetty say that there is nothing to start, if the npm install & war files when in the right directories should start hosting the app on port 8080?

@ZakarFin
Copy link
Member

ZakarFin commented Dec 17, 2024

You can use Tomcat if you are more familiar with it (Just copy the oskari-ext.properties under tomcat-instance/lib and if you name oskari-map.war as ROOT.war under webapps, it runs as the root webapp). In fact we might change our packaging on the next version and replace Jetty with Tomcat.

The line where you get the JDBC driver looks a bit funky with md-link formatting involved somehow?

You probably have it, but just making sure that you have your sample-application/package.json referencing "oskari-frontend" with "../oskari-frontend" because it would fail with npm run build:dev if you don't. However, transpiling the frontend doesn't really affect Jetty not finding anything to run. They function independently so server can start without the frontend, you will just see broken HTML-page without the actual frontend.

Both the oskari-front.xml and oskari-map.xml should provide something to run for the Jetty so I'm not sure what could be the issue. Maybe check that they link to the proper file under $JETTY_BASE/sample-application for the frontend (https://github.com/oskariorg/sample-configs/blob/master/jetty-9/oskari-server/webapps/oskari-front.xml#L13) and oskari-map.war on the webapps (https://github.com/oskariorg/sample-configs/blob/master/jetty-9/oskari-server/webapps/oskari-map.xml#L22).

I have a very brief Docker experiment here https://github.com/zakarfin/oskari-docker/ that apparently still works. I haven't tested it out recently. But maybe you can use it as base and expand step by step. Looks like you are on the right tracks as you basically just set a container for Jetty and shovel in the Oskari-based application to run as a regular Java webapp.

What you might be missing is a database that the webapp connects to. You can try setting this setting to true
db.ignoreMigrationFailures=true:
https://github.com/oskariorg/sample-configs/blob/master/jetty-9/oskari-server/resources/oskari-ext.properties#L17 since the server won't start if there's errors on migrations (such like it can't connect to a db).

@ZakarFin
Copy link
Member

Another link that might help, this is the template for our downloadable zip: https://github.com/oskariorg/sample-configs/tree/master/jetty-9 so you can see what is where and with the same content that you get on our zip-file. Just the code is compiled and shoveled on top of that to make the zip complete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants