From 95e30b6223097252a2d6253f59d5627ee8461d16 Mon Sep 17 00:00:00 2001 From: Jim Van Fleet <jim.van.fleet@levvel.io> Date: Fri, 29 Jul 2016 13:28:31 -0400 Subject: [PATCH 1/3] Adding binscripts --- .gitignore | 7 +++++++ BINSCRIPTS.md | 41 ++++++++++++++++++++++++++++++++++++++ Jenkinsfile | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ common.bash | 2 ++ 4 files changed, 104 insertions(+) create mode 100644 .gitignore create mode 100644 BINSCRIPTS.md create mode 100644 Jenkinsfile create mode 100644 common.bash diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7323a01 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +bin/build.sh +bin/destroy.sh +bin/install.sh +bin/rebuild.sh +bin/rerun.sh +bin/run.sh +bin/test.sh diff --git a/BINSCRIPTS.md b/BINSCRIPTS.md new file mode 100644 index 0000000..8569b7d --- /dev/null +++ b/BINSCRIPTS.md @@ -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=AAAAEddkrL9MeeA6VWcNn_PgV30r4lD1ks5XogeiwA%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 \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..fbb9f16 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,54 @@ +node { + + stage 'Checkout' + + checkout scm + + stage 'Acquire util' + + sh 'mkdir -p bin' + dir('bin'){ + git([ url: "https://github.internet2.edu/docker/util.git", + credentialsId: "jenkins-github-access-token" ]) + sh 'ls' + sh 'mv bin/* .' + } + + stage 'Build' + + def maintainer = maintainer() + def imagename = imagename() + def tag = env.BRANCH_NAME + if(!imagename){ + echo "You must define an imagename in common.bash" + currentBuild.result = 'FAILURE' + } + if(maintainer){ + echo "Building ${maintainer}:${tag} for ${maintainer}" + } + + sh 'bin/build.sh' + + stage 'Tests' + + sh 'bin/test.sh' + + stage 'Push' + + docker.withRegistry('https://registry.hub.docker.com/', "dockerhub-$maintainer") { + def baseImg = docker.build("$maintainer/$imagename") + baseImg.push("$tag") + } + + +} + +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 +} \ No newline at end of file diff --git a/common.bash b/common.bash new file mode 100644 index 0000000..96e0143 --- /dev/null +++ b/common.bash @@ -0,0 +1,2 @@ +maintainer="tier" +imagename="imagename-replaceme-in-common-bash" \ No newline at end of file From 85aca2f096bede59cdae940a14ed657a9009e59b Mon Sep 17 00:00:00 2001 From: Jim Van Fleet <jim.van.fleet@levvel.io> Date: Fri, 29 Jul 2016 13:29:23 -0400 Subject: [PATCH 2/3] Setting name pointers --- common.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common.bash b/common.bash index 96e0143..b10cf40 100644 --- a/common.bash +++ b/common.bash @@ -1,2 +1,2 @@ -maintainer="tier" -imagename="imagename-replaceme-in-common-bash" \ No newline at end of file +maintainer="bigfleet" +imagename="lamp" \ No newline at end of file From 410de79f1f14b9d14743fe86dddbd95301c3c5b5 Mon Sep 17 00:00:00 2001 From: Jim Van Fleet <jim.van.fleet@levvel.io> Date: Fri, 29 Jul 2016 13:42:40 -0400 Subject: [PATCH 3/3] First tests passing --- Dockerfile | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ common.bash | 3 ++- tests/image.bats | 23 ++++++++++++++++++++ 3 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 Dockerfile create mode 100755 tests/image.bats diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4e4ebe8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,55 @@ +FROM bigfleet/centos7base + +# Define args and set a default value +ARG maintainer=tier +ARG imagename=lamp +ARG tagname=20160727-dev +ARG version=1.0 + + +MAINTAINER $maintainer +LABEL Vendor="Internet2" +LABEL ImageType="COmanage" +LABEL ImageName=$imagename +LABEL TagName=$tagname +LABEL ImageOS=centos7 +LABEL Version=$version + +LABEL Build docker build --rm --tag $registry/$maintainer/$imagename:$tagname . + +# Install deps. +RUN yum -y install \ + httpd \ + mysql-devel \ + mysql-libs \ + mod_ssl \ + php \ + php-openssl \ + php-cli \ + php-ldap \ + php-mbstring \ + php-mcrypt \ + php-mysql \ + php-pear-MDB2-Driver-mysqli \ + php-pecl-memcached \ + php-xml \ + && yum clean all + +# +# UTC Timezone & Networking +# +RUN ln -sf /usr/share/zoneinfo/UTC /etc/localtime && \ + echo "NETWORKING=yes" > /etc/sysconfig/network + +# +# Global PHP configuration changes +# +RUN sed -i \ + -e 's~^;date.timezone =$~date.timezone = Europe/Rome~g' \ + -e 's~^;user_ini.filename =$~user_ini.filename =~g' \ + /etc/php.ini + +RUN echo '<?php phpinfo(); ?>' > /var/www/html/index.php + +# Port +EXPOSE 80 443 \ No newline at end of file diff --git a/common.bash b/common.bash index b10cf40..1ca7079 100644 --- a/common.bash +++ b/common.bash @@ -1,2 +1,3 @@ maintainer="bigfleet" -imagename="lamp" \ No newline at end of file +imagename="lamp" +version="1.0" \ No newline at end of file diff --git a/tests/image.bats b/tests/image.bats new file mode 100755 index 0000000..13c4aee --- /dev/null +++ b/tests/image.bats @@ -0,0 +1,23 @@ +#!/usr/bin/env bats + +load ../common + +setup() { + echo $PWD > test.log + ./bin/rebuild.sh +} + +@test "Should be buildable" { + run bin/build.sh + [ "$status" -eq 0 ] +} + +@test "Concludes first-run experience" { + result="$(docker run -i $maintainer/$imagename find /tmp/firsttimerunning)" + [ "$result" != '' ] +} + +@test "Contains php" { + run docker run -i $maintainer/$imagename which php + [ "$status" -eq 0 ] +} \ No newline at end of file