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

Commit

Permalink
Merge pull request #1 from docker/first-run
Browse files Browse the repository at this point in the history
First run
  • Loading branch information
Jim Van Fleet committed Sep 9, 2016
2 parents 287b43c + 47126b7 commit 38fb350
Show file tree
Hide file tree
Showing 22 changed files with 999 additions and 18 deletions.
101 changes: 101 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
FROM bigfleet/shibboleth_sp

# Define args and set a default value
ARG registry=docker.io
ARG maintainer=tier
ARG imagename=comanage
ARG version=1.0.5

MAINTAINER $maintainer
LABEL Vendor="Internet2"
LABEL ImageType="COmanage"
LABEL ImageName=$imagename
LABEL ImageOS=centos7
LABEL Version=$version

LABEL Build docker build --rm --tag $registry/$maintainer/$imagename .

# Install deps
RUN yum -y install --setopt=tsflags=nodocs \
httpd \
mariadb \
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 \
vim && yum -y clean all

#
# 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

ENV VERSION=$version
ENV COMANAGE_URL=https://github.com/Internet2/comanage-registry/archive/$VERSION.tar.gz
ENV COMANAGE_PREFIX=comanage-registry

RUN mkdir -p /tmp/comanage && cd /tmp/comanage && \
wget -q $COMANAGE_URL && \
# Perform verifications [TODO]
# Prepare filesystem
mkdir -p /opt/comanage && \
tar xf $VERSION.tar.gz && \
mv $COMANAGE_PREFIX-$VERSION /opt/comanage/. && \
ln -s /opt/comanage/$VERSION /opt/comanage/current && \
# # Cleanup
rm -rf /tmp/comanage

ENV COMANAGE_HOME /opt/comanage/current

WORKDIR $COMANAGE_HOME

# Add starters and installers
ADD ./container_files /opt

# Add Volumes and Set permissions
RUN mkdir /opt/shared \
&& chmod 777 /opt/shared \
&& chmod 777 /opt/bin/*.sh

# Environment variables
ENV ADMIN_NAME "Scott"
ENV ADMIN_FAMILY "Koranda"
ENV ADMIN_USERNAME "scott.koranda@sphericalcowgroup.com"
ENV COMANAGE_SERVER_FQDN "comanage.testbed.tier.internet2.edu"
ENV COMANAGE_MAIL_FROM "comanage_registry@picard.cgac.uwm.edu"
ENV COMANAGE_MAIL_HOST "localhost"
ENV COMANAGE_MAIL_PORT "25"
ENV COMANAGE_MAIL_USER "user"
ENV COMANAGE_MAIL_PASS "secret"
ENV MYSQL_HOST "i2mariadb"
ENV MYSQL_DATABASE "registry"
ENV MYSQL_USER "registry_user"
ENV MYSQL_PASSWORD "WJzesbe3poNZ91qIbmR7"
ENV TERM "testterm"
# How long will we wait for MariaDB to start up?
ENV WAIT_TIME 60

# Required volumes for mounting Shibboleth SSL files into container
VOLUME /opt/shibboleth/ssl/

# Required volumes for mounting Apache SSL files into container
VOLUME /opt/httpd/ssl/

# Port
EXPOSE 80 443

CMD ["/opt/bin/start.sh"]
68 changes: 51 additions & 17 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,45 +1,71 @@
node {
node('docker') {

stage 'Checkout'

checkout scm

stage 'Acquire util'

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

stage 'Build'

sh 'rm -rf tmp'

stage 'Setting build context'

def maintainer = maintainer()
def imagename = imagename()
def tag = env.BRANCH_NAME
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 ${imagename}:${tag}. \n\n ${error_details}"
sh "rm -f ./debug"
handleError(message)
}
if(maintainer){
echo "Building ${maintainer}:${tag} for ${maintainer}"
}

sh 'bin/build.sh'

stage 'Tests'

sh 'bin/test.sh'
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"

}

Expand All @@ -51,4 +77,12 @@ def maintainer() {
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'
}
3 changes: 2 additions & 1 deletion common.bash
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
maintainer="bigfleet"
imagename="comanage"
imagename="comanage"
version="1.0.5"
1 change: 1 addition & 0 deletions container_files/bin/cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#!/bin/bash
9 changes: 9 additions & 0 deletions container_files/bin/configure.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

/opt/bin/configure_httpd.sh

/opt/bin/configure_php.sh

/opt/bin/configure_shibd.sh


5 changes: 5 additions & 0 deletions container_files/bin/configure_http.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

log="/tmp/httpd.log"

echo "Configuring httpd: " > $log
7 changes: 7 additions & 0 deletions container_files/bin/configure_php.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

log="/tmp/php.log"

echo "Configuring php: " > $log


7 changes: 7 additions & 0 deletions container_files/bin/configure_shibd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

log="/tmp/shibd.log"

echo "Configuring shibd: " > $log


20 changes: 20 additions & 0 deletions container_files/bin/main.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash -x

log="/tmp/start-main.log"

echo "Starting Container: " > $log
date >> $log
echo "" >> $log

if [ -e "/tmp/firsttimerunning" ]; then

set -e

/opt/bin/configure.sh >> $log

/opt/bin/cleanup.sh >> $log

else
echo "COmanage container has run." >> $log
echo "If there are problems, docker rm this container and try again." >> $log
fi
33 changes: 33 additions & 0 deletions container_files/bin/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

log="/tmp/start-starting.log"
date >> $log
if [ -z ${COMPOSE+x} ]
then
echo "Not composed so not waiting for MariaDB: " > $log
/opt/bin/main.sh
laststatus="$?"
echo "Not composed status: $laststatus"
if [ "$laststatus" != "0" ]; then
echo "Not composed non-zero exit status: $laststatus" >> $log
echo "Not composed non-zero exit status: $laststatus"
exit 1
else
echo "COmanage was configured" >>$log
echo "COmanage was configured"
echo "Starting apache" >>$log
echo "Starting apache"
/usr/local/bin/httpd-shib-foreground &
fi
else
echo "Composed so waiting for MariaDB: " > $log
date >> $log
echo "Testing connectivity to database before continue with install" >> $log
echo "Testing connectivity to database before continue with install"
/opt/wait-for-it/wait-for-it.sh $MYSQL_HOST:3306 -t $WAIT_TIME --strict -- /opt/bin/main.sh

date >> $log
echo "Starting apache" >>$log
echo "Starting apache"
/usr/local/bin/httpd-shib-foreground &
fi
Loading

0 comments on commit 38fb350

Please sign in to comment.