This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ docker rm cje |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ docker stop cje | |
cje | |
$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stage 'Building nginx Container for Docker Hub' | |
docker.withRegistry("${registry_url}", "${docker_creds_id}") { | |
// Set up the container to build | |
maintainer_name = "jayjohnson" | |
container_name = "django-nginx" | |
stage "Building Container" | |
echo "Building nginx with docker.build(${maintainer_name}/${container_name}:${build_tag})" | |
container = docker.build("${maintainer_name}/${container_name}:${build_tag}", 'nginx') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stage "Pushing" | |
container.push() | |
currentBuild.result = 'SUCCESS' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
} catch (Exception err) { | |
err_msg = "Test had Exception(${err})" | |
currentBuild.result = 'FAILURE' | |
error "FAILED - Stopping build for Error(${err_msg})" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Now validate the results match the expected results | |
stage "Test(${test_num}) - Validate Results" | |
test_results = readFile '/tmp/test_results' | |
echo "Test(${test_num}) Results($test_results) == Expected(${expected_results})" | |
sh "if [ \"${test_results}\" != \"${expected_results}\" ]; then echo \" --------------------- Test(${test_num}) Failed--------------------\"; echo \" - Test(${test_num}) Failed\"; echo \" - Test(${test_num}) Failed\";exit 1; else echo \" - Test(${test_num}) Passed\"; exit 0; fi" | |
echo "Done Running Test(${test_num})" | |
// cleanup after the test run | |
sh "rm -f /tmp/test_results" | |
currentBuild.result = 'SUCCESS' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
else | |
{ | |
err_msg = "Missing Test(${test_num})" | |
echo "ERROR: ${err_msg}" | |
currentBuild.result = 'FAILURE' | |
error "Failed to finish container testing with Message(${err_msg})" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
else if (test_num == 2) | |
{ | |
// Test there's nothing established on the port since nginx is not running: | |
sh "docker exec -t ${container_name} netstat -apn | grep 80 | grep ESTABLISHED | wc -l | tr -d '\n' > /tmp/test_results" | |
expected_results = 0 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
else if (test_num == 1) | |
{ | |
// Test that port 80 is exposed | |
echo "Exposed Docker Ports:" | |
sh "docker inspect --format '{{ (.NetworkSettings.Ports) }}' ${container_name}" | |
sh "docker inspect --format '{{ (.NetworkSettings.Ports) }}' ${container_name} | grep map | grep '80/tcp:' | wc -l | tr -d '\n' > /tmp/test_results" | |
expected_results = 1 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (test_num == 0 ) | |
{ | |
// Test we can download the home page from the running django docker container | |
sh "docker exec -t ${container_name} curl -s http://localhost/home/ | grep Welcome | wc -l | tr -d '\n' > /tmp/test_results" | |
expected_results = 1 | |
} |