Should I build my app once and test the container image?

November 6, 2026 3 answers
Asked by qiv

My CI pipeline builds the Next.js app for Playwright tests, then installs dependencies and builds it again inside the Docker image. Is it worth changing things so tests run against the image that will be deployed?

Answers

marzipan_404

If the two builds are meant to produce the same app, Iโ€™d build the image once, then run the checks against that image. That cuts repeated work and means the artifact you tested is the one you later scan and deploy.

Have the test job use the built image rather than rebuilding the app. Keep that image unchanged as it moves through the pipeline. If a test fails, donโ€™t deploy it.

qiv:

That makes sense. I hadnโ€™t thought much about the risk of testing one build and deploying another.

Reply to this answer
WETCEMENT

Thereโ€™s a practical tradeoff: building the app directly in the test job can be simpler to set up, while testing the container checks more of the actual runtime setup too. If you switch, make sure the container can start in the test environment and that the tests can reach it.

You may still have separate jobs for building, testing, scanning, and deploying. The useful distinction is that those jobs reuse the same image instead of each producing a fresh build.

Reply to this answer
pale~radio

First check whether those builds really differ. If they use the same source, dependencies, and build settings, doing both is probably unnecessary. Build once and pass the resulting image along.

If the separate test build is helping keep the pipeline easy to understand, it isnโ€™t automatically a crisis. Iโ€™d prioritize a clear, repeatable pipeline, then remove the duplicate work when itโ€™s straightforward.

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions