Skip to content
This repository has been archived by the owner on Jun 29, 2021. It is now read-only.

Issue 76 #80

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ You have to modify the env.file file with the following parameters:
- __DOCKER_USER__: is the Docker Hub user used to publish the build, see publishing section (ex. myuser) +
If not given, publishing to Docker Hub will not be enabled.
- __DOCKER_PASSWORD__: is the password of the Docker Hub user
- __DOCKER_HOST__: Ip that the jenkins-docker can reach to connect to the host docker by tls

Then, you can open it in your browser :

Expand Down
3 changes: 3 additions & 0 deletions env.file
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ GITHUB_TOKEN=token
# Credentials used for publishing image on docker hub (not mandatory)
#DOCKER_USER=user
#DOCKER_PASSWORD=pass

# Ip that the jenkins-docker can reach to connect to the host docker by tls
DOCKER_HOST=ip.of.the.host
25 changes: 14 additions & 11 deletions workflow-job
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.kohsuke.github.GHRepository
// $repoURL parameter : specifies the commiter GitHub repo URL
// $sha1 parameter : specifies the actual commit

def dockerIp = System.getenv("DOCKER_HOST")
def continuousDeploymentDockerIp = '62.210.101.42'
def continuousDeploymentConfigurationPath = '/root/james/conf'
def hostname = 'james.linagora.com'
Expand Down Expand Up @@ -212,6 +213,13 @@ def waitForCommandSuccess (command, maxRetries) {
}
}

env.DOCKER_CERT_PATH = '/keys/'
env.DOCKER_TLS_VERIFY = 'TRUE'

def setDockerHost(dockerHost) {
env.DOCKER_HOST = "tcp://${dockerHost}:2376"
}

def flows = [:]

def sha1OrBranch = {
Expand Down Expand Up @@ -256,6 +264,7 @@ def findImapPortCmd(dockerContainer) {
}

flows["${sha1}"] = {
setDockerHost(dockerIp)
def buildId = "${branch.toLowerCase()}-${UUID.randomUUID()}"
def mergeBranch = "MERGE-${buildId}"
def images = new Images(buildId);
Expand All @@ -267,8 +276,9 @@ flows["${sha1}"] = {
def findImapPortSpring = findImapPortCmd("${containers.jamesSpring}")

def sha1ToBuild = sha1OrBranch()
def integrationArguments = "localhost \$JAMES_PORT ${sha1ToBuild}"
def integrationArguments = "${dockerIp} \$JAMES_PORT ${sha1ToBuild}"
def verbose = "-a stdout -a stderr"
def dockerEnv = "--env=DOCKER_HOST=${env.DOCKER_HOST} --env=DOCKER_CERT_PATH=${env.DOCKER_CERT_PATH} --env=DOCKER_TLS_VERIFY=TRUE"

def statuses = new CommitStatuses();
def commitStatusFactory = new CommitStatusFactory(repoName, sha1);
Expand Down Expand Up @@ -326,7 +336,7 @@ flows["${sha1}"] = {
stage "Building ${buildId}"
node {
sh "docker build --tag=${images.jamesCompile} dockerfiles/compilation/java-8"
sh "cd dockerfiles/; docker run ${verbose} --tmpfs=/tmp:rw,exec,size=1g --tmpfs=/james-project:rw,size=4g --name=${containers.jamesCompile} ${useMavenCache} -e DOCKER_CONTAINER=${containers.jamesCompile} --volumes-from=${containers.keys} --volumes-from=${containers.gitPublish} --volume=/jpa/destination --volume=/cassandra/destination --volume=/spring/destination -v /var/run/docker.sock:/var/run/docker.sock ${images.jamesCompile} ${mergeBranch}"
sh "cd dockerfiles/; docker run ${verbose} --tmpfs=/tmp:rw,exec,size=1g --tmpfs=/james-project:rw,size=4g --name=${containers.jamesCompile} ${dockerEnv} ${useMavenCache} -e DOCKER_CONTAINER=${containers.jamesCompile} --volumes-from=${containers.keys} --volumes-from=${containers.gitPublish} --volume=/jpa/destination --volume=/cassandra/destination --volume=/spring/destination ${images.jamesCompile} ${mergeBranch}"

buildingJava8.success();
}
Expand Down Expand Up @@ -498,26 +508,19 @@ flows["${sha1}"] = {
}
stage "Continuous Deployment"
node {
try {
env.DOCKER_CERT_PATH = '/keys/'
env.DOCKER_TLS_VERIFY = 'TRUE'
env.DOCKER_HOST = "tcp://${continuousDeploymentDockerIp}:2376"
setDockerHost(continuousDeploymentDockerIp)
sh "docker pull linagora/james-project"
if (isAlive("james-project")) {
sh "docker rm -f james-project"
}
sh "docker run --hostname linagora.com -p '80:80' -p '25:25' -p '110:110' -p '143:143' -p '465:465' -p '587:587' -p '993:993' -p '8000:8000' --link cassandra:cassandra --link elasticsearch:elasticsearch -d --name james-project -v ${continuousDeploymentConfigurationPath}:/root/conf -t linagora/james-project"
continuousDeployment.success();
} finally {
env.DOCKER_CERT_PATH = null
env.DOCKER_TLS_VERIFY = null
env.DOCKER_HOST = null
}
}
}
} finally {
stage "Cleaning ${buildId}"
node {
setDockerHost(dockerIp)
deleteContainer(containers.gitPublish)
deleteImage(images.gitPublish)

Expand Down