-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from geoadmin/c2c-ci
C2c ci
- Loading branch information
Showing
2 changed files
with
154 additions
and
1 deletion.
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,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 |
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