jperelli / osm-static-maps

Openstreetmap static maps is a nodejs lib, CLI and server open source inspired on google static map service
http://osm-static-maps.herokuapp.com/
GNU General Public License v2.0
160 stars 52 forks source link

osm-static-map doesn't work in docker container #36

Closed quentin-bardenet closed 6 months ago

quentin-bardenet commented 1 year ago

I've created a little application that generate an image from geoJson data through API. My problem is, even if everything works well on local I cant' make it work on docker container.

Here is the code

require("dotenv").config();
const osmsm = require("osm-static-maps");
const express = require("express");
const app = express();

const fs = require("fs");

app.use(express.json());

app.post("/generateStaticMap", async (req, res) => {
  const { geojson } = req.body;

  const imageBinaryBuffer = await osmsm({ geojson });

  res.send(imageBinaryBuffer.toString("base64"));
});

app.listen(process.env.APP_PORT, () => {
  console.log(`Server is running on port ${process.env.APP_PORT}.`);
});

Here is the docker file

FROM node AS builder
WORKDIR /app
COPY ./package.json ./
RUN npm install
COPY . .

# Second Stage : Setup command to run your app using lightweight node image
FROM node
WORKDIR /app
COPY --from=builder /app ./
RUN \
    apt-get update \
    && \
    apt-get install -y \
    libx11-xcb1 \
    libxtst6 \
    libnss3 \
    libxss1 \
    libasound2 \
    libatk-bridge2.0-0 \
    libgtk-3-0 \
    fonts-wqy-zenhei \
    && \
    rm -rf /var/lib/apt/lists/*

RUN \
    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \
    && \
    /root/.cargo/bin/cargo install oxipng

CMD ["npm", "run", "start"]

And finally here is the error I get when I try to create an image

{}
/app/node_modules/osm-static-maps/src/lib.js:76
    return browser.newPage()
                   ^

TypeError: Cannot read properties of null (reading 'newPage')
    at Browser.getPage (/app/node_modules/osm-static-maps/src/lib.js:76:20)
    at async /app/node_modules/osm-static-maps/src/lib.js:151:20
jperelli commented 6 months ago

Try latest version that uses latest packages and added package-lock. That might be the issue. Reopen if you still find the problem.