Reuse Docker image from previous action

I have a pipeline that consists roughly of these steps:

  1. [PHP container] Update Composer dependencies
  2. [Node container] Build JS/CSS assets with Laravel Mix
  3. [SFTP] Upload files to server
  4. [PHP container] Send cURL request to API endpoint on server to clear and reset various caches, etc.

This works fine, but it’s a bit of a waste that steps 1 and 4 both end up creating and initialising their own Docker images – once the Docker image in step 1 is set up, there’s no reason it couldn’t be reused to run the single command in step 4 as well. The image from step 1 is cached anyways, not built from scratch every time, so I would think it could just be spun up from cache later on in the pipeline.

Looking at the docs, it looks like it might be possible to do that by building my own Docker image, but that seems like massive overkill just to run composer update and a single cURL command.

Is there a way to reuse an existing, cached image from an earlier action in the pipeline, rather than creating a new one?

Hi, why do you use a PHP container action to send a request instead of the Buddy HTTP request action?

If you want to reuse an existing image, you should have the same image version and the same package commands in both actions. However, it is not strictly necessary, as Buddy caches the image for every action after the first run. So, if you run this pipeline a second time, the action execution will use the cached image.

I did actually use an HTTP request action originally, but for some reason that stopped working – it kept getting 401 errors. The exact same HTTP request works fine from Insomnia/Postman, and it also works fine with the cURL call, so I don’t know exactly what happened with the HTTP action, but I couldn’t get it to work anymore. Surprisingly, the cURL way is also much faster: the HTTP request took about 15 seconds to send the request (plus the time it takes for the server to respond), whereas the cURL action only takes about one to two seconds before the request is sent off.

Are you saying that if I make sure the two PHP containers have the same settings and package commands, then Buddy will automatically recognise that an identical image has already been created and then reuse that for both actions, rather than creating and spinning up two separate images?

I had assumed that this would not be the case, so for the cURL action, I removed most of the package commands since there’s no need for Composer or extra PHP libraries to run a cURL request. That of course also means that Buddy couldn’t reuse the image, since it was different, but if I understand you correctly, I should be able to scratch that action and re-add it with a container that’s completely identical to the one from step 1, and then Buddy should reuse the same image in both actions?

The same two images will be used for subsequent runs, yes, but that’s a different thing – the same image in multiple runs, rather than multiple images in the same run.