Skip to content

Instantly share code, notes, and snippets.

View jay-johnson's full-sized avatar

Jay jay-johnson

View GitHub Profile
@jay-johnson
jay-johnson / remove cje
Created July 15, 2016 06:15
remove cje
$ docker rm cje
@jay-johnson
jay-johnson / stop cje
Created July 15, 2016 06:15
stop cje
$ docker stop cje
cje
$
@jay-johnson
jay-johnson / nginx Jenkins Pipeline building example
Last active July 19, 2016 14:07
nginx Jenkins Pipeline building example
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')
@jay-johnson
jay-johnson / Django container push
Last active July 19, 2016 14:06
Django container push
stage "Pushing"
container.push()
currentBuild.result = 'SUCCESS'
@jay-johnson
jay-johnson / Stop testing if there was an exception and log the error out for debugging
Last active July 19, 2016 14:06
Stop testing if there was an exception and log the error out for debugging
} catch (Exception err) {
err_msg = "Test had Exception(${err})"
currentBuild.result = 'FAILURE'
error "FAILED - Stopping build for Error(${err_msg})"
}
@jay-johnson
jay-johnson / Determine Test Results - Do the results == expected results?
Last active July 25, 2016 16:15
Determine Test Results - Do the results == expected results?
// 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'
@jay-johnson
jay-johnson / Error out on any unsupported test
Last active July 19, 2016 14:03
Error out on any unsupported test
else
{
err_msg = "Missing Test(${test_num})"
echo "ERROR: ${err_msg}"
currentBuild.result = 'FAILURE'
error "Failed to finish container testing with Message(${err_msg})"
}
@jay-johnson
jay-johnson / Test 2
Last active July 19, 2016 14:02
Test 2
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
}
@jay-johnson
jay-johnson / Test 1
Last active July 19, 2016 14:04
Test 1
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
}
@jay-johnson
jay-johnson / Test 0
Last active July 19, 2016 13:59
Test 0
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
}