Skip to content

Minorchanges #6

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
5 changes: 3 additions & 2 deletions README.md
Expand Up @@ -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
Expand Down Expand Up @@ -38,4 +38,5 @@ This will also install a Jenkinsfile to your repository, if it doesn't have one.


### Testing
#### test.sh
#### test.sh
`bin/test.sh`
2 changes: 1 addition & 1 deletion bin/build.sh
Expand Up @@ -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 .
docker build --rm -t $maintainer/$imagename --build-arg maintainer=$maintainer --build-arg imagename=$imagename --build-arg version=$version .
4 changes: 3 additions & 1 deletion bin/install.sh
Expand Up @@ -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
Expand All @@ -10,4 +12,4 @@ fi
if [ ! -f Jenkinsfile ]; then
mv util/Jenkinsfile.sample Jenkinsfile
fi
rm -rf util
rm -rf util
5 changes: 4 additions & 1 deletion bin/test.sh
@@ -1,3 +1,6 @@
#!/bin/bash

bats tests
for i in $( ls tests/)
do
bats --tap tests/$i
done
66 changes: 66 additions & 0 deletions tests/image-test.bats
@@ -0,0 +1,66 @@
#!/usr/bin/env bats
load ../common

@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 "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 ]
}
@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 ]
}
@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 ]
}