Skip to content

Commit

Permalink
Fix and improve the debugging mode
Browse files Browse the repository at this point in the history
Use Docker buildkit for faster build
  • Loading branch information
sbrunner committed Mar 13, 2023
1 parent 53c33fc commit 14b9ef8
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 40 deletions.
22 changes: 13 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM gradle:6.9.3-jdk11 AS builder

RUN apt-get update && \
RUN --mount=type=cache,target=/var/cache,sharing=locked \
--mount=type=cache,target=/root/.cache \
apt-get update && \
apt-get install --yes --no-install-recommends fonts-liberation gettext curl && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
gradle --version

WORKDIR /src
Expand All @@ -15,26 +15,30 @@ COPY docs/build.gradle ./docs/
COPY publish/build.gradle ./publish/
COPY core ./core

RUN gradle :core:processResources :core:classes
RUN --mount=type=cache,target=/home/gradle/.gradle \
gradle :core:processResources :core:classes
COPY checkstyle_* ./
# '&& touch success || true' is a trick to be able to get out some artifacts
RUN gradle :core:checkstyleMain :core:spotbugsMain :core:violations --stacktrace \
&& ( (gradle :core:build :core:explodedWar :core:libSourcesJar :core:libJavadocJar && touch success) || true)
RUN --mount=type=cache,target=/home/gradle/.gradle \
(gradle :core:checkstyleMain :core:spotbugsMain :core:violations --stacktrace > /tmp/logs 2>&1) \
&& ( (gradle :core:build :core:explodedWar :core:libSourcesJar :core:libJavadocJar && touch success) || true)

ARG GIT_HEAD
ENV GIT_HEAD=${GIT_HEAD}

COPY publish ./publish

RUN ([ -e success ] && (gradle :publish:build && touch success-publish)) || true
RUN --mount=type=cache,target=/home/gradle/.gradle \
([ -e success ] && ( (gradle :publish:build >> /tmp/logs 2>&1) && touch success-publish)) || true

COPY examples ./examples
COPY docs ./docs

RUN ([ -e success ] && (gradle :examples:build buildDocs && touch success-examples-docs)) || true
RUN --mount=type=cache,target=/home/gradle/.gradle \
([ -e success ] && ( (gradle :examples:build buildDocs >> /tmp/logs 2>&1) && touch success-examples-docs)) || true

FROM builder AS test-builder

RUN [ -e success ] && [ -e success-publish ] && [ -e success-examples-docs ]
RUN cat /tmp/logs && [ -e success ] && [ -e success-publish ] && [ -e success-examples-docs ]

VOLUME [ "/src/core" ]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GIT_HEAD_ARG = --build-arg=GIT_HEAD=$(shell git rev-parse HEAD)
export DOCKER_BUILDKIT = 0
export DOCKER_BUILDKIT = 1

.PHONY: build
build:
Expand Down
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ Execute the following command():
> make build
```

This will build three artifacts: print-servlet-xxx.war, print-lib.jar, print-standalone.jar
This will build three artifacts: `print-servlet-xxx.war`, `print-lib.jar`, `print-standalone.jar`.

The build also builds the documentation in the docs/build/site folder. To deploy the documentation it should
simply be copied to the gh-pages branch and then committed GitHub will automatically build the updated site
simply be copied to the `gh-pages` branch and then committed GitHub will automatically build the updated site
at: <https://mapfish.github.io/mapfish-print/>

If you only want to build the docs simply run:
Expand All @@ -35,19 +35,22 @@ The test (part of the build) requires the 'Liberation Sans' font, which can be d

</div>

# Auto-reload mode
# Debug mode

To be able to quickly test modifications in the print you should:

- Copy the file `docker-compose.override.sample.yaml` to `docker-compose.override.yaml`.
- Run `docker compose up -d`,
The print will be available on port `8080` and on code modification will be built and trigger a restart.

# Create new stabilisation branch
With that you will have a running print, when you modify the code the print will be rebuilt and restarted,
and the debugging port will be opened on `5005`.

# Create new stabilization branch

- Update `CHANGELOG.md`
- Create a new branch name `x.y` from master.
- Create a new label names `backport x.y` in the right color (GitHub: Issues->Labels->New Label).
- Create a new label names `backport x.y` in the right color (GitHub: Issues -> Labels -> New Label).
- Create a tag `x.y.0`.
- On the master branch: Update the `SECURITY.md` file, add a policy for the new and old version.
- On the master branch update the `.github/workflows/rebuild.yaml` file by adding the new branch name.
Expand Down Expand Up @@ -76,15 +79,15 @@ If you want to run in debug mode you can do the following:

For the examples that use GeoServer you should run it in the composition, then build and start the composition:

```
```bash
make build
cp docker-compose.override.sample.yaml docker-compose.override.yaml
make acceptance-tests-up
```

Run the example:

```
```bash
docker-compose exec builder gradle print -PprintArgs="-config /src/examples/src/test/resources/examples/simple/config.yaml -spec /src/examples/src/test/resources/examples/simple/requestData.json -output /src/examples/output.pdf"
```

Expand All @@ -101,8 +104,8 @@ Import project into Eclipse
# Run in Eclipse

- Create new Java Run Configuration
- Main class is org.mapfish.print.cli.Main
- Program arguments: -config samples/config.yaml -spec samples/spec.json -output \$HOME/print.pdf
- Main class is `org.mapfish.print.cli.Main`
- Program arguments: `-config samples/config.yaml -spec samples/spec.json -output \$HOME/print.pdf`

# Contributor License Agreement

Expand Down
16 changes: 8 additions & 8 deletions core/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ FROM mapfish_print_builder AS builder
FROM tomcat:9.0.62-jdk17-openjdk-slim-bullseye AS runner
LABEL maintainer="Camptocamp <info@camptocamp.com>"

RUN perl -0777 -i -pe 's/(<Valve className="org.apache.catalina.valves.AccessLogValve"[^>]*>)/<Valve className="ch.qos.logback.access.tomcat.LogbackValve" quiet="true"\/>/s' "${CATALINA_HOME}/conf/server.xml" \
RUN --mount=type=cache,target=/var/cache,sharing=locked \
--mount=type=cache,target=/root/.cache \
perl -0777 -i -pe 's/(<Valve className="org.apache.catalina.valves.AccessLogValve"[^>]*>)/<Valve className="ch.qos.logback.access.tomcat.LogbackValve" quiet="true"\/>/s' "${CATALINA_HOME}/conf/server.xml" \
&& echo "tomcat.util.scan.StandardJarScanFilter.jarsToSkip=*" >> "${CATALINA_HOME}/conf/catalina.properties" \
&& echo "org.apache.catalina.startup.TldConfig.jarsToSkip=*" >> "${CATALINA_HOME}/conf/catalina.properties" \
&& echo "tomcat.util.scan.DefaultJarScanner.jarsToSkip=*" >> "${CATALINA_HOME}/conf/catalina.properties" \
Expand All @@ -15,9 +17,7 @@ RUN perl -0777 -i -pe 's/(<Valve className="org.apache.catalina.valves.AccessLog
&& apt-get update \
&& apt-get upgrade --assume-yes \
&& apt-get install --assume-yes --no-install-recommends curl \
fonts-liberation fonts-dejavu fontconfig \
&& apt-get clean \
&& rm --recursive --force /var/lib/apt/lists/*
fonts-liberation fonts-dejavu fontconfig procps psmisc

COPY --from=builder /src/core/build/webapp "${CATALINA_HOME}/webapps/ROOT/"
COPY --from=builder /src/examples/build/classes/java/test/org/mapfish/print/HumanAlphaSerie.class "${CATALINA_HOME}/webapps/ROOT/WEB-INF/classes/org/mapfish/print/"
Expand Down Expand Up @@ -52,14 +52,14 @@ CMD ["/usr/local/tomcat/bin/docker-start-print"]
FROM runner AS tester

COPY jettyRunExtraFiles/mapfish-spring-application-context-override-acceptencetests.xml \
webapps/ROOT/WEB-INF/classes/mapfish-spring-application-context-override.xml
/usr/local/tomcat/webapps/ROOT/WEB-INF/classes/mapfish-spring-application-context-override.xml

FROM runner AS watcher

RUN apt-get update \
RUN --mount=type=cache,target=/var/cache,sharing=locked \
--mount=type=cache,target=/root/.cache \
apt-get update \
&& apt-get install --yes --no-install-recommends python3-pip rsync python3-setuptools \
&& apt-get clean \
&& rm --recursive --force /var/lib/apt/lists/* \
&& python3 -m pip --disable-pip-version-check --no-cache-dir install inotify

FROM runner AS final
13 changes: 8 additions & 5 deletions core/docker/usr/local/tomcat/bin/docker-start-watch
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3

import os
import subprocess
from threading import Lock, Timer

Expand All @@ -20,10 +21,10 @@ def start():
"/usr/local/tomcat/webapps/ROOT/WEB-INF/classes/org/mapfish/print/",
]
)
print("Start Tomcat")
subprocess.check_call(["catalina.sh", "start"])
started = True
timer = None
print("PYTHON: &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 555")


def main():
Expand All @@ -38,17 +39,19 @@ def main():
with lock:

if timer is not None:
print("cancel")
timer.cancel()
timer = None

if started:
subprocess.check_call(["catalina.sh", "stop"])
print("Stop Tomcat")
subprocess.check_call(["catalina.sh", "stop", "5", "-force"])
# Remove the pid file so that the next start will not fail
with open(os.environ["CATALINA_PID"], "w"):
pass
started = False

timer = Timer(1, start)
timer = Timer(10, start)
timer.start()
print("start")


if __name__ == "__main__":
Expand Down
18 changes: 13 additions & 5 deletions core/src/main/java/org/mapfish/print/http/UserAgentCreator.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
package org.mapfish.print.http;

import org.apache.http.util.VersionInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Utility class for the creation of the User-Agent string.
*
* @author bhoefling
*
* @author bhoefling
*/
public final class UserAgentCreator {
private static final Logger LOGGER = LoggerFactory.getLogger(UserAgentCreator.class);

private static final String AGENT_NAME = "MapFishPrint";

/**
* Private constructor.
*/
private UserAgentCreator() {

}
/**
* Builds a User-Agent string.
*
*
* @return User-Agent
*/
public static String getUserAgent() {
Expand All @@ -31,7 +33,13 @@ public static String getUserAgent() {
// This is based on the code from HttpClient:
final VersionInfo mapFishPrintVersionInfo = VersionInfo.loadVersionInfo("org.mapfish.print",
UserAgentCreator.class.getClassLoader());
final String mfpRelease = mapFishPrintVersionInfo.getRelease();

String mfpRelease = "0.0.0";
try {
mapFishPrintVersionInfo.getRelease();
} catch (final Exception e) {
LOGGER.error("Error getting MapFishPrint version", e);
}

final String userAgent = String.format("%s/%s %s", AGENT_NAME, mfpRelease, httpClientUserAgent);
return userAgent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
<import resource="mapfish-spring-application-context.xml" />
<bean id="servletContext" class="org.mapfish.print.cli.CliServletContext"/>
<bean id="main" class="org.mapfish.print.cli.Main"/>

</beans>
6 changes: 6 additions & 0 deletions docker-compose.override.sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ services:
- /usr/local/tomcat/bin/docker-start-watch
volumes_from:
- builder
ports:
- 5005:5005
environment:
CATALINA_OUT: /dev/stdout
CATALINA_PID: /usr/local/tomcat/bin/catalina.pid
JAVA_OPTS: -Dsun.net.inetaddr.ttl=30 -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005
3 changes: 1 addition & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ services:
PRINT_YAML_MAX_ALIASES: 200
LOG_LEVEL: DEBUG
JASPER_LOG_LEVEL: DEBUG
CATALINA_OUT: /dev/stdout

tests:
image: mapfish_print_builder
command: sleep infinity
command: tail --follow /dev/null
volumes:
- ./examples/src/test/resources/examples:/src/examples/src/test/resources/examples
environment:
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
enablePublishing=false
group=org.mapfish.print
version=1.0.0
org.gradle.caching=true

0 comments on commit 14b9ef8

Please sign in to comment.