# thoughtframe-runtime — Jetty + baked WAR on top of thoughtframe-os.
# Fast rebuilds: only this layer changes when the WAR changes.
#
# Build (Gradle sets OS_IMAGE):
#   docker build --build-arg OS_IMAGE=thoughtframe-os:dev -t thoughtframe-runtime:dev .
ARG OS_IMAGE=registry.thoughtframe.ai/thoughtframe-os:latest
FROM ${OS_IMAGE}

ENV JETTY_HOME=/opt/jetty
ENV JETTY_BASE=/opt/jetty-base

RUN mkdir -p $JETTY_HOME $JETTY_BASE/webapps/ROOT

# Keep in step with :damsel Jetty deps (ASM must parse JDK 25 classfiles).
RUN curl -L https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-home/12.0.35/jetty-home-12.0.35.tar.gz \
	| tar -xz -C $JETTY_HOME --strip-components=1

RUN java -jar $JETTY_HOME/start.jar \
	    jetty.base=$JETTY_BASE \
	    --create-startd \
	    --add-modules=server,http,ee8-webapp,ee8-deploy,ee8-annotations,ee8-jsp,ee8-websocket-javax

# Compose sets user: USERID:GROUPID (EnterMedia-style). Keep Jetty dirs writable for that uid.
RUN chmod -R a+rwX $JETTY_HOME $JETTY_BASE

# App WAR baked in at build time (Jenkins createWar). Entrypoint bootstraps / overlays from this.
RUN mkdir -p /opt/thoughtframe
COPY ROOT.war /opt/thoughtframe/ROOT.war
RUN chmod a+r /opt/thoughtframe/ROOT.war

COPY entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh

WORKDIR $JETTY_BASE
# No USER lock — runtime uid comes from compose / docker run --user
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
