docker-build-publish: add registry + server support

registry: where to push images,
server: where to run the docker file onto
e.g.

registry:
  url: https://registry.example.com/
  credentials-id: foobar

Co-Authored-By: Linus Wallgren <linus.wallgren@scypho.com>
Change-Id: I2e592b1c52138bd4623ad2acd05c744224a8e50b
This commit is contained in:
Alexander Couzens 2016-06-30 20:39:39 +02:00 committed by Darragh Bailey
parent 0bdd819969
commit 52a77d639c
3 changed files with 79 additions and 1 deletions

View File

@ -3543,6 +3543,14 @@ def docker_build_publish(parse, xml_parent, data):
:arg str repo-name: Name of repository to push to.
:arg str repo-tag: Tag for image. (default '')
:arg dict server: The docker daemon (optional)
* **uri** (str): Define the docker server to use. (optional)
* **credentials-id** (str): ID of credentials to use to connect
(optional)
:arg dict registry: Registry to push to
* **url** (str) repository url to use (optional)
* **credentials-id** (str): ID of credentials to use to connect
(optional)
:arg bool no-cache: If build should be cached. (default false)
:arg bool no-force-pull: Don't update the source image before building when
it exists locally. (default false)
@ -3554,9 +3562,13 @@ def docker_build_publish(parse, xml_parent, data):
:arg str build-context: Project root path for the build, defaults to the
workspace if not specified. (default '')
Example:
Minimal example:
.. literalinclude:: /../../tests/builders/fixtures/docker-builder001.yaml
Full example:
.. literalinclude:: /../../tests/builders/fixtures/docker-builder002.yaml
"""
db = XML.SubElement(xml_parent,
'com.cloudbees.dockerpublish.DockerBuilder')
@ -3576,6 +3588,28 @@ def docker_build_publish(parse, xml_parent, data):
]
convert_mapping_to_xml(db, data, mapping, fail_required=True)
if 'server' in data:
server = XML.SubElement(db, 'server')
server.set('plugin', 'docker-commons')
server_data = data['server']
if 'credentials-id' in server_data:
XML.SubElement(server, 'credentialsId').text = str(
server_data['credentials-id'])
if 'uri' in server_data:
XML.SubElement(server, 'uri').text = str(
server_data['uri'])
if 'registry' in data:
registry = XML.SubElement(db, 'registry')
registry.set('plugin', 'docker-commons')
registry_data = data['registry']
if 'credentials-id' in registry_data:
XML.SubElement(registry, 'credentialsId').text = str(
registry_data['credentials-id'])
if 'url' in registry_data:
XML.SubElement(registry, 'url').text = str(
registry_data['url'])
def build_name_setter(registry, xml_parent, data):
"""yaml: build-name-setter

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<builders>
<com.cloudbees.dockerpublish.DockerBuilder plugin="docker-build-publish">
<repoName>test</repoName>
<repoTag>test-tag</repoTag>
<noCache>true</noCache>
<noForcePull>false</noForcePull>
<skipBuild>false</skipBuild>
<skipDecorate>false</skipDecorate>
<skipTagLatest>false</skipTagLatest>
<skipPush>false</skipPush>
<dockerfilePath>/tmp/</dockerfilePath>
<buildContext>/tmp/</buildContext>
<server plugin="docker-commons">
<credentialsId>docker-server</credentialsId>
<uri>unix:///var/run/docker.sock</uri>
</server>
<registry plugin="docker-commons">
<credentialsId>registry-docker</credentialsId>
<url>https://registry.example.org</url>
</registry>
</com.cloudbees.dockerpublish.DockerBuilder>
</builders>
</project>

View File

@ -0,0 +1,19 @@
builders:
- docker-build-publish:
repo-name: 'test'
repo-tag: 'test-tag'
no-cache: true
no-force-pull: false
skip-build: false
skip-decorate: false
skip-latest: false
skip-tag: false
file-path: '/tmp/'
build-context: '/tmp/'
registry:
url: 'https://registry.example.org'
credentials-id: 'registry-docker'
server:
uri: 'unix:///var/run/docker.sock'
credentials-id: 'docker-server'