diff --git a/node-server/full/Dockerfile b/node-server/full/Dockerfile new file mode 100644 index 0000000..4704bb4 --- /dev/null +++ b/node-server/full/Dockerfile @@ -0,0 +1,29 @@ +FROM node:17-bullseye-slim + +# Create user and folders +RUN groupadd --gid 10001 -r openwanderer \ + && useradd --uid 10001 -d /home/openwanderer -m -r -s /bin/false -g openwanderer openwanderer \ + && mkdir -p /opt/openwanderer /data/openwanderer/tmp /data/openwanderer/panos + + +# Add local files to image +WORKDIR /opt/openwanderer + +COPY --chown=openwanderer:openwanderer ./public ./public +COPY --chown=openwanderer:openwanderer ./*.sql ./ +COPY --chown=openwanderer:openwanderer ./*.json ./ +COPY --chown=openwanderer:openwanderer ./*.js ./ +COPY --chown=openwanderer:openwanderer ./*.mjs ./ +COPY --chown=openwanderer:openwanderer ./*.md ./ +COPY --chown=openwanderer:openwanderer ./LICENSE ./ +COPY --chown=openwanderer:openwanderer ./.env ./.env + + +# Build OpenWanderer +RUN npm install +RUN npm run build + + +# Expose service +USER openwanderer +EXPOSE 3000 diff --git a/node-server/full/README.md b/node-server/full/README.md index 450ac0a..78e9e56 100644 --- a/node-server/full/README.md +++ b/node-server/full/README.md @@ -1,4 +1,4 @@ -OpenWanderer example application +OpenWanderer example application ================================ This is an example OpenWanderer web application, making use of the new npm package for the server `openwanderer-server` and the client side NPM package `openwanderer-app`, which provides a full OpenWanderer application widget. @@ -8,23 +8,61 @@ Licensing As of the first commit on October 10, 2020, the code is now licensed under the Lesser GNU General Public License, by agreement between both OpenWanderer repository owners (@mrAceT and @nickw). The exception is third-party code such as `geojson-path-finder` which is licensed separately, details in the relevant directories. This has been done to: -- ensure that any changes to OpenWanderer itself will remain Free and open source (if you change OpenWanderer, you must make the modified code available under a compatible free software license); +- ensure that any changes to OpenWanderer itself will remain Free and open source (if you change OpenWanderer, you must make the modified code available under a compatible free software license); - but also allow proprietary applications to *use* OpenWanderer code. Any further changes to the current OpenTrailView - OTV360; repo [here](https://gitlab.com/nickw1/opentrailview) will remain under the GPL v3. -Building the application - server side + +Building the application using Docker +------------------------------------- + +A Docker image can be built to have a simpler setup. First, you need to have a working PostgreSQL database with [PostGIS](https://postgis.net) extension enabled, this can be done using the following commands: + +```bash +psql -c "CREATE DATABASE ow;" +psql -d ow -c "CREATE EXTENSION postgis"; +psql -d ow -f database.sql +``` + +Then, you have to create a `.env` configuration file containing details about your database settings (more info on [Node server documentation](https://github.com/openwanderer/node-server)). The file can be set as following: + +``` +PANO_DIR=/data/openwanderer/panos +MAX_FILE_SIZE=3 +DB_USER=postgres +DB_DBASE=ow +DB_HOST=172.17.0.1 +TMPDIR=/data/openwanderer/tmp +``` + +Now, everything is ready for building Docker image, run the following command: + +```bash +docker build -t openwanderer/example:latest . +``` + +Once building is done, you can start the OpenWanderer app using this command: + +```bash +docker run --rm -p 3000:3000 --name=openwanderer openwanderer/example:latest npm run start +``` + +Your shiny OpenWanderer app can be accessed in your web browser at http://localhost:3000/ + + +Building the application - server side -------------------------------------- You need [Node.js](https://nodejs.org) and [NPM](https://npmjs.com) installed on your system. You also need to install [PostGIS](https://postgis.net) as well as PostgreSQL. -A good resource for instructions on installing PostGIS is [on the OpenStreetMap wiki](https://wiki.openstreetmap.org/wiki/PostGIS/Installation). Even though these instructions relate to setting up a Mapnik map tile server, they are equally applicable for setting up a database for OpenWanderer. +A good resource for instructions on installing PostGIS is [on the OpenStreetMap wiki](https://wiki.openstreetmap.org/wiki/PostGIS/Installation). Even though these instructions relate to setting up a Mapnik map tile server, they are equally applicable for setting up a database for OpenWanderer. To setup the database please import `database.sql` into your database. There is a `.env-example` file containing settings. You need to copy this to `.env` and modify the settings so that they are appropriate for your system. Please see the [Node server](https://github.com/openwanderer/node-server) repository for details. -To build, use +To build, use ``` npm install npm run build @@ -40,10 +78,10 @@ This example application shows the use of the `openwanderer-app` NPM package, wh - view a given panorama; - upload a set of panoramas and create a sequence from them; - view and navigate a sequence, for those panoramas which belong to a sequence. -- view panorama locations on a map interface; +- view panorama locations on a map interface; - rotate panoramas, both via the map (pan only) and via an interface in panorama mode, if you are logged in (pan, tilt and roll); -You should login with username and password `admin`. Signup does not do anything in the sample app. In a real app you would need to implement the login routes using a database and implement some middleware to prevent access to sensitive functionality unless you are logged in. +You should login with username and password `admin`. Signup does not do anything in the sample app. In a real app you would need to implement the login routes using a database and implement some middleware to prevent access to sensitive functionality unless you are logged in. Note that although the widget is customisable (in terms of icons used for certain operations, for example), it assumes certain defaults, particularly regarding the icons used and the page elements to place the various controls. The `index.html` provides the default controls. The needed default icons are provided in the `images` directory; see the README in there for author information for individual icons. diff --git a/node-server/full/app.mjs b/node-server/full/app.mjs index 50bb8ab..c50c2f3 100644 --- a/node-server/full/app.mjs +++ b/node-server/full/app.mjs @@ -6,7 +6,7 @@ import db from 'openwanderer-server/db/index.mjs'; const pgSession = connectPgSimple(expressSession); -// openwanderer-server exports a standard Express app object +// openwanderer-server exports a standard Express app object owServer.use(express.static('public')); owServer.use(expressSession({ @@ -18,6 +18,7 @@ owServer.use(expressSession({ saveUninitialized: false, rolling: true, unset: 'destroy', + createTableIfMissing: true, cookie: { maxAge: 600000, httpOnly: false @@ -61,5 +62,5 @@ owServer.post('/user/logout', (req, res) => { owServer.post('/user/signup', (req, res) => { res.status(400).json({error: 'Signup functionality not implemented, please login with username admin, password admin'}); }); - + owServer.listen(3000); diff --git a/node-server/full/package.json b/node-server/full/package.json index 3f02b78..7eb3353 100644 --- a/node-server/full/package.json +++ b/node-server/full/package.json @@ -12,6 +12,7 @@ "node-polyfill-webpack-plugin": "^1.1.0" }, "scripts": { - "build": "npx webpack" + "build": "npx webpack", + "start": "node app.mjs" } }