Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: docker/comanage-match-base
base: master
Choose a base ref
...
head repository: docker/comanage-match-base
compare: develop1
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 2 commits
  • 13 files changed
  • 1 contributor

Commits on Aug 19, 2019

  1. inital commit of COmanage match for Dockerhub

    chubing committed Aug 19, 2019
    Copy the full SHA
    38cd8b4 View commit details
  2. Update Jenkinsfile

    chubing committed Aug 19, 2019
    Copy the full SHA
    1df34bb View commit details
82 changes: 82 additions & 0 deletions DatabaseConnectivityTestCommand.php
@@ -0,0 +1,82 @@
<?php
/**
* COmanage Database Connectivity Test Command, shared between Match and Registry
*
* Portions licensed to the University Corporation for Advanced Internet
* Development, Inc. ("UCAID") under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* UCAID licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @link http://www.internet2.edu/comanage COmanage Project
* @package match
* @since COmanage Common v1.0.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/

/**
* THIS FILE SHOULD BE MASTERED IN THE COMMON REPOSITORY.
*/

declare(strict_types = 1);

namespace App\Command;

use Cake\Console\Arguments;
use Cake\Console\Command;
use Cake\Console\ConsoleIo;
use Cake\Datasource\ConnectionManager;

use Doctrine\DBAL\DriverManager;

class DatabaseConnectivityTestCommand extends Command {
/**
* Test Connectivity to the Database
*
* @since COmanage Match v1.0.0, COmanage Registry v5.0.0
* @param Arguments $args Command Arguments
* @param ConsoleIo $io Console IO
* @throws RuntimeException
*/

public function execute(Arguments $args, ConsoleIo $io) {
// Use the ConnectionManager to get the database config.
$db = ConnectionManager::get('default');

// $db is a ConnectionInterface object
$cfg = $db->config();

$config = new \Doctrine\DBAL\Configuration();

$cfargs = [
'dbname' => $cfg['database'],
'user' => $cfg['username'],
'password' => $cfg['password'],
'host' => $cfg['host'],
'driver' => ($cfg['driver'] == 'Cake\Database\Driver\Postgres' ? "pdo_pgsql" : "pdo_mysql")
];

$conn = DriverManager::getConnection($cfargs, $config);

try {
$conn->query('SELECT NOW()');
$io->out("Connected to database");
return 0;
}
catch(\Exception $e) {
$io->out("Unable to connect to database");
return 1;
}
}
}
64 changes: 64 additions & 0 deletions DatabaseSetupAlreadyCommand.php
@@ -0,0 +1,64 @@
<?php
/**
* COmanage Database Setup Already Command, shared between Match and Registry
*
* Portions licensed to the University Corporation for Advanced Internet
* Development, Inc. ("UCAID") under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* UCAID licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @link http://www.internet2.edu/comanage COmanage Project
* @package match
* @since COmanage Common v1.0.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/

/**
* THIS FILE SHOULD BE MASTERED IN THE COMMON REPOSITORY.
*/

declare(strict_types = 1);

namespace App\Command;

use Cake\Console\Arguments;
use Cake\Console\Command;
use Cake\Console\ConsoleIo;
use Cake\ORM\TableRegistry;

class DatabaseSetupAlreadyCommand extends Command {
/**
* Test Connectivity to the Database
*
* @since COmanage Match v1.0.0, COmanage Registry v5.0.0
* @param Arguments $args Command Arguments
* @param ConsoleIo $io Console IO
* @throws RuntimeException
*/

public function execute(Arguments $args, ConsoleIo $io) {
$metaTable = TableRegistry::get('Meta');

try {
$metaTable->findById('1')->firstOrFail();
$io->out("Match database is setup");
return 0;
}
catch(\Exception $e) {
$io->out("Match database is not setup");
return 1;
}
}
}
112 changes: 112 additions & 0 deletions Dockerfile
@@ -0,0 +1,112 @@
# COmanage Match Dockerfile
#
# Portions licensed to the University Corporation for Advanced Internet
# Development, Inc. ("UCAID") under one or more contributor license agreements.
# See the NOTICE file distributed with this work for additional information
# regarding copyright ownership.
#
# UCAID licenses this file to you under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
FROM php:7.3.5-apache-stretch

# Official PHP image with Apache HTTPD includes
# --with-openssl
# --with-mbstring
# but intl, pdo, pdo_pgsql, pgsql,
# extensions must be built.
RUN apt-get update && apt-get install -y \
libicu-dev \
libpq-dev \
patch \
ssl-cert \
wget \
zlib1g \
libpcre3-dev \
&& docker-php-ext-configure intl \
&& docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
&& docker-php-ext-install intl pdo pdo_pgsql pgsql \
&& docker-php-source delete \
&& apt-get purge -y \
libicu-dev \
libpq-dev \
&& apt-get clean

ARG COMANAGE_MATCH_VERSION
ENV COMANAGE_MATCH_VERSION ${COMANAGE_MATCH_VERSION:-develop}
LABEL comanage_match_version=${COMANAGE_MATCH_VERSION}

ENV COMANAGE_MATCH_SRC_URL=https://github.internet2.edu/COmanage/match/archive/${COMANAGE_MATCH_VERSION}.tar.gz

ARG COMANAGE_MATCH_DIR
ENV COMANAGE_MATCH_DIR ${COMANAGE_MATCH_DIR:-/srv/comanage-match}
LABEL comanage_match_dir=${COMANAGE_MATCH_DIR}

WORKDIR $COMANAGE_MATCH_DIR

RUN mkdir -p ${COMANAGE_MATCH_DIR} \
&& wget -O comanage.tar.gz ${COMANAGE_MATCH_SRC_URL} \
&& tar -zxf comanage.tar.gz -C ${COMANAGE_MATCH_DIR} --strip-components=1 \
&& rm -f comanage.tar.gz \
&& rm -f ${COMANAGE_MATCH_DIR}/app/tmp \
&& rm -f ${COMANAGE_MATCH_DIR}/app/logs \
&& mkdir ${COMANAGE_MATCH_DIR}/app/tmp \
&& mkdir ${COMANAGE_MATCH_DIR}/app/logs \
&& chown -R www-data:www-data ${COMANAGE_MATCH_DIR}/app/tmp \
&& chown -R www-data:www-data ${COMANAGE_MATCH_DIR}/app/logs \
&& cd /var/www/html \
&& ln -s ${COMANAGE_MATCH_DIR}/app/webroot match

RUN a2enmod headers \
&& a2enmod ssl \
&& a2enmod rewrite \
&& a2dissite 000-default.conf \
&& a2disconf other-vhosts-access-log \
&& cd /etc/apache2 \
&& ln -s /etc/ssl/certs/ssl-cert-snakeoil.pem cert.pem \
&& ln -s /etc/ssl/private/ssl-cert-snakeoil.key privkey.pem

COPY apache-include-directory-match /etc/apache2/
COPY apache-include-virtual-host-port443-base /etc/apache2/
COPY apache-include-virtual-host-port80-redirect /etc/apache2/

COPY comanage_utils.sh /usr/local/lib/
COPY comanage_shibboleth_sp_utils.sh /usr/local/lib/
COPY docker-comanage-match-entrypoint /usr/local/bin/

# Patch to configure console logging. The patch is
# applied by the entry point script when appropriate.
#
# The patch is the output of the command
#
# diff -Naur app.php.original app.php > comanage_match_console_logging.patch
COPY comanage_match_console_logging.patch /usr/local/src/

# Add commands for testing database connectivity and setup status until
# they are part of Match source.
COPY DatabaseConnectivityTestCommand.php ${COMANAGE_MATCH_DIR}/app/src/Command/
COPY DatabaseSetupAlreadyCommand.php ${COMANAGE_MATCH_DIR}/app/src/Command/

VOLUME ${COMANAGE_MATCH_DIR}/local

EXPOSE 80 443

# Allow values for first administrator bootstrapped into the
# platform to be specified at image build time, in addition to
# being injected at run time through the entrypoint script.
ARG COMANAGE_MATCH_ADMIN_USERNAME

# Set simple defaults for first administrator bootstrapped into the
ENV COMANAGE_MATCH_ADMIN_USERNAME ${COMANAGE_MATCH_ADMIN_USERNAME:-match.admin}

ENTRYPOINT ["docker-comanage-match-entrypoint"]

CMD ["apache2-foreground"]
125 changes: 125 additions & 0 deletions Jenkinsfile
@@ -0,0 +1,125 @@
pipeline {
agent any
environment {
maintainer = "t"
imagename = 'g'
tag = 'l'
}
stages {
stage('Setting build context') {
steps {
script {
maintainer = maintain()
imagename = imagename()
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'
}
sh 'mkdir -p tmp && mkdir -p bin'
dir('tmp'){
git([ url: "https://github.internet2.edu/docker/util.git", credentialsId: "jenkins-github-access-token" ])
sh 'rm -rf ../bin/*'
sh 'mv ./bin/* ../bin/.'
}
// Build and test scripts expect that 'tag' is present in common.bash. This is necessary for both Jenkins and standalone testing.
// We don't care if there are more 'tag' assignments there. The latest one wins.
sh "echo >> common.bash ; echo \"tag=\\\"${tag}\\\"\" >> common.bash ; echo common.bash ; cat common.bash"
}
}
}
stage('Clean') {
steps {
script {
try{
sh 'bin/destroy.sh >> debug'
} catch(error) {
def error_details = readFile('./debug');
def message = "BUILD ERROR: There was a problem building the Base Image. \n\n ${error_details}"
sh "rm -f ./debug"
handleError(message)
}
}
}
}
stage('Build') {
steps {
script {
try{
docker.withRegistry('https://registry.hub.docker.com/', "dockerhub-$maintainer") {
baseImg = docker.build("$maintainer/$imagename", "--build-arg GROUPER_CONTAINER_VERSION=$tag --no-cache .")
}
} 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('Test') {
steps {
script {
try {
// sh 'bin/test.sh 2>&1 | tee debug ; test ${PIPESTATUS[0]} -eq 0'
echo 'no test yet'
} catch (error) {
def error_details = readFile('./debug')
def message = "BUILD ERROR: There was a problem testing ${imagename}:${tag}. \n\n ${error_details}"
sh "rm -f ./debug"
handleError(message)
}
}
}
}

stage('Push') {
steps {
script {
docker.withRegistry('https://registry.hub.docker.com/', "dockerhub-$maintainer") {
baseImg.push("$tag")
}
}
}
}
stage('Notify') {
steps{
echo "$maintainer"
slackSend color: 'good', message: "$maintainer/$imagename:$tag pushed to DockerHub"
}
}
}
post {
always {
echo 'Done Building.'
}
failure {
// slackSend color: 'good', message: "Build failed"
handleError("BUILD ERROR: There was a problem building ${maintainer}/${imagename}:${tag}.")
}
}
}


def maintain() {
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: 'chubing@internet2.edu', sendToIndividuals: true])
sh 'exit 1'
}