Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(config-cli): Provide a cli for creating temporary server and dump screenshots. #2236

Merged
merged 13 commits into from
Jun 13, 2022

Conversation

Wentao-Kuang
Copy link
Contributor

No description provided.

@Wentao-Kuang Wentao-Kuang requested a review from a team as a code owner June 3, 2022 02:45
Create a temporary server from a config bundle file and dump the screenshots

```bash
./bin/bmc.js screenshot-server - config s3://..../config.json.gz
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should just be a argument to screenshot

eg

./bin/bmc.js screenshot --config s3://.../config.json.gz

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be good to separate to two different cli? I think this will make the cli logic not too complex.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be pretty simiple logic ?

something like

if (this.config.value) 
 const host = await startServer()
 return await screenshot(host);
}

return await screenshot(this.host.value)

they are both doing the same thing, screenshotting some host, so to me they are the same command

const port = 5000;
const ServerUrl = `http://localhost:${port}`;
const BasemapsServer = createServer(logger);
BasemapsServer.listen(port, '0.0.0.0', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is async you should really await for the server to start before starting chrome.

granted chrome startup is going to be way slower than the server but it could create issues if the server startup takes too long

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createServer() is not async function? Do you want me to update to async?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something like this

await new Promise(resolve => BaseampsServer.listen(port, '0.0.0.0', () => resolve()))

Config.setConfigProvider(mem);

// Create a basemaps server.
const port = 5000;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this port should be a high random number, is there a npm package to find a unused port?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using random free port from 10000 to 11000 now.


async getTileSetId(tileSetId: string, tag: string): Promise<string> {
if (tag === 'production') return tileSetId;
async function getTileSetId(tileSetId: string, tag: string): Promise<string> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove these now.

if we are pointing at a bundled config there is not @tag to worry about any more!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pr tag removed. We can just point a lambda function url as host to take screenshot for linz/basemaps-config.

@Wentao-Kuang Wentao-Kuang requested a review from blacha June 12, 2022 23:22
BasemapsServer = createServer(logger);

if (BasemapsServer == null) throw new Error('Failed to Create server with the config File');
BasemapsServer.listen(port, '0.0.0.0', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not waiting for this to finish loading.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I forget this. Just fixed.

Dump the screenshots with config file

```bash
./bin/bmc.js screenshot - config s3://..../config.json.gz
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--config ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good pick.

@Wentao-Kuang Wentao-Kuang requested a review from blacha June 13, 2022 02:11
if (config != null) {
const port = await getPort({ port: portNumbers(10000, 11000) });
host = `http://localhost:${port}`;
const server = createServer(logger);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: why create a new var if we could just use BasemapsServer

another option would be const BasemapsServer = this.startServer(config) which returns null | Server

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why if I pass the BasemapsServer into the await new Promise<void>() if always return type checking errors to say that BasemapsServer could be undefined even I have checked not null before. So I create a new var to pass it after.

Copy link
Member

@blacha blacha Jun 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah if you did this as a function that returned Promise<Server | null> could be optimised out.

blacha
blacha previously approved these changes Jun 13, 2022

// Start server
const server = createServer(logger);
server.listen(port, '0.0.0.0', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this lost its promise again?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I copy from the wrong place. Just fixed.

@Wentao-Kuang Wentao-Kuang requested a review from blacha June 13, 2022 21:14

// Start server
const server = createServer(logger);
await new Promise<void>((resolve) =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return new Promise<FastifyInstance>(r => {
r(server);
});

if (style) return styleIdTagId;
return styleId;
}
async function startServer(host: string, port: number, config: string, logger: LogType): Promise<FastifyInstance> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is host passed in just to log it?

could generate host inside the function or log outside the function


let BasemapsServer: FastifyInstance | undefined = undefined;
if (config != null) {
const port = await getPort({ port: portNumbers(10000, 11000) });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just use any port?

@kodiakhq kodiakhq bot merged commit 0713b05 into master Jun 13, 2022
@kodiakhq kodiakhq bot deleted the feat/screenshot-server branch June 13, 2022 22:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants