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?
Should I build my app once and test the container image?
Answers
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.
Reply to this answer
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
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.
qiv:
That makes sense. I hadnโt thought much about the risk of testing one build and deploying another.