Bamboo and Composer deployment pitfall

The hole I fell into

Bamboo makes it easy to just make a big pile of files (during build) and copy them out to the places you’re deploying.

The problem is when you need to delete some of those files. I haven’t seen a good way with the Bamboo tasks available to do those deletions. The copy task is just that, with no options you can set to actually sync.

In my case, I was running Composer during that build stage and then just copying packages from Composer out to my deploy areas. Did I not see this coming? I probably did and had to move on to the next urgent item on the list after I had something working.

So when I finally needed to delete some WordPress plugins I’d loaded with Composer it was a mess. I could use a bash script to delete plugins, but composer.json, composer.lock and other files within the /vendor/ directory would not necessarily all be in sync. It’s also not a smart or sustainable practice when Composer already has all the tools needed to do that maintenance for me.

How I dug myself out of it

Running composer update on my deploy installs did nothing, because composer.json and composer.lock both had no indication that the packages I needed to delete were actually there.

I tried to fake Composer out by copying in an old composer.lock from before the packages were deleted – Git came in handy for this. This didn’t work either – I’m guessing there’s an additional manifest in /vendor/ somewhere but am not sure.

Ultimately, I had to get an old composer.json with all the packages represented, and delete composer.lock.  I then ran composer install so Composer would have everything in place to know what was there. Then updated composer.json with the correct set of packages, ran composer update and that worked beautifully.

Wait, why again did I not let Bamboo and Composer do their own jobs?

Well, the truth is that right now I have no way to run Composer on my WordPress installs during a Bamboo deploy. I can run Composer in the Bamboo environment, and I can run Composer from my local machine with a network drive that points to an install. So I probably went with the Bamboo copy task out of necessity at the time. I’ve got a request working its way through the system now to have a proper environment set up so I can automate the Composer updates with Bamboo.