Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Initial commit
Jim Van Fleet
committed
Jul 12, 2017
0 parents
commit 51b2b91
Showing
11 changed files
with
230 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
FROM postgres:alpine | ||
|
||
ARG maintainer=tier | ||
ARG imagename=siteadmin-postgres | ||
ARG version=9.6 | ||
ARG postgres_db=shibboleth | ||
|
||
ENV POSTGRES_DB=$postgres_db | ||
|
||
MAINTAINER $maintainer | ||
LABEL Vendor="Internet2" | ||
LABEL ImageType="postgres" | ||
LABEL ImageName=$imagename | ||
LABEL ImageOS=alpine | ||
LABEL Version=$version | ||
|
||
COPY container_files/ /docker-entrypoint-initdb.d/ | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
node { | ||
|
||
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/build.sh &> debug' | ||
} catch(error) { | ||
def error_details = readFile('./debug'); | ||
def message = "BUILD ERROR: There was a problem building ${imagename}:${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 building ${imagename}:${tag}. \n\n ${error_details}" | ||
sh "rm -f ./debug" | ||
handleError(message) | ||
} | ||
|
||
stage 'Push' | ||
|
||
docker.withRegistry('https://registry.hub.docker.com/', "dockerhub-$maintainer") { | ||
def baseImg = docker.build("$maintainer/$imagename") | ||
baseImg.push("$tag") | ||
} | ||
|
||
stage 'Notify' | ||
|
||
slackSend color: 'good', message: "$maintainer/$imagename:$tag pushed to DockerHub" | ||
|
||
} | ||
|
||
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]) | ||
sh 'exit 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
|
||
# This file will run a container in the background | ||
source common.bash . | ||
|
||
docker run -d --name=$imagename $maintainer/$imagename |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
# This file will run a container in the background | ||
source common.bash . | ||
|
||
echo "Cleaning up Docker image($maintainer/$imagename)" | ||
docker stop $imagename >> /dev/null | ||
docker rm $imagename |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
maintainer="tier" | ||
imagename="siteadmin-postgres" | ||
version="9.6" | ||
postgres_db="shibboleth" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL | ||
CREATE USER shibboleth; | ||
GRANT ALL ON DATABASE $POSTGRES_DB TO shibboleth; | ||
EOSQL |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
CREATE TABLE version ( | ||
major int NOT NULL, | ||
minor int NOT NULL | ||
); | ||
INSERT INTO version VALUES (1,0); | ||
|
||
CREATE TABLE strings ( | ||
context varchar(255) NOT NULL, | ||
id varchar(255) NOT NULL, | ||
expires timestamp NOT NULL, | ||
version smallint NOT NULL, | ||
value varchar(255) NOT NULL, | ||
PRIMARY KEY (context, id) | ||
); | ||
|
||
CREATE TABLE texts ( | ||
context varchar(255) NOT NULL, | ||
id varchar(255) NOT NULL, | ||
expires timestamp NOT NULL, | ||
version smallint NOT NULL, | ||
value text NOT NULL, | ||
PRIMARY KEY (context, id) | ||
); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env bats | ||
|
||
load ../common | ||
|
||
|
||
@test "Schema shell present" { | ||
docker run -i $maintainer/$imagename find /docker-entrypoint-initdb.d/00-setup.sh | ||
} | ||
|
||
@test "Data load present" { | ||
docker run -i $maintainer/$imagename find /docker-entrypoint-initdb.d/shibboleth_sp.sql | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env bats | ||
|
||
load ../common | ||
|
||
# These tests assume the pipeline will start and stop the container. | ||
|
||
@test "Leaves running process" { | ||
result="$(docker ps | grep $imagename)" | ||
[ "$result" != '' ] | ||
} | ||
|
||
@test "Creates shibboleth database" { | ||
|
||
} |