diff --git a/docker-compose.josm.yml b/docker-compose.josm.yml new file mode 100644 index 0000000000..fb59cde604 --- /dev/null +++ b/docker-compose.josm.yml @@ -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 . +# + +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 diff --git a/docs/DEV-2.-Backend.md b/docs/DEV-2.-Backend.md index fe0c9f8709..3ecf82d07f 100644 --- a/docs/DEV-2.-Backend.md +++ b/docs/DEV-2.-Backend.md @@ -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: +Access the JOSM GUI in browser: + +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 diff --git a/josm/Dockerfile b/josm/Dockerfile new file mode 100644 index 0000000000..0b7bb5885b --- /dev/null +++ b/josm/Dockerfile @@ -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 . +# + +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"] diff --git a/josm/container-entrypoint.sh b/josm/container-entrypoint.sh new file mode 100644 index 0000000000..7e1dc919b6 --- /dev/null +++ b/josm/container-entrypoint.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +# Start JOSM as nginx (unpriv) user +gosu nginx josm & + +exec nginx -g "daemon off;" diff --git a/josm/nginx-josm.conf b/josm/nginx-josm.conf new file mode 100644 index 0000000000..c130fdde7f --- /dev/null +++ b/josm/nginx-josm.conf @@ -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; + } +} diff --git a/josm/novnc/Dockerfile b/josm/novnc/Dockerfile new file mode 100644 index 0000000000..a1c362c2b5 --- /dev/null +++ b/josm/novnc/Dockerfile @@ -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 diff --git a/josm/novnc/index.html b/josm/novnc/index.html new file mode 100644 index 0000000000..5927bc740c --- /dev/null +++ b/josm/novnc/index.html @@ -0,0 +1,8 @@ + + + + + +

If you see this click here.

+ + diff --git a/josm/preferences.xml b/josm/preferences.xml new file mode 100644 index 0000000000..374f214a66 --- /dev/null +++ b/josm/preferences.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + +