Gatsby: How to trigger Gatsby builds on local server with when content in Wordpress changes

Created on 29 Sep 2019  路  6Comments  路  Source: gatsbyjs/gatsby

Hey, this question is following the closed issue @ github.com/gatsbyjs/gatsby/issues/2753

The issue I am having is that when I update a post in wordpress CMS i would need to rebuild the whole Gatsby site in order to get the changes displayed in the front-end.

I have setup a docker with gatsby and wordpress but for some reason I would like to keep everything together and not use netlify to host my gatsby site.

What I would like to do is to host the whole app with wordpress, db and gatsby on Digital Ocean.

Is there a way to trigger the gatsby site build on wordpress update button click with this setup?

hopefully someone can help me with this, :)

question or discussion

Most helpful comment

@jimmysafe, what @jonniebigodes mentions, is a good source for inspiration on how to accomplish this. (The entire linked issue, has some good ways to do what you want.)

However I would like to add, that if it runs on the same server anyway. You could simply run something along the lines of <?php exec("gatsby build /path/to/gatsby-site); ?> - get HookPress (or something entirely different) to fire the commands/scripts you want, when you update a post - or something else.

This of course, arguably adds their own security risks - and WordPress needs permissions to even fire the scripts etc. at the other site.

I would look into hooks in WordPress. As I see it, a simple bash script could be fired whenever needed.

Or, you could go and see what plugins are already out there. Like this one: https://github.com/crgeary/wp-jamstack-deployments

All 6 comments

@jimmysafe see what i just mentioned in #2753.

@jimmysafe, what @jonniebigodes mentions, is a good source for inspiration on how to accomplish this. (The entire linked issue, has some good ways to do what you want.)

However I would like to add, that if it runs on the same server anyway. You could simply run something along the lines of <?php exec("gatsby build /path/to/gatsby-site); ?> - get HookPress (or something entirely different) to fire the commands/scripts you want, when you update a post - or something else.

This of course, arguably adds their own security risks - and WordPress needs permissions to even fire the scripts etc. at the other site.

I would look into hooks in WordPress. As I see it, a simple bash script could be fired whenever needed.

Or, you could go and see what plugins are already out there. Like this one: https://github.com/crgeary/wp-jamstack-deployments

@dhhdev @jonniebigodes thanks for the reply. I think this plugin https://github.com/crgeary/wp-jamstack-deployments is specifically made for the netlify webhook (not sure i will look into it). for the time being i will go for the bash script and see how it goes! :)

p.s. I have just checked and ,Hookpress is not anymore available in the plugins for security reasons :(

@jimmysafe, I must admit I didn鈥檛 even check to see if HookPress was still a thing. I haven鈥檛 really touched WordPress in years. And when I worked on an in-house PHP project. We just added what we wanted the hard way, anyway. Hehe.

You could also just add a simple button to the WordPress interface I guess. That goes out and fire a new fresh build. Which I would honestly do myself. Automatically doing it, can be nice. But some times you just want to fiddle around in WordPress without it triggering a built every time. (At least it would be the case for me.)

Just to update this thread for future readers, the WordPress plugin mentioned above (I'm the author), works with any provider that supports Webhooks to trigger deployments, whether it be Netlify, Zeit or a custom solution.

It's also completely optional to automatically deploy when content changes, all configurable in the settings. There is a manual button you can press to trigger deploys as and when you want them.

I'm open to adding some extra ways to deploy if it helps others. Just create an issue on my repo and I'll look into supporting it.

Thank you for opening this!

We're marking this issue as answered and closing it for now but please feel free to comment here if you would like to continue this discussion. We also recommend heading over to our communities if you have questions that are not bug reports or feature requests. We hope we managed to help and thank you for using Gatsby!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kalinchernev picture kalinchernev  路  3Comments

ghost picture ghost  路  3Comments

magicly picture magicly  路  3Comments

3CordGuy picture 3CordGuy  路  3Comments

signalwerk picture signalwerk  路  3Comments