Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Adapting for appliance test

  • Loading branch information
Jim Van Fleet
Jim Van Fleet committed Sep 12, 2016
0 parents commit 31852691514d2601adbb0147bb4e43d9df08cf9c
Showing with 178 additions and 0 deletions.
  1. +9 −0 .gitignore
  2. +41 −0 BINSCRIPTS.md
  3. +108 −0 Jenkinsfile
  4. +4 −0 bin/compose.sh
  5. +4 −0 bin/decompose.sh
  6. +7 −0 bin/prune.sh
  7. +3 −0 bin/recompose.sh
  8. +2 −0 common.bash
@@ -0,0 +1,9 @@
bin/build.sh
bin/destroy.sh
bin/install.sh
bin/rebuild.sh
bin/rerun.sh
bin/run.sh
bin/start.sh
bin/stop.sh
bin/test.sh
@@ -0,0 +1,41 @@
# util

This repository is intended to be downloaded into a container repository during development for convenience purposes. Since the major mechanisms of developing to the Docker container construction lifecycle are identical across container images, this repository allows for consistency and additional ease of use across all container images.

## Install

If you are reading this file in BINSCRIPTS.md, your container project is likely to be util-enabled.

To use these scripts yourself, issue this command:

```
curl "https://github.internet2.edu/raw/docker/util/master/bin/install.sh?token=AAAAE4VRBLPB8VExPHSR5nCe791IAYqaks5Xzug5wA%3D%3D" | bash
```

### common.bash

The installation process will create a common.bash file. This file should be the central, canonical authority for management of environment variables. While a subprocess may override them, the files in common.bash should be treated as authoritative defaults. Processes (e.g. `docker build`, `bats`, inside `Jenkinsfile`) can read this file and process the results therein.

You should edit this file to change the image name, and add any other helpful environment variables.

### Jenkinsfile

This will also install a Jenkinsfile to your repository, if it doesn't have one. This will ensure that your Jenkins pipeline can leverage these scripts in the way intended. Ensuring the commands that you issue on your laptop match the commands issued by the build pipeline is critical to ensure predictable, reliable results.

## Use


### Building

#### build.sh
`bin/build.sh `
#### destroy.sh
#### rebuild.sh

### Running
### rerun.sh
### run.sh


### Testing
#### test.sh
@@ -0,0 +1,108 @@
node('docker') {

stage 'Checkout'

checkout scm

stage 'Acquire util'

sh 'mkdir -p tmp && mkdir -p bin'
dir('tmp'){
git([ url: "https://github.internet2.edu/docker/util.git",
credentialsId: "jenkins-github-access-token" ])
sh 'mv ./bin/* ../bin/.'
}
sh 'rm -rf tmp'

stage 'Setting build context'

def maintainer = maintainer()
def imagename = imagename()
def tag

// Tag images created on master branch with 'latest'
if(env.BRANCH_NAME == "master"){
tag = "latest"
}else{
tag = env.BRANCH_NAME
}

if(!imagename){
echo "You must define an imagename in common.bash"
currentBuild.result = 'FAILURE'
}
if(maintainer){
echo "Building ${imagename}:${tag} for ${maintainer}"
}

stage 'Build'
try{
sh 'bin/rebuild.sh &> debug'
} catch(error) {
def error_details = readFile('./debug');
def message = "BUILD ERROR: There was a problem building COmanage appliance (${tag}). \n\n ${error_details}"
sh "rm -f ./debug"
handleError(message)
}

stage 'Compose'
try{
sh 'bin/compose.sh &> debug'
} catch(error) {
def error_details = readFile('./debug');
def message = "BUILD ERROR: There was a problem composing COmanage appliance (${tag}). \n\n ${error_details}"
sh "rm -f ./debug"
handleError(message)
}

stage 'Tests'

try{
sh 'bin/test.sh &> debug'
} catch(error) {
def error_details = readFile('./debug');
def message = "BUILD ERROR: There was a problem testing COmanage appliance :${tag}. \n\n ${error_details}"
sh "rm -f ./debug"
handleError(message)
}

stage 'Clean Up'

cleanup()

stage 'Notify'

slackSend color: 'good', message: "COmanage-appliance (${tag}) passes test battery"

}

def maintainer() {
def matcher = readFile('common.bash') =~ 'maintainer="(.+)"'
matcher ? matcher[0][1] : 'tier'
}

def imagename() {
def matcher = readFile('common.bash') =~ 'imagename="(.+)"'
matcher ? matcher[0][1] : null
}

def handleError(String message){
echo "${message}"
currentBuild.setResult("FAILED")
slackSend color: 'danger', message: "${message}"
//step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: 'chris.bynum@levvel.io', sendToIndividuals: true])
cleanup()
sh 'exit 1'
}

def cleanup() {
try{
sh 'bin/decompose.sh &> debug'
sh 'bin/prune.sh &> debug'
} catch(error) {
def error_details = readFile('./debug');
def message = "BUILD ERROR: There was a problem cleaning up COmanage appliance :${tag}. \n\n ${error_details}"
sh "rm -f ./debug"
handleError(message)
}
}
@@ -0,0 +1,4 @@
#!/bin/bash

echo "Composing"
docker-compose up -d
@@ -0,0 +1,4 @@
#!/bin/bash

echo "Decomposing"
docker-compose stop
@@ -0,0 +1,7 @@
#!/bin/bash

result=$(docker volume ls -qf dangling=true)

if [ ! -z "$result" ]; then
docker volume rm $result
fi
@@ -0,0 +1,3 @@
#!/bin/bash

source bin/decompose.sh && source bin/destroy.sh && source bin/prune.sh && source bin/build.sh && source bin/compose.sh
@@ -0,0 +1,2 @@
maintainer="my"
imagename="comanage"

0 comments on commit 3185269

Please sign in to comment.
You can’t perform that action at this time.