@basemaps/server 6.27.0 → 6.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,20 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [6.28.0](https://github.com/linz/basemaps/compare/v6.27.0...v6.28.0) (2022-06-06)
7
+
8
+
9
+ ### Features
10
+
11
+ * **docker:** add a container of basemaps-server and basemaps-landing ([#2225](https://github.com/linz/basemaps/issues/2225)) ([13f8144](https://github.com/linz/basemaps/commit/13f814446de0b2896e0ccca620d4b0a017380c14))
12
+ * **server:** bundle basemaps-server cli so its easier to install ([#2218](https://github.com/linz/basemaps/issues/2218)) ([8457b66](https://github.com/linz/basemaps/commit/8457b66be6d0f54decf43b515bb78853cefbc8ed))
13
+ * **server:** provide a better error when loading configuration bundles ([#2222](https://github.com/linz/basemaps/issues/2222)) ([8318192](https://github.com/linz/basemaps/commit/83181920c8a9e061babd38a8ffd0dec93830dced))
14
+ * **sprites:** create sprites using sharp ([#2235](https://github.com/linz/basemaps/issues/2235)) ([e7b6a9e](https://github.com/linz/basemaps/commit/e7b6a9e9c95359dc866b40e7a6988837a71d9d96))
15
+
16
+
17
+
18
+
19
+
6
20
  # [6.27.0](https://github.com/linz/basemaps/compare/v6.26.0...v6.27.0) (2022-05-29)
7
21
 
8
22
 
package/README.md CHANGED
@@ -2,14 +2,42 @@
2
2
 
3
3
  WMTS/XYZ Tile server command line interface.
4
4
 
5
- This wraps the @basemaps/lambda-tiler into a standalone express http server.
5
+ This wraps the @basemaps/tiler into a standalone express http server.
6
6
 
7
7
  ## Usage
8
+ Basemaps server expects a folder tree full of configuration, with multiple tilesets and styles configuration files.
8
9
 
10
+ ```bash
11
+ basemaps-server --config path/to/config/
12
+ ```
13
+
14
+ ### Usage docker
15
+
16
+ The server is also published as a docker container
17
+
18
+ ```bash
19
+ docker run -it \
20
+ --volume $PWD/config:/config \
21
+ --volume $PWD/tiffs:$PWD/tiffs \
22
+ -p 5000:5000 \
23
+ ghcr.io/linz/basemaps-server:v6.28.0 --config /config
9
24
  ```
10
- basemaps-server --config path/to/config
25
+
26
+ Where `${PWD}/config` contains all the configuration and `${PWD}/tiffs` is all the relevant tiff files
27
+
28
+ ### Bundled configuration
29
+
30
+ Basemaps server can also be configured with a single configuration bundle file, which can be created from a configuration folder
31
+
32
+ By bundling the configuration the startup time is greatly reduced as each individual tiff file does not have to be scanned for dimensions, it does mean that new tiffs will not be picked up until a new bundle is created.
33
+
34
+ ```bash
35
+ basemaps-server --config path/to/config/ --bundle config.bundle.json
36
+ basemaps-server --config config.bundle.json
11
37
  ```
12
38
 
39
+
40
+ ### Usage with LINZ imagery
13
41
  Usage with basemaps config, you will need access to basemaps' imagery cache
14
42
 
15
43
  please contact basemaps@linz.govt.nz if you need access.
@@ -20,6 +48,8 @@ basemaps-server --config basemaps-config/config
20
48
  ```
21
49
 
22
50
 
51
+
52
+
23
53
  ### Direct TIFF access
24
54
 
25
55
  If you have a folder of tiffs the basemaps-server can index the folder and create tiles from
@@ -32,7 +62,7 @@ For example given a structure where there are two folders full of tiffs
32
62
  /images/10_geographx_nz_texture_shade_2012_8-0m_01FHRPYJ5FV1XAARZAC4T4K6MC/*.tiff
33
63
  ```
34
64
 
35
- running `basemaps-server --config /images` will create two tile sets one for each folder `gebco_2021...` and `geographx_nz_t...` and then also create a combined layer in the order the tiffs are found.
65
+ running `basemaps-server --config /images --no-config` will create two tile sets one for each folder `gebco_2021...` and `geographx_nz_t...` and then also create a combined layer in the order the tiffs are found.
36
66
 
37
67
 
38
68
  ## Developing
@@ -40,8 +70,10 @@ running `basemaps-server --config /images` will create two tile sets one for eac
40
70
  When running the `@basemaps/server` in development mode, ensure `@basemaps/landing` page has been bundled
41
71
 
42
72
  ```bash
43
- cd packages/landing
44
- yarn bundle
73
+ yarn
74
+ yarn build
75
+
76
+ npx lerna run bundle --stream # Bundle everything
45
77
  ```
46
78
 
47
- This will package all the static assets into `landing/dist` and will be served from `http://localhost:3000`
79
+ This will package all the static assets into `landing/dist` and will be served from `http://localhost:5000`
package/build/cli.d.ts CHANGED
@@ -1,15 +1,13 @@
1
- import { Command, flags } from '@oclif/command';
2
- export declare class BasemapsServerCommand extends Command {
3
- static description: string;
4
- static flags: {
5
- verbose: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
6
- port: import("@oclif/parser/lib/flags").IOptionFlag<number>;
7
- dynamo: flags.IOptionFlag<string | undefined>;
8
- config: flags.IOptionFlag<string | undefined>;
9
- files: flags.IOptionFlag<string | undefined>;
10
- };
1
+ import { LogType } from '@basemaps/shared';
2
+ import { BaseCommandLine } from '@basemaps/shared/build/cli/base.js';
3
+ export declare class BasemapsServerCommand extends BaseCommandLine {
4
+ config: import("@rushstack/ts-command-line").CommandLineStringParameter;
5
+ ignoreConfig: import("@rushstack/ts-command-line").CommandLineFlagParameter;
6
+ bundle: import("@rushstack/ts-command-line").CommandLineStringParameter;
7
+ port: import("@rushstack/ts-command-line").CommandLineIntegerParameter;
8
+ constructor();
11
9
  static args: never[];
12
- loadTiffs(tiffPath: string, serverUrl: string): Promise<void>;
13
- run(): Promise<void>;
10
+ loadTiffs(tiffPath: string, serverUrl: string, logger: LogType): Promise<void>;
11
+ onExecute(): Promise<void>;
14
12
  }
15
13
  //# sourceMappingURL=cli.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAkBhD,qBAAa,qBAAsB,SAAQ,OAAO;IAChD,MAAM,CAAC,WAAW,SAAuD;IACzE,MAAM,CAAC,KAAK;;;;;;MAMV;IAEF,MAAM,CAAC,IAAI,UAAM;IAEX,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA0B7D,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAoC3B"}
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAGA,OAAO,EAAsC,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAW,MAAM,oCAAoC,CAAC;AAoB9E,qBAAa,qBAAsB,SAAQ,eAAe;IACxD,MAAM,kEAIH;IACH,YAAY,gEAGT;IACH,MAAM,kEAIH;IACH,IAAI,mEAKD;;IASH,MAAM,CAAC,IAAI,UAAM;IAEX,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IA0B9E,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;CAkDjC"}
package/build/cli.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import { ConfigJson, ConfigProviderDynamo, ConfigProviderMemory } from '@basemaps/config';
2
2
  import { TileSetLocal } from '@basemaps/lambda-tiler/build/cli/tile.set.local.js';
3
3
  import { TileSets } from '@basemaps/lambda-tiler/build/tile.set.cache.js';
4
- import { Config, Env, fsa, LogConfig } from '@basemaps/shared';
5
- import { Command, flags } from '@oclif/command';
4
+ import { Config, Const, Env, fsa, LogConfig } from '@basemaps/shared';
5
+ import { BaseCommandLine, CliInfo } from '@basemaps/shared/build/cli/base.js';
6
6
  import { basename, dirname } from 'path';
7
7
  import { createServer } from './server.js';
8
- const logger = LogConfig.get();
8
+ CliInfo.package = 'basemaps/server';
9
9
  const BaseProvider = {
10
10
  id: 'pv_linz',
11
11
  version: 1,
@@ -17,8 +17,35 @@ const BaseProvider = {
17
17
  },
18
18
  },
19
19
  };
20
- export class BasemapsServerCommand extends Command {
21
- async loadTiffs(tiffPath, serverUrl) {
20
+ const DefaultPort = 5000;
21
+ export class BasemapsServerCommand extends BaseCommandLine {
22
+ constructor() {
23
+ super({
24
+ toolFilename: 'bms',
25
+ toolDescription: 'Create a WMTS/XYZ Tile server from basemaps config',
26
+ });
27
+ this.config = this.defineStringParameter({
28
+ argumentName: 'CONFIG',
29
+ parameterLongName: '--config',
30
+ description: 'Configuration source to use',
31
+ });
32
+ this.ignoreConfig = this.defineFlagParameter({
33
+ parameterLongName: '--no-config',
34
+ description: 'Assume no config and just load tiffs from the configuration path',
35
+ });
36
+ this.bundle = this.defineStringParameter({
37
+ argumentName: 'BUNDLE',
38
+ parameterLongName: '--bundle',
39
+ description: 'Compile the configuration into a bundle and output path',
40
+ });
41
+ this.port = this.defineIntegerParameter({
42
+ argumentName: 'PORT',
43
+ parameterLongName: '--port',
44
+ description: 'port to use',
45
+ defaultValue: DefaultPort,
46
+ });
47
+ }
48
+ async loadTiffs(tiffPath, serverUrl, logger) {
22
49
  const config = new ConfigProviderMemory();
23
50
  Config.setConfigProvider(config);
24
51
  const tifSets = new Map();
@@ -40,51 +67,56 @@ export class BasemapsServerCommand extends Command {
40
67
  }
41
68
  }
42
69
  }
43
- async run() {
44
- var _a;
45
- const { flags } = this.parse(BasemapsServerCommand);
46
- if (flags.verbose)
47
- logger.level = 'debug';
48
- const ServerUrl = `http://localhost:${flags.port}`;
49
- if (flags.config != null) {
50
- // Load configuration from a collection of JSON files
51
- logger.info({ path: flags.config, mode: 'config' }, 'Starting Server');
52
- if (flags.config.endsWith('.json')) {
53
- const configJson = await fsa.read(flags.config);
54
- const mem = ConfigProviderMemory.fromJson(JSON.parse(configJson.toString()));
55
- Config.setConfigProvider(mem);
56
- }
57
- else {
58
- const cj = await ConfigJson.fromPath(flags.config, logger);
59
- Config.setConfigProvider(cj.mem);
60
- }
70
+ async onExecute() {
71
+ var _a, _b;
72
+ await super.onExecute();
73
+ const logger = LogConfig.get();
74
+ logger.level = 'debug';
75
+ const config = (_a = this.config.value) !== null && _a !== void 0 ? _a : 'dynamodb://' + Const.TileMetadata.TableName;
76
+ const port = this.port.value;
77
+ const ServerUrl = (_b = Env.get(Env.PublicUrlBase)) !== null && _b !== void 0 ? _b : `http://localhost:${port}`;
78
+ // Force a default url base so WMTS requests know their relative url
79
+ process.env[Env.PublicUrlBase] = ServerUrl;
80
+ if (config.startsWith('dynamodb://')) {
81
+ // Load config from dynamodb table
82
+ const table = config.slice('dynamodb://'.length);
83
+ logger.info({ path: config, table, mode: 'dynamo' }, 'Starting Server');
84
+ Config.setConfigProvider(new ConfigProviderDynamo(table));
61
85
  }
62
- else if (flags.dynamo != null) {
63
- // Load configuration from a dynamodb table
64
- logger.info({ dynamo: flags.dynamo, mode: 'dynamo' }, 'Starting Server');
65
- Config.setConfigProvider(new ConfigProviderDynamo(flags.dynamo));
86
+ else if (config.endsWith('.json')) {
87
+ // Bundled config
88
+ logger.info({ path: config, mode: 'config' }, 'Starting Server');
89
+ const configJson = await fsa.read(config);
90
+ const mem = ConfigProviderMemory.fromJson(JSON.parse(configJson.toString()));
91
+ Config.setConfigProvider(mem);
66
92
  }
67
- else if (flags.files != null) {
68
- // Generate configuration form a collection of tiff files
69
- logger.info({ path: flags.files, mode: 'files' }, 'Starting Server');
70
- await this.loadTiffs(flags.files, ServerUrl);
93
+ else if (this.ignoreConfig.value) {
94
+ // Load config directly from tiff files
95
+ logger.info({ path: config, mode: 'tiffs' }, 'Starting Server');
96
+ await this.loadTiffs(config, ServerUrl, logger);
71
97
  }
72
98
  else {
73
- throw new Error('Either a --config, --tiff or --dynamodb must be supplied');
99
+ const mem = await ConfigJson.fromPath(config, logger);
100
+ const bundlePath = this.bundle.value;
101
+ if (bundlePath) {
102
+ await fsa.writeJson(bundlePath, mem.toJson());
103
+ logger.info({ path: bundlePath }, 'ConfigBundled');
104
+ return;
105
+ }
106
+ // Assume the folder is a collection of config files
107
+ logger.info({ path: config, mode: 'config' }, 'Starting Server');
108
+ mem.createVirtualTileSets();
109
+ Config.setConfigProvider(mem);
74
110
  }
75
- // Force a default url base so WMTS requests know their relative url
76
- process.env[Env.PublicUrlBase] = (_a = process.env[Env.PublicUrlBase]) !== null && _a !== void 0 ? _a : `http://localhost:${flags.port}`;
77
- createServer(logger).listen(flags.port, () => {
111
+ if (this.bundle.value != null) {
112
+ throw new Error('--bundle path provided without providing a configuration path');
113
+ }
114
+ createServer(logger).listen(port !== null && port !== void 0 ? port : DefaultPort, '0.0.0.0', () => {
78
115
  logger.info({ url: ServerUrl }, 'ServerStarted');
79
116
  });
80
117
  }
81
118
  }
82
- BasemapsServerCommand.description = 'Create a WMTS/XYZ Tile server for basemaps config';
83
- BasemapsServerCommand.flags = {
84
- verbose: flags.boolean(),
85
- port: flags.integer({ default: 5000 }),
86
- dynamo: flags.string({ description: 'Dynamodb table', required: false }),
87
- config: flags.string({ description: 'Configuration path', required: false }),
88
- files: flags.string({ description: 'Use folders of tiffs as the configuration', required: false }),
89
- };
90
119
  BasemapsServerCommand.args = [];
120
+ new BasemapsServerCommand().executeWithoutErrorHandling().catch((c) => {
121
+ console.error(c);
122
+ });
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAI3C,OAAgB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAcnD,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,GAAG,eAAe,CAyC7D"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAI3C,OAAgB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAuBnD,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,GAAG,eAAe,CAwC7D"}
package/build/server.js CHANGED
@@ -14,10 +14,18 @@ function isAlbResult(r) {
14
14
  return 'statusCode' in r;
15
15
  }
16
16
  const instanceId = ulid.ulid();
17
+ function getLandingLocation() {
18
+ if (typeof require !== 'undefined' && typeof require.resolve === 'function') {
19
+ return require.resolve('@basemaps/landing/dist');
20
+ }
21
+ else {
22
+ const require = createRequire(import.meta.url);
23
+ return require.resolve('@basemaps/landing/dist');
24
+ }
25
+ }
17
26
  export function createServer(logger) {
18
27
  const BasemapsServer = fastify();
19
- const require = createRequire(import.meta.url);
20
- const landingLocation = require.resolve('@basemaps/landing');
28
+ const landingLocation = getLandingLocation();
21
29
  if (landingLocation == null) {
22
30
  logger.warn('Server:Landing:Failed');
23
31
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@basemaps/server",
3
- "version": "6.27.0",
3
+ "version": "6.28.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/linz/basemaps.git",
@@ -19,29 +19,45 @@
19
19
  "main": "./build/index.js",
20
20
  "types": "./build/index.d.ts",
21
21
  "scripts": {
22
- "test": "ospec --globs 'build/**/*.test.js'"
22
+ "test": "ospec --globs 'build/**/*.test.js'",
23
+ "bundle": "../../scripts/bundle.js package.json"
23
24
  },
24
25
  "publishConfig": {
25
26
  "access": "public"
26
27
  },
27
28
  "bin": {
28
- "basemaps-server": "./bin/basemaps-server.js"
29
+ "basemaps-server": "./bin/basemaps-server.cjs"
29
30
  },
31
+ "bundle": [
32
+ {
33
+ "entry": "src/cli.ts",
34
+ "outfile": "bin/basemaps-server.cjs",
35
+ "executable": true,
36
+ "external": [
37
+ "pino-pretty",
38
+ "sharp"
39
+ ]
40
+ }
41
+ ],
30
42
  "files": [
31
43
  "build/",
32
44
  "bin/"
33
45
  ],
46
+ "optionalDependencies": {
47
+ "@basemaps/landing": "^6.28.0"
48
+ },
34
49
  "dependencies": {
35
- "@basemaps/config": "^6.27.0",
50
+ "sharp": "^0.30.2"
51
+ },
52
+ "devDependencies": {
53
+ "@basemaps/config": "^6.28.0",
36
54
  "@basemaps/geo": "^6.26.0",
37
- "@basemaps/lambda-tiler": "^6.27.0",
55
+ "@basemaps/lambda-tiler": "^6.28.0",
38
56
  "@basemaps/landing": "^6.27.0",
39
- "@basemaps/shared": "^6.27.0",
57
+ "@basemaps/shared": "^6.28.0",
40
58
  "@fastify/static": "^5.0.2",
41
- "@linzjs/lambda": "^3.0.1",
42
- "@oclif/command": "^1.8.0",
43
59
  "fastify": "^3.27.4",
44
60
  "pretty-json-log": "^1.0.0"
45
61
  },
46
- "gitHead": "c6aa61c20503cbc7f04cf31927f4e2b95aed34cb"
62
+ "gitHead": "c9e62ec8f9cf5aa1dd79305575fdd1708835e0d9"
47
63
  }
@@ -1,11 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- if (process.env.AWS_REGION == null) process.env.AWS_REGION = process.env.AWS_DEFAULT_REGION;
4
-
5
- import { BasemapsServerCommand } from '../build/cli.js';
6
- import Errors from '@oclif/errors/handle.js';
7
-
8
- BasemapsServerCommand.run(void 0, import.meta.url).catch((error) => {
9
- if (error.oclif) return Errors(error);
10
- console.log(error);
11
- });