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

Update Serverless deploy #805

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Update Serverless deploy #805

wants to merge 9 commits into from

Conversation

joconor
Copy link

@joconor joconor commented Apr 28, 2023

Update Serverless Framework & serverless-lift plugin versions
Use supported wildcard for api/serverless.yml allowedOrigins
Add extension to web/serverless.yml to address AWS change to new S3 bucket default permissions.

@netlify
Copy link

netlify bot commented Apr 28, 2023

‼️ Deploy request for rwjs-deploy-target-ci rejected.

Name Link
🔨 Latest commit c24b64d

@vercel
Copy link

vercel bot commented Apr 28, 2023

@joconor is attempting to deploy a commit to the RedwoodJS Team on Vercel.

A member of the Team first needs to authorize it.

@thedavidprice
Copy link
Contributor

Deploy Test 1

I used 'https://*' setting for file serverless-aws/api/serverless.yml

I attempted a local deployment, which was successful. I ran into this error on https://d3j2lmbogvczkg.cloudfront.net

Error: Header 'authorization' has invalid value: 'Bearer <!DOCTYPE html><html lang="en">...[page html here]

There were no fetch errors in the Network tab or developer console. More suspicious is that there was NO GraphQL fetch in the Network list. Old content from the cache!

I re-ran from Chrome Incognito, using "empty cache and hard reload". The error I got:

Error: Failed to execute 'fetch' on 'Window': Invalid value

Never seen that before 😬

Deploy Test 2

I used 'https://d3j2lmbogvczkg.cloudfront.net' setting for file serverless-aws/api/serverless.yml

I attempted a local deployment, which was successful. Ran into the same error as above.

This is suspicious to me (from the deploy console):

[STARTED] Deploying web....

Deploying serverless-aws-web to stage production (us-east-1, "aws-serverless-rwjs-deploy-ci" provider)

Change set did not include any changes to be deployed. (18s)
[COMPLETED] Deploying web....

So I did make a change to a component, manually deleted web and api /dist, and tried the deploy again. Same console output. Same results.


I've updated the PR with my local changes. Not sure what to try next. Unfortunately, this isn't the first time I've had to chase my tail when it comes to this deployment... 🐶

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm ok to try this for testing. But to confirm we have CORS working, we'll need to be able to deploy this with the original setting.

@joconor
Copy link
Author

joconor commented May 4, 2023

Hey @thedavidprice give it another try. Note that previously the auth function was missing from api/serverless.yml. And there were no GraphQL fetches because the posts were pre-rendered

@thedavidprice
Copy link
Contributor

@joconor I spent more hours on this today than I care to admit. It's closer, but not 100%. Take a look at my changes here:

And the remaining issues here:

Good news is that it's not CORS. That is resolved. Also, I found I was running into a problem similar to your redwood#5785 only it had to do with conflicts between local deploy env vars and GitHub Actions. I've resolved it now. And I'm suggesting we just stop using .env.production.

I really can't put more time into this in the near term. But I'll do my best to respond if you're able to keep iterating.

@joconor
Copy link
Author

joconor commented May 10, 2023

Hey @thedavidprice I'll definitely keep iterating on this. I'd love to have a stable 'base' while trying to create a new Serverless plugin geared specifically toward the needs of Redwood.

Question though: If you stop using .env.production (where 'production' is replaced by whatever the value is for the --stage option), what will be the mechanism for specifying stage specific variables? The whole stage concept is incredibly valuable. Our team is currently working with 5 separate deploys of our one app.

@thedavidprice
Copy link
Contributor

what will be the mechanism for specifying stage specific variables? The whole stage concept is incredibly valuable. Our team is currently working with 5 separate deploys of our one app.

How are you deploying (local, GitHub Action, etc.)? And are you checking all those separate .env files into the Repo (other than .env.default)?

For the case where 1) deploying locally and 2) you're not sharing .env files (which best practices say you shouldn't be doing), then you'll just each use the .env file. Yes, it's on you to match the values with the deploy target, but this is what you're doing regardless (it might just be in one file instead of multiple). Note: this has nothing to do with setting the stage/context on Serverless, in the serverless.yml, or via the Serverless CLI. Whatever stage you've set via those three contexts, the redwood CLI will always pick up .env

Note: there's a tool (and others like it) for sharing .env called https://www.dotenv.org (repo here https://github.com/dotenv-org/dotenv-vault)

Lastly, after doing a bit more research, it's feeling more clear that in the Node ecosystem, it's not idiomatic to use the pattern .env.[stage]. The senior (aka old 😉) developer in me is very used to this (as are many on our team), which is most likely why it got inserted into the Serverless deploy command. I didn't do that work, but now having re-looked at the code, it should have been obvious then that the one-line added to use .env.[stage] with yarn rw deploy serverless --first-run would never work with the rest of the Redwood CLI, including yarn rw deploy serverless. Apologies that this happened in the first place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants