Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
# 3.10.3

Support AWS functions hotfix

- Move dependencies right.

# 3.10.2

Support AWS functions

- Move dependencies to dev to conform the 50Mib limit

# 3.10.1

Hotfix

- Fix broken local puppeteer

# 3.10.0

Add support to vercel api functions

- Use chrome-aws-lambda as alternative to base puppeteer

# 3.9.1

Maintenance

- Upgrade dependencies to latest versions

# 3.9.0

Read geojson from file or stdin
Expand Down
17 changes: 15 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
FROM node:14.2
FROM node:14.2 AS build

WORKDIR /app

COPY ./ ./

RUN npm install --only=production


FROM node:14.2 as release

RUN \
apt-get update \
Expand All @@ -21,7 +30,11 @@ RUN \
/root/.cargo/bin/cargo install oxipng

WORKDIR /app

COPY --from=build /app ./

EXPOSE 3000
CMD [ "npm", "run", "installandstartdev" ]

CMD [ "npm", "start" ]

HEALTHCHECK CMD curl -f http://localhost:3000/health || exit 1
35 changes: 35 additions & 0 deletions Dockerfile-alpine
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
FROM mhart/alpine-node:15 AS base

RUN apk upgrade --no-cache -U && \
apk add --no-cache -t build-dependencies gcc g++ make zlib musl-dev libpng-dev nasm autoconf nss && \
apk add --no-cache chromium freetype freetype-dev harfbuzz ca-certificates ttf-freefont


FROM base AS build

WORKDIR /app

COPY ./ ./

RUN npm install --only=production && \
npm install puppeteer


FROM base AS release

RUN apk add --no-cache \
--repository=http://dl-cdn.alpinelinux.org/alpine/edge/main \
--repository=http://dl-cdn.alpinelinux.org/alpine/edge/community \
rust cargo curl && \
cargo install oxipng && \
apk del build-dependencies

WORKDIR /app

COPY --from=build /app ./

EXPOSE 3000

CMD [ "npm", "start" ]

HEALTHCHECK CMD curl -f http://localhost:3000/health || exit 1
14 changes: 14 additions & 0 deletions docker-compose-alpine.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: "3.2"

services:

osmsm:
build:
context: .
dockerfile: Dockerfile-alpine
environment:
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: 'true'
PUPPETEER_EXECUTABLE_PATH: '/usr/bin/chromium-browser'
ports:
- 3000:3000
restart: unless-stopped
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@ services:
build: .
ports:
- 3000:3000
volumes:
- .:/app
restart: unless-stopped
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "osm-static-maps",
"version": "3.9.0",
"version": "3.10.3",
"description": "Create a static image of a map with the features you want",
"author": "Julian Perelli",
"contributors": [
Expand All @@ -15,17 +15,18 @@
"url": "http://github.com/jperelli/osm-static-maps.git"
},
"dependencies": {
"commander": "^6.2.0",
"chrome-aws-lambda": "^5.5.0",
"commander": "^6.2.1",
"express": "4.17.1",
"handlebars": "4.7.6",
"imagemin": "7.0.1",
"imagemin-jpegtran": "7.0.0",
"imagemin-optipng": "8.0.0",
"leaflet": "^1.7.1",
"leaflet-polylinedecorator": "1.6.0",
"mapbox-gl": "^1.12.0",
"mapbox-gl-leaflet": "0.0.13",
"puppeteer": "^5.4.1"
"mapbox-gl": "^1.13.0",
"mapbox-gl-leaflet": "0.0.14",
"puppeteer-core": "^5.5.0"
},
"engines": {
"node": ">=12"
Expand All @@ -40,6 +41,7 @@
"osmsm": "./src/cli.js"
},
"devDependencies": {
"nodemon": "2.0.4"
"nodemon": "2.0.6",
"puppeteer": "^5.5.0"
}
}
}
2 changes: 1 addition & 1 deletion src/lib.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,6 @@ interface OsmStaticMapsOptions {
}

/** Renders a map controlled by the options passed and returns an image */
function _default<T extends OsmStaticMapsOptions>(
declare function _default<T extends OsmStaticMapsOptions>(
options?: T
): Promise<T extends { renderToHtml: true } ? string : Buffer>;
35 changes: 31 additions & 4 deletions src/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@ const fs = require('fs');
const http = require('http');
const https = require("https");
const Handlebars = require('handlebars');
const puppeteer = require('puppeteer');
const path = require('path');
const child_process = require("child_process");

let chrome = { args: [] };
let puppeteer;

if (process.env.AWS_LAMBDA_FUNCTION_VERSION) {
// running on the Vercel platform.
chrome = require("chrome-aws-lambda");
puppeteer = require("puppeteer-core");
} else {
// running locally.
puppeteer = require("puppeteer");
}

const files = {
leafletjs: fs.readFileSync(require.resolve('leaflet/dist/leaflet.js'), 'utf8'),
Expand Down Expand Up @@ -35,20 +45,35 @@ class Browser {
}
async launch() {
return puppeteer.launch({
args: ["--no-sandbox", "--disable-setuid-sandbox"]
args: [...chrome.args, "--no-sandbox", "--disable-setuid-sandbox"],
defaultViewport: chrome.defaultViewport,
executablePath: await chrome.executablePath,
headless: true,
ignoreHTTPSErrors: true,
});
}
async getBrowser() {
if (this.openingBrowser) {
throw new Error('osm-static-maps is not ready, please wait a few seconds')
}
if (!this.browser || !this.browser.isConnected()) {
// console.log('NEW BROWSER')
this.browser = await this.launch()
this.openingBrowser = true;
try {
this.browser = await this.launch();
}
catch (e) {
console.log('Error opening browser')
console.log(JSON.stringify(e, undefined, 2))
}
this.openingBrowser = false;
}
return this.browser
}
async getPage() {
const browser = await this.getBrowser()
// console.log("NEW PAGE");
return await browser.newPage()
return browser.newPage()
}
}
const browser = new Browser();
Expand All @@ -73,6 +98,8 @@ function httpGet(url) {
});
}

process.on("warning", (e) => console.warn(e.stack));

module.exports = function(options) {
return new Promise(function(resolve, reject) {
options = options || {};
Expand Down