webiny / webiny-js

Open-source serverless enterprise CMS. Includes a headless CMS, page builder, form builder, and file manager. Easy to customize and expand. Deploys to AWS.
https://www.webiny.com
Other
7.29k stars 601 forks source link

webiny watch is dependent on temporary artifact #4084

Closed LeoDeJaneiro closed 4 months ago

LeoDeJaneiro commented 4 months ago

Version

5.38.2

Operating System

MacOS 13.6.2

Browser

No response

What are the steps to reproduce this bug?

  1. deploy, e.g. yarn webiny deploy --env prod
  2. remove file .webiny/workspaces/apps/api/Pulumi.yaml
  3. run develop command, e.g. yarn webiny watch --package admin --env prod --allowProduction

What is the expected behavior?

The development should work and not be dependent of any file within the .webiny folder.

What do you see instead?

webiny info: Running "hook-before-watch" hook... webiny success: Hook "hook-before-watch" completed. Watching admin package... TypeError: Cannot read properties of null (reading 'region') at modifier (/Users/repo/temp/CMS-webiny/node_modules/@webiny/serverless-cms-aws/createAdminAppConfig.ts:13:52) at reduce (/Users/repo/temp/CMS-webiny/node_modules/@webiny/serverless-cms-aws/createReactAppConfig.ts:140:20) at Array.reduce () at loadEnvVars (/Users/repo/temp/CMS-webiny/node_modules/@webiny/serverless-cms-aws/createReactAppConfig.ts:135:50) at Object.watch (/Users/repo/temp/CMS-webiny/node_modules/@webiny/serverless-cms-aws/createReactAppConfig.ts:173:13) at /Users/repo/temp/CMS-webiny/node_modules/@webiny/cli-plugin-deploy-pulumi/commands/watch/worker.js:47:31 at Object. (/Users/repo/temp/CMS-webiny/node_modules/@webiny/cli-plugin-deploy-pulumi/commands/watch/worker.js:52:3) at Module._compile (node:internal/modules/cjs/loader:1376:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1435:10) at Module.load (node:internal/modules/cjs/loader:1207:32)

Additional information

No response

Possible solution

No response

adrians5j commented 4 months ago

Thanks for submitting the issue.

The reason why this can't work is the following...

Upon starting the (admin) watch command, we first pick up a couple of things from the API application, like deployed API URLs or Amazon Cognito-related IDs. This requires the API app to be deployed at least once.

Not sure how you ended up even in the .webiny folder. Ultimately, the folder should not be touched by users, it's all internal stuff.

I will close this issue for now, but ofc, if you want to keep the discussion going, feel free to do so, and I can reopen if needed.

LeoDeJaneiro commented 4 months ago

Hey @adrians5j, thanks for your answer.

If you say

This requires the API app to be deployed at least once.

do you mean that the API app is required to be deployed by the user who runs the watch command? Does it mean, that on a shared environment (which was already deployed), the necessary steps for a new developer (who has not deployed initially) are:

  1. trigger deployment (which should not have any effect due to the unchanged infrastructure code)
  2. watch (should this work now because the .webiny folder was created locally now?)

FYI: let me describe the original issue and why I investigated this. Multiple developers want to work on a shared environment. I deployed webiny and have this .webiny folder locally. I have commited the repository without this folder. The other devs cloned the repository and are not able to use the watch command. The error for them:

TypeError: Cannot read properties of null (reading 'apiUrl')
    at modifier (/Users/.../CMS-webiny/node_modules/@webiny/serverless-cms-aws/createWebsiteAppConfig.ts:13:54)
    at reduce (/Users/.../CMS-webiny/node_modules/@webiny/serverless-cms-aws/createReactAppConfig.ts:140:20)
    at Array.reduce (<anonymous>)
    at loadEnvVars (/Users/.../CMS-webiny/node_modules/@webiny/serverless-cms-aws/createReactAppConfig.ts:135:50)
    at Object.watch (/Users/.../CMS-webiny/node_modules/@webiny/serverless-cms-aws/createReactAppConfig.ts:173:13)
    at /Users/.../CMS-webiny/node_modules/@webiny/cli-plugin-deploy-pulumi/commands/watch/worker.js:47:31
    at Object.<anonymous> (/Users/.../CMS-webiny/node_modules/@webiny/cli-plugin-deploy-pulumi/commands/watch/worker.js:52:3)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
Cannot read properties of null (reading 'apiUrl')

They have a valid AWS session and admin permissions in the account.

LeoDeJaneiro commented 3 months ago

Hey @adrians5j, this still is an issue for us.

adrians5j commented 3 months ago

Hey @LeoDeJaneiro, sry for delay, totally missed this message.

I see what you mean, you want to have one API being deployed by one team member, and then you want other devs to use it when doing frontend development.

That could work if you're also checking in your .pulumi folder into git.

At first, it crossed my mind that all team members should also have access to the AWS acc into which the API was initially deployed, but on a second thought, I don't think it's required.

But what is required are, in the .env file, the same Pulumi-related env vars:

# See https://www.pulumi.com/docs/intro/concepts/secrets/#changing-the-secrets-provider-for-a-stack.
PULUMI_SECRETS_PROVIDER=passphrase

# Used with "passphrase" secrets provider.
# See https://www.pulumi.com/docs/reference/cli/environment-variables/.
PULUMI_CONFIG_PASSPHRASE=passphrase

Try it and let me know if it works. I think that only with these two env vars correctly assigned in the .env file, when running the watch admin cmd, the required cloud resource IDs should be pulled correctly, and the Admin should be successfully spun up locally.