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

Refactor and simplify PWADevServer host/port handling #339

Merged
merged 21 commits into from
Oct 9, 2018

Conversation

zetlen
Copy link
Contributor

@zetlen zetlen commented Oct 8, 2018

This PR is a:

[ ] New feature
[x] Enhancement/Optimization
[x] Refactor
[ ] Bugfix
[ ] Test for existing code
[ ] Documentation

Summary

When this pull request is merged, it will pull out a lot of our hand-rolled hostname and SSL certificate handling, in favor of davewasmer/devcert which has made great strides and handles most of what we want to handle.

  • Refactored the host generation into a configureHost utility exposed in Buildpack. Unique host generation can now be shared by both dev and staging.
  • Changed the API for secure hosts.
    • Now, there are not separate options for unique unsecure hosts and secure certificates. If you opt in to the provided host, you'll get SSL.
    • Instead of being randomly generated and then stored in a database, the hostnames and ports are derived from a hash of the current directory; no persistence is required.
  • There is no more stateful database. The ~/.config/pwa-buildpack.db is gone for now. No promises on whether it will return.
  • The staging server now uses the same configureHost utility to create a unique url.
  • Removed many utils and tests which were no longer necessary.
  • To share configuration, the webpack.config.js and staging server now obtain their provideSecureHost config from documented environment variables, which have been added to example.env.

Additional information

Some rules of thumb about the default implementation:

  • We recommend simply setting MAGENTO_BUILDPACK_PROVIDE_SECURE_HOST=1 and MAGENTO_BUILDPACK_SECURE_HOST_ADD_UNIQUE_HASH=1. This produces readable domains and unique ports that work for most cases.
  • Generally, a port in the 8000-8999 range indicates a dev server, a port in the 9000-9999 range indicates a staging server, and a port 10000 or above indicates a temporary port because the preferred one is in use.
  • The staging server will not automatically select an in-use port. It is meant to be configured externally, by provisioning scripts.
  • In order to get anything to work, I had to discard the lerna link convert methodology that had caused so many conflicts. Many of the changes are just reorganizing dependency config with no functionality change.

jcalcaben and others added 3 commits October 8, 2018 06:58
- chore: Remove hand-rolled implementations of privilege escalation and replace
with `devcert`.
- refactor: Remove individual options for SSL and unique host, combining them into
one thing.

Fixes #307.

fix: add new refactor to staging server
@zetlen
Copy link
Contributor Author

zetlen commented Oct 8, 2018

The package-lock.json files are back, so this looks like a huge PR, but it isn't one. Lots of homegrown code was removed.

@PWAStudioBot
Copy link
Contributor

Fails
🚫

The following unit tests did not pass 😔. All tests must pass before this PR can be merged

packages/pwa-buildpack/src/Utilities/__tests__/configureHost.spec.js
�[1m�[31m  �[1m● �[1mwarns about sudo prompt if cert needs to be created�[39m�[22m
�[2mexpect(�[22m�[31mjest.fn()�[39m�[2m).toHaveBeenCalledWith(�[22m�[32mexpected�[39m�[2m)�[22m

Expected mock function to have been called with:
  �[32m[StringMatching /requires temporary administrative privileges/]�[39m
But it was �[31mnot called�[39m.

�[2m�[22m
�[2m �[0m �[90m 140 | �[39m simulate�[33m.�[39mcertCreated()�[33m;�[39m�[0m�[22m
�[2m �[0m �[90m 141 | �[39m await configureHost({ subdomain�[33m:�[39m �[32m'best-boss-i-ever-had'�[39m })�[33m;�[39m�[0m�[22m
�[2m �[0m�[31m�[1m>�[2m�[39m�[90m 142 | �[39m expect(console�[33m.�[39mwarn)�[33m.�[39mtoHaveBeenCalledWith(�[0m�[22m
�[2m �[0m �[90m | �[39m �[31m�[1m^�[2m�[39m�[0m�[22m
�[2m �[0m �[90m 143 | �[39m expect�[33m.�[39mstringMatching(�[32m'requires temporary administrative privileges'�[39m)�[0m�[22m
�[2m �[0m �[90m 144 | �[39m )�[33m;�[39m�[0m�[22m
�[2m �[0m �[90m 145 | �[39m})�[33m;�[39m�[0m�[22m
�[2m�[22m
�[2m �[2mat Object.toHaveBeenCalledWith (�[2m�[0m�[36msrc/Utilities/tests/configureHost.spec.js�[39m�[0m�[2m:142:26)�[2m�[22m


Generated by 🚫 dangerJS

@coveralls
Copy link

coveralls commented Oct 8, 2018

Coverage Status

Coverage decreased (-3.5%) to 15.88% when pulling accee8f on zetlen/fix-devserver-porthandling into bcbdd87 on release/2.0.

@zetlen
Copy link
Contributor Author

zetlen commented Oct 8, 2018

@mhhansen If you want to help today, I would be real grateful if you could take a look at this one. This one is an enabler of other people getting work done, as I think it removes a lot of bugs and a lot of code burden from us.

@mhhansen
Copy link
Contributor

mhhansen commented Oct 9, 2018

1. works OK
OK watch:venia, creates, runs and serves without troubles or errors related to SSL.
I was asked for password to store the local domain in hosts file, but just the first time.
which ended up serving OK:

PWADevServer ready at https://magento-venia-concept-cryj2.local.pwadev:8533

2. You first needs to run interactive mode
You can't run watch:all if current domain was not previously added to the hosts file
It will ask for sudo pass to store the domain. so, needs to be interactive, otherwise it complains about that, and suggest to first run the dev environment (watch:venia). Once it's added
This will happen, each time the domain changes (cause it needs to be added into the hosts file)
Makes sense, but this behavior I think should be added to devdocs.

3. (improve) declare a default subdomain to avoid undefined when unique_hash is not present
While having onlysecure_host enabled (without UNIQUE_HASH), it will create an undefined subdomain.

MAGENTO_BUILDPACK_PROVIDE_SECURE_HOST=1

screen shot 2018-10-09 at 8 31 20 am

If you provide the secure_host_subdomain option (and comment out the unique_hash), it creates and make use of the specified subdomain:

MAGENTO_BUILDPACK_PROVIDE_SECURE_HOST=1
MAGENTO_BUILDPACK_SECURE_HOST_SUBDOMAIN="bjork"
#MAGENTO_BUILDPACK_SECURE_HOST_ADD_UNIQUE_HASH=1

screen shot 2018-10-09 at 8 35 35 am

4. add to venia .env file
We've to add and document into the pacakges/venia-concept/example.env new env options:

MAGENTO_BUILDPACK_PROVIDE_SECURE_HOST
MAGENTO_BUILDPACK_SECURE_HOST_ADD_UNIQUE_HASH
MAGENTO_BUILDPACK_SECURE_HOST_SUBDOMAIN
MAGENTO_BUILDPACK_SECURE_HOST_EXACT_DOMAIN

5. vendor.js stills gets called

bjork.local.pwadev/:14 GET https://bjork.local.pwadev:8533/js/vendor.js net::ERR_ABORTED 500 (Internal Server Error)

Couldn't reproduce any of the ERR_SSL_PROTOCOL_ERROR and so..
I'll add/send code review for points 3 and 4, just wanted to deliver the feedback.

I'll run a few more tests with SW enabled to see how it behaves. Cause I ended up with MagentoRouteHandler error, from the checkPropTypes expecting number got string, error. but it only happened with my instance that has venia sample data installed. tried out with a second m2 install that has the default sample data (installed via CLI sampledata:deploy), and I don't get that error.

BTW: tested over Win10, and after tweaking a few scripts from package.json I was able to npm install. the thing is, there's one package that executes unix commands, so you can't run the servers currently. will take a look later this week.

mhhansen
mhhansen previously approved these changes Oct 9, 2018
Copy link
Contributor

@mhhansen mhhansen left a comment

Choose a reason for hiding this comment

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

sent a minor thing related to the default SUBDOMAIN name to avoid undefined in the final url

@zetlen zetlen force-pushed the zetlen/fix-devserver-porthandling branch from 4d3fc5a to b4bdc95 Compare October 9, 2018 22:32
@zetlen zetlen force-pushed the zetlen/fix-devserver-porthandling branch from b4bdc95 to accee8f Compare October 9, 2018 22:59
@zetlen
Copy link
Contributor Author

zetlen commented Oct 9, 2018

That certainly was a fun CI adventure.

@zetlen zetlen merged commit 449c52c into release/2.0 Oct 9, 2018
@zetlen zetlen deleted the zetlen/fix-devserver-porthandling branch October 9, 2018 23:03
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.

5 participants