2

I'm building a Wordpress CI/CD pipeline based on Docker and some custom deployment scripts. The flow is pretty standard:

- Dev machine pushes complete website archive and database dump to external repository
- There is similar Wordpress docker infrastructure (web, db, app) being used on dev machine and on production servers
- When deployment is initiated the production machine downloads code and db to local repository and spins a new Docker out of it

It all works great, but the problem I'm facing is that Wordpress by default includes full URL in edited pages. So if developer is adding an image to a page the database page will have a code

<img src="sampledevmachine.local/image1.jpg">

Now there are two solutions that come to it. Either the deployment script does search and replace on the database dump file or developer machines can have their hosts file adjusted to make Wordpress think its being accessed by production domain.

Both of these solutions sound a little "dirty". So I'm curious how others would approach such a problem and how would you setup an "elegant" CI/CD for Wordpress.

1 Answers1

0

I honestly don't think there are elegant CI/CD approaches for WP. The 'standard' way of changing the URIs in WP is to do a search/replace but using a tool, rather than on the SQL export. This is because lots of data is serialised as PHP arrays/objects and they breaks silently when a string is replaced (if the length of the string is not the same).

What I do to deploy to different environments is to run the wp search-replace tool with the options

  • --all-tables: Just to be sure.
  • --precise: To deal with PHP serialised arrays/objects
  • --skip-columns=guid: skip the guid columns in some tables as some of them use the domain name as part of the GUID.

You might need to run this tool several times as different parts of wordpress store the domain in different ways (sometimes with or without the connection scheme)

It might be worth mentioning, what I've seen too is that the code has a deployment pipeline, but db/content changes are done using a replication plugin that can push content and at the same time update links, such as Duplicator or All-in-One WP Migration. I've never used this, so I can't comment much on it.

Augusto
  • 28,839
  • 5
  • 58
  • 88