Skip to content

Wait to delete build folder until finished building #634

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

Closed
zackify opened this issue Sep 12, 2016 · 2 comments
Closed

Wait to delete build folder until finished building #634

zackify opened this issue Sep 12, 2016 · 2 comments

Comments

@zackify
Copy link

zackify commented Sep 12, 2016

If you serve the build folder using nginx, when building the app on a deploy, there's anywhere from a few seconds to a minute or two where nginx will return a 403, because the build is deleted before it is finished. See this conversation for more: https://twitter.com/Vjeux/status/775410547470716929

Basically, my solution is to wait until a build finishes, or is a few miliseconds from finishing when running npm run build

@vjeux
Copy link
Contributor

vjeux commented Sep 12, 2016

The way the build step was envisioned is that you would run npm run build and once it is finished building, then move the folder somewhere that's going to be live. I didn't think about the use case where you direct prod traffic directly from that build folder.

While we are talking about solutions inside of create-react-app which we may or may not want to implement, you can unblock yourself by changing the build script from

react-scripts build

to

react-scripts build && mv prod/ last_prod/ && mv build/ prod/ && rm -rf last_prod

and redirect your nginx traffic to the prod/ folder. You should have no downtime that way while updating. You may have requests of old css files while doing the flip and are running into push safety issues but they should be minimal.

@vjeux
Copy link
Contributor

vjeux commented Sep 12, 2016

@lacker also raised an issue on Twitter: "also a problem if build dies halfway"

I don't think we should support your use case and instead you should implement a publish step that just swaps out folders when the build is done. This should solve your use case.

Please do not hesitate to continue commenting on the issue if you think I overlooked some things or have concrete things we could do inside of create-react-app to better support what you are trying to do.

@vjeux vjeux closed this as completed Sep 12, 2016
@lock lock bot locked and limited conversation to collaborators Jan 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants