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

add autoDomain and autoDomainWaitFor option to config #356

Conversation

bryan-hunter
Copy link
Contributor

addressed feedback on #323

Changes proposed in this pull request:

  • Adds autoDomain and autoDomainWaitFor option to customDomain config

This will enable the creation/deletion of a domain name to be run as part of sls deploy and sls remove.

This will be an option to eliminate the need to call sls create_domain prior to sls deploy if you'd like to only run sls deploy across all of your stacks and do not want to run an additional pre-command.

Due to eventual consistency, autoDomainWaitFor option is defaulted to 120 seconds but it should only ever have to wait on the first time it is created.

@bryan-hunter
Copy link
Contributor Author

@jconstance-amplify I've re-raised a PR with autoDomainWaitFor option and added an integration test. Let me know what you think :)

@jconstance-amplify
Copy link
Collaborator

@bryan-hunter Thanks for updating the PR. I'll try to fiddle around with this today.

src/index.ts Outdated
this.serverless.cli.log(`Waiting ${waitFor} seconds before starting deployment
because first time creating domain`);

await sleep(waitFor);
Copy link
Collaborator

Choose a reason for hiding this comment

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

One thing I don't like here is waiting for the entire period. What do you think about polling every few seconds until the time elapses? Or is there a throttling concern for this API that I'm forgetting about?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agreed - this should only happen for the first deployment, but I did almost implement that before raising the PR, but wanted to get feedback first in case it could be avoided.

that being said, I'll add this now :) thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jconstance-amplify I added a polling interval of 3 seconds (didn't seem worth making configurable). Let me know what you think :)

@sonarcloud
Copy link

sonarcloud bot commented Jun 19, 2020

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 1 Security Hotspot to review)
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

const atLeastOneDoesNotExist = () => this.domains.some((domain) => !domain.domainInfo);
const maxWaitFor = parseInt(this.serverless.service.custom.customDomain.autoDomainWaitFor, 10) || 120;
const pollInterval = 3;
for (let i = 0; i * pollInterval < maxWaitFor && atLeastOneDoesNotExist() === true; i++) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

How do we exit this for loop?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if all domains exist , then atLeastOneDoesNotExist() will be false and exit (await this.getDomainInfo(); in the for loop will repopulate data so it can go from true/false)

otherwise, if it never populates, the i * pollInterval will eventually be greater than maxWaitFor and it'll exit and the deployment will eventually fail in the same way as if you never ran create_domain

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jconstance-amplify let me know what you think :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn 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.

@jconstance-amplify no vacations allowed!!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Fortunately for you I came back on Monday! :D

@gongjoonamu
Copy link

I ran into this issue today! This would be a great addition because although it's clearly highlighted here in the documentation I made the assumption that the deploy would also run the create_domain step.
image

Copy link
Collaborator

@jconstance-amplify jconstance-amplify left a comment

Choose a reason for hiding this comment

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

Apologies for the long wait @bryan-hunter. I was able to get some time to look at this yesterday evening, and seems to work okay for me.

I'll go ahead and merge this now. Thanks!

@jconstance-amplify jconstance-amplify merged commit a05d5e4 into amplify-education:master Jul 14, 2020
@bryan-hunter
Copy link
Contributor Author

Thank you so much!

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.

None yet

3 participants