Skip to content

Commit

Permalink
Merge pull request #690 from spwoodcock/build/josm-docker-dev
Browse files Browse the repository at this point in the history
Add JOSM API to docker compose dev stack
  • Loading branch information
robsavoye authored Aug 9, 2023
2 parents 077b837 + 5a6af5e commit 0b27735
Show file tree
Hide file tree
Showing 8 changed files with 209 additions and 0 deletions.
54 changes: 54 additions & 0 deletions docker-compose.josm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Copyright (c) 2022, 2023 Humanitarian OpenStreetMap Team
# This file is part of FMTM.
#
# FMTM is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# FMTM is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with FMTM. If not, see <https:#www.gnu.org/licenses/>.
#

version: "3"

networks:
x11:

services:
josm:
image: "ghcr.io/hotosm/fmtm/josm:latest"
build:
context: josm
container_name: josm
environment:
- DISPLAY=josm-novnc:0.0
depends_on:
- josm-novnc
networks:
- fmtm-dev
- x11
ports:
- 8111:80
restart: unless-stopped

josm-novnc:
image: "ghcr.io/hotosm/fmtm/josm-novnc:latest"
build:
context: josm/novnc
container_name: josm_novnc
environment:
- DISPLAY_WIDTH=1280
- DISPLAY_HEIGHT=600
- RUN_XTERM=no
- RUN_FLUXBOX=no
ports:
- "8112:8080"
networks:
- x11
restart: unless-stopped
17 changes: 17 additions & 0 deletions docs/DEV-2.-Backend.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,23 @@ Creating a new release during development may not always be feasible.

> Note: this is useful for debugging features during active development.

## Running JOSM in the dev stack

- Run JOSM with FMTM:

```bash
docker compose \
-f docker-compose.yml \
-f docker-compose.josm.yml \
up -d
```

This adds JOSM to the docker compose stack for local development.
Access the JOSM Remote API: <http://localhost:8111>
Access the JOSM GUI in browser: <http://localhost:8112>

You can now call the JOSM API from FMTM and changes will be reflected in the GUI.

## Conclusion

Running the FMTM project is easy with Docker. You can also run the
Expand Down
78 changes: 78 additions & 0 deletions josm/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Copyright (c) 2022, 2023 Humanitarian OpenStreetMap Team
# This file is part of FMTM.
#
# FMTM is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# FMTM is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with FMTM. If not, see <https:#www.gnu.org/licenses/>.
#

FROM docker.io/debian:bookworm as base
ARG MAINTAINER=admin@hotosm.org
LABEL org.hotosm.fmtm.maintainer="${MAINTAINER}" \
org.hotosm.fmtm.josm-port="8111" \
org.hotosm.fmtm.nginx-port="80"
RUN set -ex \
&& apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install \
-y --no-install-recommends "locales" "ca-certificates" \
&& DEBIAN_FRONTEND=noninteractive apt-get upgrade -y \
&& rm -rf /var/lib/apt/lists/* \
&& update-ca-certificates
# Set locale
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8



FROM base as gpg-key
RUN set -ex \
&& apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install \
-y --no-install-recommends \
"curl" \
"gnupg2" \
&& rm -rf /var/lib/apt/lists/*
RUN curl -sS https://josm.openstreetmap.de/josm-apt.key \
| gpg --dearmor | tee /opt/josm.gpg



FROM base as runtime
COPY --from=gpg-key \
/opt/josm.gpg /etc/apt/trusted.gpg.d/josm.gpg
RUN echo \
"deb [arch=$(dpkg --print-architecture) \
signed-by=/etc/apt/trusted.gpg.d/josm.gpg] \
https://josm.openstreetmap.de/apt alldist universe" \
| tee /etc/apt/sources.list.d/josm.list > /dev/null
RUN set -ex \
&& apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install \
-y --no-install-recommends \
"gosu" \
"josm" \
"nginx" \
&& rm -rf /var/lib/apt/lists/*
COPY container-entrypoint.sh /container-entrypoint.sh
# Add non-root user
RUN useradd --system -r -u 101 -m -c "nginx user" \
-d /home/nginx -s /bin/false nginx \
&& chmod +x /container-entrypoint.sh
COPY --chown=nginx \
preferences.xml /home/nginx/.config/JOSM/preferences.xml
# Replace default nginx config
COPY --chown=nginx \
nginx-josm.conf /etc/nginx/sites-enabled/default
# Run as root, change to nginx user in entrypoint
ENTRYPOINT ["/container-entrypoint.sh"]
6 changes: 6 additions & 0 deletions josm/container-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

# Start JOSM as nginx (unpriv) user
gosu nginx josm &

exec nginx -g "daemon off;"
13 changes: 13 additions & 0 deletions josm/nginx-josm.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
server {
listen 80 default_server;
server_name _;

location / {
proxy_pass http://127.0.0.1:8111;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
6 changes: 6 additions & 0 deletions josm/novnc/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM docker.io/theasp/novnc:latest
COPY index.html /usr/share/novnc/
RUN useradd -r -u 900 -m -c "novnc account" -d /home/appuser -s /bin/false appuser \
&& chown -R appuser:appuser /app
WORKDIR /app
USER appuser
8 changes: 8 additions & 0 deletions josm/novnc/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
<meta http-equiv="refresh" content="0; URL=vnc.html?resize=scale" />
</head>
<body>
<p>If you see this <a href="vnc.html?resize=scale">click here</a>.</p>
</body>
</html>
27 changes: 27 additions & 0 deletions josm/preferences.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<preferences xmlns='http://josm.openstreetmap.de/preferences-1.0' version='18789'>
<tag key='josm.version' value='18789'/>
<tag key='draw.splashscreen' value='false'/>
<tag key='expert' value='true'/>
<tag key='gui.start.animation' value='false'/>
<tag key='cache.capabilities1637351842' value='1691490836'/>
<tag key='cache.motd.html' value='1691490835'/>
<tag key='cache.motd.html.java' value='11.0.18'/>
<tag key='cache.motd.html.lang' value='En:'/>
<tag key='cache.motd.html.version' value='18789'/>
<tag key='draw.rawgps.colormode' value='0'/>
<tag key='draw.rawgps.lines' value='2'/>
<tag key='mappaint.renderer-class-name' value='org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer'/>
<tag key='oauth.use-for-all-requests' value='false'/>
<tag key='org.openstreetmap.josm.gui.preferences.PreferenceDialog.geometry' value='x=1610,y=585,width=800,height=774'/>
<tag key='preferences.reset.draw.rawgps.lines' value='true'/>
<list key='projection.sub.core:mercator'>
</list>
<tag key='propertiesdialog.preview-on-hover' value='false'/>
<tag key='proxy.policy' value='no-proxy'/>
<tag key='remotecontrol.enabled' value='true'/>
<list key='validator.skip'>
</list>
<list key='validator.skipBeforeUpload'>
</list>
</preferences>

0 comments on commit 0b27735

Please sign in to comment.