GitHub Actions: build outside vs inside container? GitHub Actions: build outside vs inside container? docker docker

GitHub Actions: build outside vs inside container?


Sounds like you covered it well, I'll just pinpoint 📌 a few things.

Using multistage build is great (build inside) and it really depends on your use case. For example, if the build step is not too complicated, like your examples, then going with multistage is enough, plus it has its benefits of having a small image as an artifact.

Moving on to a complicated build - let's say you need to -

  1. Download artifact from GitHub, a release.tar.gz file and unpack it
  2. Build the unpacked file/compile it in some way
  3. Download another artifact from AWS S3
  4. You get the idea ...
  5. Eventually build your application

So here we have multiple steps, that maybe running some of them in parallel, for example, downloading artifacts, can reduce the build time. Moreover, if you split the build to Steps, you can monitor which steps failed, and send notifications accordingly.

To sum it up -

  • Having a long-multistage build in the same Dockerfile is difficult, if you find yourself writing more than 30 rows in a Dockerfile, you might consider splitting to Steps
  • Using Docker's multi-stage build is great if you want to shrink your Docker image artifact. I wouldn't use it as a pipeline
  • Splitting to Steps provides better monitoring, and saves build time due to parallelism

Let me know if you have more thoughts, it's a great topic