From 42c382b10f516aa67fef5b855f1e98675b75c207 Mon Sep 17 00:00:00 2001 From: villadalmine Date: Thu, 25 Aug 2016 07:44:08 -0300 Subject: [PATCH 01/14] Change curl auth method using access personal token with username --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f5949ba..c73413d 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ If you are reading this file in BINSCRIPTS.md, your container project is likely To use these scripts yourself, issue this command: ``` -curl "https://github.internet2.edu/raw/docker/util/master/bin/install.sh?token=AAAAETsVKUnOEAMM8TvUUZccPYi13wsnks5Xq46jwA%3D%3D" | bash +curl -u user:token "https://github.internet2.edu/raw/docker/util/master/bin/install.sh" | bash ``` ### common.bash @@ -38,4 +38,4 @@ This will also install a Jenkinsfile to your repository, if it doesn't have one. ### Testing -#### test.sh \ No newline at end of file +#### test.sh From fb8d21fdc930b2ca11baf338053d682e0b019da7 Mon Sep 17 00:00:00 2001 From: villadalmine Date: Thu, 25 Aug 2016 07:50:48 -0300 Subject: [PATCH 02/14] Imagename is not necessary in build argument and it is not supported in FROM tag. --- bin/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/build.sh b/bin/build.sh index 190c975..3c801f8 100755 --- a/bin/build.sh +++ b/bin/build.sh @@ -3,4 +3,4 @@ source common.bash . echo "Building new Docker image($maintainer/$imagename)" -docker build --rm -t $maintainer/$imagename --build-arg maintainer=$maintainer --build-arg imagename=$imagename --build-arg version=$version . \ No newline at end of file +docker build --rm -t $maintainer/$imagename --build-arg maintainer=$maintainer --build-arg version=$version . From 08a3eda252d06a947eb483f6b3c3ae17d93e6c73 Mon Sep 17 00:00:00 2001 From: villadalmine Date: Thu, 25 Aug 2016 09:20:56 -0300 Subject: [PATCH 03/14] Added test.sh file. This file execute the bats tests --- bin/test.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/test.sh b/bin/test.sh index 6d4b8be..2fbd340 100755 --- a/bin/test.sh +++ b/bin/test.sh @@ -1,3 +1,6 @@ #!/bin/bash -bats tests \ No newline at end of file +for i in $( ls tests/) +do +bats --tap tests/$i +done From de7fbc43c6fd728a653954d02f0fb9ea62576fbb Mon Sep 17 00:00:00 2001 From: villadalmine Date: Thu, 25 Aug 2016 09:21:39 -0300 Subject: [PATCH 04/14] Added tests in install script --- bin/install.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bin/install.sh b/bin/install.sh index 2db62de..bb825b0 100755 --- a/bin/install.sh +++ b/bin/install.sh @@ -2,6 +2,8 @@ git clone git@github.internet2.edu:docker/util.git find util/bin -name "*.sh" -exec sh -c 'echo "$1" | sed "s/util\///" >> .gitignore' -- {} \; mkdir -p bin +mkdir -p tests +mv util/tests/* tests/. mv util/bin/* bin/. mv util/README.md BINSCRIPTS.md if [ ! -f common.bash ]; then @@ -10,4 +12,4 @@ fi if [ ! -f Jenkinsfile ]; then mv util/Jenkinsfile.sample Jenkinsfile fi -rm -rf util \ No newline at end of file +rm -rf util From 3a92b9ae4701257d7de88f950b7df038c04acf21 Mon Sep 17 00:00:00 2001 From: villadalmine Date: Thu, 25 Aug 2016 09:23:12 -0300 Subject: [PATCH 05/14] Added command to execute test --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c73413d..6f6b785 100644 --- a/README.md +++ b/README.md @@ -39,3 +39,4 @@ This will also install a Jenkinsfile to your repository, if it doesn't have one. ### Testing #### test.sh +`bin/test.sh` From da9f58249b7007dbd12ce1db900cba769b4933d8 Mon Sep 17 00:00:00 2001 From: villadalmine Date: Thu, 25 Aug 2016 09:27:46 -0300 Subject: [PATCH 06/14] Added again imagename --- bin/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/build.sh b/bin/build.sh index 3c801f8..909b400 100755 --- a/bin/build.sh +++ b/bin/build.sh @@ -3,4 +3,4 @@ source common.bash . echo "Building new Docker image($maintainer/$imagename)" -docker build --rm -t $maintainer/$imagename --build-arg maintainer=$maintainer --build-arg version=$version . +docker build --rm -t $maintainer/$imagename --build-arg maintainer=$maintainer --build-arg imagename=$imagename --build-arg version=$version . From 74710ec0d0d2b330a1276e270d461ac3fdfbff3c Mon Sep 17 00:00:00 2001 From: villadalmine Date: Thu, 25 Aug 2016 10:45:54 -0300 Subject: [PATCH 07/14] Added first test --- tests/image-test.bats | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 tests/image-test.bats diff --git a/tests/image-test.bats b/tests/image-test.bats new file mode 100644 index 0000000..8fb9b36 --- /dev/null +++ b/tests/image-test.bats @@ -0,0 +1,8 @@ +#!/usr/bin/env bats +load ../common + +@test "Build Docker Image" { + result=$(bin/build.sh |grep -c "Successfully built*") + [ $result = 1 ] + +} From 1d18a20e677646647c44292ab181d559ca210437 Mon Sep 17 00:00:00 2001 From: villadalmine Date: Thu, 25 Aug 2016 10:47:52 -0300 Subject: [PATCH 08/14] Changed = to -eq because output of result is a numeric value --- tests/image-test.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/image-test.bats b/tests/image-test.bats index 8fb9b36..6d44d38 100644 --- a/tests/image-test.bats +++ b/tests/image-test.bats @@ -3,6 +3,6 @@ load ../common @test "Build Docker Image" { result=$(bin/build.sh |grep -c "Successfully built*") - [ $result = 1 ] + [ $result -eq 1 ] } From 5e3d22e6b7690653c8c235acd7177efbbd306d4d Mon Sep 17 00:00:00 2001 From: villadalmine Date: Fri, 26 Aug 2016 09:24:22 -0300 Subject: [PATCH 09/14] Added more logic to first test --- tests/image-test.bats | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/tests/image-test.bats b/tests/image-test.bats index 6d44d38..9f05462 100644 --- a/tests/image-test.bats +++ b/tests/image-test.bats @@ -1,8 +1,35 @@ #!/usr/bin/env bats load ../common -@test "Build Docker Image" { - result=$(bin/build.sh |grep -c "Successfully built*") - [ $result -eq 1 ] +@test "Build Docker Image $imagename/$maintainer" { + run bash -c "ps -eaf |grep -v grep|grep -c docker" + if [ $output -eq 0 ]; then + skip "Docker service is not running" + fi + run bash -c "ls -l Dockerfile" + if [ $status -ne 0 ]; then + skip "Dockerfile is not present" + fi + + run bash -c "grep -c -e imagename -e maintainer -e version common.bash " + if [ $output -ne 3 ]; then + skip "imagename,maintainer and version are not defined" + fi + + run bash -c "grep -c -e version -e imagename -e maintainer Dockerfile" + if [ $output -lt 3 ]; then + skip "imagename,maintainer and version are not defined in Dockerfile" + fi + + run bash -c "docker ps -f names=$imagename |wc -l" + if [ $output -gt 1 ]; then + skip "Docker $imagename/$maintainer was created before" + fi + run bash -c "docker images -q $maintainer/$imagename" + if [ $status -eq 0 ]; then + skip "Docker image $maintainer/$imagename was built before" + fi + run bash -c "bin/build.sh" + [ $status -eq 0 ] } From 71bad8fd6e11d9486470a31f54685c3faa347245 Mon Sep 17 00:00:00 2001 From: villadalmine Date: Fri, 26 Aug 2016 12:35:44 -0300 Subject: [PATCH 10/14] Added test to start container --- tests/image-test.bats | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/image-test.bats b/tests/image-test.bats index 9f05462..9f3c1b5 100644 --- a/tests/image-test.bats +++ b/tests/image-test.bats @@ -33,3 +33,12 @@ load ../common run bash -c "bin/build.sh" [ $status -eq 0 ] } +@test "Starting Docker Image $maintainer7$imagename" { + run bash -c "docker ps -a -f name=$imagename -q|wc -l" + if [ $output -eq 1 ]; then + skip "Can not start $imagename because exist a previous image with same name " + fi + run bash -c "bin/start.sh" + run bash -c "docker ps -f name=$imagename -q|wc -l" + [ $output -eq 1 ] +} From 5bf904df55e5d430e5c54b12478074bd4e219c8f Mon Sep 17 00:00:00 2001 From: villadalmine Date: Fri, 26 Aug 2016 13:37:47 -0300 Subject: [PATCH 11/14] Added test for destroy image --- tests/image-test.bats | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/image-test.bats b/tests/image-test.bats index 9f3c1b5..e500ccc 100644 --- a/tests/image-test.bats +++ b/tests/image-test.bats @@ -42,3 +42,25 @@ load ../common run bash -c "docker ps -f name=$imagename -q|wc -l" [ $output -eq 1 ] } +@test "Stopping Docker Image $maintainer/$imagename" { + run bash -c "docker ps -f name=$imagename -q|wc -l" + if [ $output -eq 0 ]; then + skip "Image $imagename is not running, nothing to stop" + fi + run bash -c "bin/stop.sh" + run bash -c "docker ps -a -f name=$imagename -q|wc -l" + [ $output -eq 1 ] +} +@test "Destroying Image $maintainer/$imagename" { + run bash -c "docker ps -q -a -f name=$imagename -q|wc -l" + if [ $output -eq 0 ]; then + skip "Cannot destroy a non created container" + fi + run bash -c "docker start $imagename" + run bash -c "docker ps -q -f name=$imagename -q|wc -l" + if [ $output -eq 0 ]; then + skip "Cannot destroy a non started container" + fi + run bash -c "bin/destroy.sh" + [ $status -eq 0 ] +} From 87a228d9fa7863f66b82da5b7f1d3cbe58900095 Mon Sep 17 00:00:00 2001 From: villadalmine Date: Fri, 26 Aug 2016 13:57:20 -0300 Subject: [PATCH 12/14] Added rebuild images --- tests/image-test.bats | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/image-test.bats b/tests/image-test.bats index e500ccc..954199d 100644 --- a/tests/image-test.bats +++ b/tests/image-test.bats @@ -64,3 +64,11 @@ load ../common run bash -c "bin/destroy.sh" [ $status -eq 0 ] } +@test "Rebuilding and destroying in one step" { + run bash -c "bin/build.sh" + if [ $status -ne 0 ]; then + skip "Cannot rebuild the image" + fi + run bash -c "bin/rebuild.sh" + [ $status -eq 0 ] +} From ea7f188c84c50c46754e43fc33a42fb5465c65a5 Mon Sep 17 00:00:00 2001 From: villadalmine Date: Fri, 26 Aug 2016 14:12:23 -0300 Subject: [PATCH 13/14] Minor fix in variable --- tests/image-test.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/image-test.bats b/tests/image-test.bats index 954199d..d7b499e 100644 --- a/tests/image-test.bats +++ b/tests/image-test.bats @@ -27,7 +27,7 @@ load ../common skip "Docker $imagename/$maintainer was created before" fi run bash -c "docker images -q $maintainer/$imagename" - if [ $status -eq 0 ]; then + if [ $status -eq 1 ]; then skip "Docker image $maintainer/$imagename was built before" fi run bash -c "bin/build.sh" From 0cf5e9f16695c4431577dc84a07a1811ea62d2df Mon Sep 17 00:00:00 2001 From: villadalmine Date: Fri, 26 Aug 2016 15:07:37 -0300 Subject: [PATCH 14/14] Removed some previous control in build test --- tests/image-test.bats | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tests/image-test.bats b/tests/image-test.bats index d7b499e..a7088cd 100644 --- a/tests/image-test.bats +++ b/tests/image-test.bats @@ -22,14 +22,6 @@ load ../common skip "imagename,maintainer and version are not defined in Dockerfile" fi - run bash -c "docker ps -f names=$imagename |wc -l" - if [ $output -gt 1 ]; then - skip "Docker $imagename/$maintainer was created before" - fi - run bash -c "docker images -q $maintainer/$imagename" - if [ $status -eq 1 ]; then - skip "Docker image $maintainer/$imagename was built before" - fi run bash -c "bin/build.sh" [ $status -eq 0 ] }