In the early days, we had to maintain two docker registries, one in AWS us-east-1 and the other in eu-west-1. This required us to build our containers and then push it to both registries. Below is a build.grade using Ben’s Gradle-Docker plugin to do the following:
This is how the build.grade looks like:
Note that you can also build this on Jenkins.
- Builds a docker container based on the Dockerfile in the root directory.
- Tag and push to both repos (us-east-1 and eu-west-1).
This is how the build.grade looks like:
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
buildscript { | |
repositories { | |
jcenter() | |
} | |
dependencies { | |
classpath 'com.bmuschko:gradle-docker-plugin:2.3.1' | |
} | |
} | |
apply plugin: 'com.bmuschko.docker-remote-api' | |
import com.bmuschko.gradle.docker.tasks.container.* | |
import com.bmuschko.gradle.docker.tasks.image.* | |
def dockerRepo = "dockerregistry.us-east-1.mycompany.net:7001/offline-pipeline-jenkins" | |
def euDockerRepo = "dockerregistry.eu-west-1.mycompany.net:7001/offline-pipeline-jenkins" | |
repositories { | |
mavenCentral() | |
} | |
docker { | |
if ("JENKINS_HOME" in System.env) { | |
url = "unix:///var/run/docker.sock" | |
} else { | |
url = "http://192.168.59.103:2375" | |
} | |
} | |
task buildImage(type: DockerBuildImage) { | |
inputDir = file('.') | |
tag = "${dockerRepo}" | |
} | |
task pushImage(type: DockerPushImage) { | |
dependsOn buildImage | |
imageName = "${dockerRepo}" | |
tag = "latest" | |
} | |
task tagDocker(type: DockerTagImage) { | |
dependsOn buildImage | |
force = true | |
imageId = buildImage.getTag() | |
repository = "${euDockerRepo}" | |
tag = "latest" | |
} | |
task pushImageToEu(type: DockerPushImage) { | |
dependsOn tagDocker | |
imageName = "${euDockerRepo}" | |
tag = "latest" | |
} | |
task pushImages() { | |
dependsOn pushImage, pushImageToEu | |
} |
Note that you can also build this on Jenkins.
No comments:
Post a Comment