Skip to content

Commit

Permalink
Merge pull request #56 from geoadmin/c2c-ci
Browse files Browse the repository at this point in the history
C2c ci
  • Loading branch information
pmauduit authored Jun 26, 2017
2 parents 53f7a92 + 79ef3d1 commit 2247c64
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 1 deletion.
128 changes: 128 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#!/usr/bin/groovy

@Library('c2c-pipeline-library') import static com.camptocamp.utils.*

selectNodes {
(it.memorysize_mb as Float) > 12000
}

dockerBuild {

def mavenOpts = '-B -Dmaven.repo.local=./.m2_repo -Ddb.username=geonetwork -Ddb.name=geonetwork -Ddb.type=postgres -Ddb.host=database -Ddb.password=geonetwork'

stage('Docker pull the maven image') {
sh 'docker pull maven:3-jdk-8'
}
withDockerContainer(image: 'maven:3-jdk-8') {
stage('Getting the sources') {
git url: 'https://github.com/camptocamp/geocat.git', branch: env.BRANCH_NAME
sh 'git submodule update --init --recursive'
}
stage('First build without test') {
sh "mvn clean install ${mavenOpts} -DskipTests"
}
stage('Second build with tests') {
sh "mvn clean install ${mavenOpts} -fn"
}
stage('calculating coverage') {
sh "mvn cobertura:cobertura ${mavenOpts} -fn -Dcobertura.report.format=xml"
step([$class: 'CoberturaPublisher',
autoUpdateHealth: false,
autoUpdateStability: false,
coberturaReportFile: '**/target/site/cobertura/coverage.xml',
failNoReports: true,
failUnhealthy: false,
failUnstable: false,
maxNumberOfBuilds: 0,
onlyStable: false,
sourceEncoding: 'UTF_8',
zoomCoverageChart: true])
}
stage('Saving tests results') {
junit '**/target/surefire-reports/TEST-*.xml'
}
stage('configure georchestra c2c docker-hub account') {
// Requires a username / password configured in Jenkins' credentials, with id docker-c2cgeorchestra
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'dockerhub',
usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) {
def configXmlStr = """<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>docker-hub</id>
<username>USERNAME</username>
<password>PASSWORD</password>
<configuration>
<email>[email protected]</email>
</configuration>
</server>
</servers>
</settings>""".replaceAll("USERNAME", env.USERNAME).replaceAll("PASSWORD", env.PASSWORD)
sh "echo '${configXmlStr}' > /settings.xml"
}
}
stage('Build/publish a docker image') {
// one-liner to setup docker
sh 'curl -fsSLO https://get.docker.com/builds/Linux/x86_64/docker-17.05.0-ce.tgz && tar --strip-components=1 -xvzf docker-17.05.0-ce.tgz -C /usr/local/bin'
sh "mvn -s /settings.xml ${mavenOpts} -pl web -Pdocker docker:build docker:push"
}
} // withDockerContainer

// Using another container, deploys the previously published image onto the dev env
stage('Deploy newly created images on the dev env') {
withDockerContainer(image: 'debian', args: "--privileged -u 0:0") {

stage('Install / configure needed tools') {
sh 'apt update && apt install -y make ssh git wget unzip'
sh 'mkdir -p ~/bin'
} // stage

stage("Prepare caas-dev access") {
withCredentials([file(credentialsId: 'jenkins-caas-dev-bgdi.ch.json', variable: 'FILE')]) {
sh 'mkdir -p ~/.rancher'
sh "cp ${FILE} ~/.rancher/caas.dev.bgdi.ch.json"
} // withCredentials
} // stage

stage("Configuring AWS / S3") {
sh 'mkdir ~/.aws'
withCredentials([[$class: 'UsernamePasswordMultiBinding',
credentialsId: 'terraform-georchestra-aws-credentials',
usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) {
def credentialsFile = """
[c2c]
aws_access_key_id = ${env.USERNAME}
aws_secret_access_key = ${env.PASSWORD}
region = eu-west-1
"""
sh "echo '${credentialsFile}' > ~/.aws/credentials"
} // withCredentials
} // stage

stage('Checking out the terraform-geocat repository') {
sshagent(["terraform-geocat-deploy-key"]) {
sh "ssh -oStrictHostKeyChecking=no [email protected] || true"
sh "rm -rf terraform-geocat"
sh "git clone [email protected]:camptocamp/terraform-geocat.git"
} // sshagent
} // stage

stage('Terraforming') {
ansiColor('xterm') {
if (env.BRANCH_NAME == 'geocat_3.4.x') {
sh """cd terraform-geocat &&
ln -s /root/bin/terraform /usr/bin &&
make install &&
make init &&
cd rancher-environments/geocat-dev &&
terraform apply"""
} else {
println "Not onto the 'geocat_3.4.x' branch, skipping redeploy"
}// if
} // ansiColor
} // stage
} // withDockerContainer
} // stage
} // dockerBuild
27 changes: 26 additions & 1 deletion web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -793,8 +793,33 @@
<es.spring.profile>es</es.spring.profile>
</properties>
</profile>
<profile>
<id>docker</id>
<build>
<plugins>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.14</version>
<configuration>
<imageName>camptocamp/geocat:${project.version}</imageName>
<baseImage>tomcat:8-jre8</baseImage>
<resources>
<resource>
<targetPath>/usr/local/tomcat/webapps</targetPath>
<directory>${project.build.directory}</directory>
<include>geonetwork.war</include>
</resource>
</resources>
<!-- This will require a settings.xml file for maven -->
<serverId>docker-hub</serverId>
<registryUrl>https://index.docker.io/v1/</registryUrl>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<properties>
<geonetwork.version>${project.version}</geonetwork.version>
<geonetwork.subversion>SNAPSHOT</geonetwork.subversion>
Expand Down

0 comments on commit 2247c64

Please sign in to comment.