Running and verifying the solution

The next build step in Jenkins will deploy the solution locally, running in Docker containers, and verify that the build is working correctly. This step is another PowerShell script, which starts by deploying the application with docker container run commands:

docker container run -d `
--label ci `
--name nerd-dinner-db `
dockeronwindows/ch10-nerd-dinner-db:2e;

docker container run -d `
--label ci `
-l "traefik.frontend.rule=Host:nerd-dinner-test;PathPrefix:/" `
-l "traefik.frontend.priority=1" `
-e "HomePage:Enabled=false" `
-e "DinnerApi:Enabled=false" `
dockeronwindows/ch10-nerd-dinner-web:2e;

...

One advantage of using the Docker CLI over Compose in the build is that I can create containers in a specific order, which gives more time for slow-starting applications such as the NerdDinner website to be ready before testing them. I'm also adding a label, ci, to all the containers, which I can use later to clean up all the test containers, without removing any other containers.

After this step is completed, all the containers should be running. Before I run the end-to-end test suite, which could be a lengthy operation, I have another PowerShell step in the build that runs a simple verification test to make sure that the application responds:

Invoke-WebRequest -UseBasicParsing http://nerd-dinner-test
Remember that these commands are running inside the Jenkins container, which means it can access other containers by name. I don't need to publish specific ports or inspect containers to get their IP addresses. The script starts the Traefik container with the name nerd-dinner-test, and all the frontend containers use that same hostname in their Traefik rules. The Jenkins job can access that URL and the app will respond if the build has been successful.

At this point, the application has been built from the latest source code, and it's all up and running in containers. I've verified that the home page is accessible, which proves that the site is working. The build steps are all console commands, so the output will be written to the job log in Jenkins. For every build, you will see all the output, including the following:

  • Docker executing the Dockerfile commands
  • NuGet and MSBuild steps compiling the application
  • Docker starting application containers
  • PowerShell making the web request to the application

The Invoke-WebRequest cmdlet is a simple build verification test. It gives an error if the build or deployment has failed, but, if it succeeds, that still does not mean the application is working correctly. For greater confidence in the build, I run end-to-end integration tests in the next build step.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.254.90