I'm building at a Build and Deployment pipeline and looking for clarification on a couple points. In addition, I'm trying to implement Trunk Based Development with short-lived branches.
The process I have thus far:
Local development is done on the
main
branch.Developer, before pushing to remote, rebases on remote
main
branch.Developer pushes to remote short-lived branch:
git push origin main:short_lived_branch
.Developer opens PR to merge
short_lived_branch
intomain
.When PR is submitted it triggers the
PR
pipeline that has the following stages:- Builds the microservice.
- Unit tests the microservice.
- If passing, builds the Docker image with a
test-latest
tag and push to container registry. - Integration testing with other microservices (still need to figure this out).
- Cross-browser testing (still need to figure this out).
If the
PR
pipeline is successful, the PR is approved, commits are squashed,short_lived_branch
is merged tomain
andshort_lived_branch
is deleted.The merge to
main
triggers theDeployment
pipeline, which has the following stages:- Builds the microservice.
- Unit tests the microservice.
- If passing, builds the Docker image with a
release-<version>
tag and push to container registry. - Integration testing with other microservices (still need to figure this out).
- Cross-browser testing (still need to figure this out).
- If passing, deploy the images to Kubernetes cluster.
I still have a ton of research to do on the integration and cross-browser testing, as it isn't quite clear to me how to implement it.
That being said, my questions thus far really have to do with the process overall, unit testing and building the Docker image:
Does this flow make sense or should it be changed in anyway?
Regarding unit testing and building the Docker image, I've read some articles that suggest doing the unit testing during the building of the Docker image in the
Dockerfile
. Basically eliminating the first two stages in myPR
andDeployment
pipelines. Some reasons given:- You are testing the code and not the containerized code which is actually what will be run.
- Even if unit testing passes, the image could be broke and it will be even longer before you find out.
- Building on that, it increases the overall build and deployment time. From my experience, the first two stages in my pipelines for a specific service take about a minute and half. Then building and pushing the image takes another two and half minutes. Overall about four minutes. If the unit tests were incorporated into the Docker build, then it could possibly shave a minute or more off the first three stages in my pipeline.
Would this be a bad practice to eliminate the code build and unit testing stages, and just moving unit testing into the Docker build stage?
Thanks for weighing in on this while I'm sorting it out.