summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames E. Blair <jeblair@redhat.com>2019-01-21 13:33:01 -0800
committerJames E. Blair <jeblair@redhat.com>2019-01-22 09:02:44 -0800
commit2b7689ba0071882195ecefe578869291082c9fb9 (patch)
tree469a2369f63ed9df669f2dc5466f1795d4a5f5ad
parentcb54c59577f69687b283b2ccd117fe4c0bce2f9b (diff)
Add docker image build jobs
These are generic docker image build and upload jobs which use the recently added roles of the same names. With the new pass-to-parent feature, child jobs can add their own credentials to these jobs. Change-Id: I669a9e6616a031837adab8c5c5806431fcca2150
Notes
Notes (review): Code-Review+2: Tobias Henkel <tobias.henkel@bmw.de> Code-Review+2: David Shrewsbury <shrewsbury.dave@gmail.com> Workflow+1: David Shrewsbury <shrewsbury.dave@gmail.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Wed, 23 Jan 2019 15:16:46 +0000 Reviewed-on: https://review.openstack.org/632172 Project: openstack-infra/zuul-jobs Branch: refs/heads/master
-rw-r--r--playbooks/docker-image/README.rst80
-rw-r--r--playbooks/docker-image/credentials.rst22
-rw-r--r--playbooks/docker-image/pre.yaml3
-rw-r--r--playbooks/docker-image/promote.yaml3
-rw-r--r--playbooks/docker-image/run.yaml3
-rw-r--r--playbooks/docker-image/upload.yaml3
-rw-r--r--roles/build-docker-image/common.rst8
-rw-r--r--zuul.yaml30
8 files changed, 148 insertions, 4 deletions
diff --git a/playbooks/docker-image/README.rst b/playbooks/docker-image/README.rst
new file mode 100644
index 0000000..91bffd4
--- /dev/null
+++ b/playbooks/docker-image/README.rst
@@ -0,0 +1,80 @@
1This is one of a collection of jobs which are designed to work
2together to build, upload, and promote docker images in a gating
3context:
4
5 * :zuul:job:`build-docker-image`: Build the images.
6 * :zuul:job:`upload-docker-image`: Build and stage the images on dockerhub.
7 * :zuul:job:`promote-docker-image`: Promote previously uploaded images.
8
9The :zuul:job:`build-docker-image` job is designed to be used in
10a `check` pipeline and simply builds the images to verify that
11the build functions.
12
13The :zuul:job:`upload-docker-image` job builds and uploads the images
14to Docker Hub, but only with a single tag corresponding to the
15change ID. This job is designed in a `gate` pipeline so that the
16build produced by the gate is staged and can later be promoted to
17production if the change is successful.
18
19The :zuul:job:`promote-docker-image` job is designed to be used in a
20`promote` pipeline. It requires no nodes and runs very quickly on the
21Zuul executor. It simply re-tags a previously uploaded image for a
22change with whatever tags are supplied by
23:zuul:jobvar:`build-docker-image.docker_images.tags`. It also removes
24the change ID tag from the repository in Docker Hub, and removes any
25similar change ID tags more than 24 hours old. This keeps the
26repository tidy in the case that gated changes fail to merge after
27uploading their staged images.
28
29They all accept the same input data, principally a list of
30dictionaries representing the images to build. YAML anchors_ can be
31used to supply the same data to all three jobs.
32
33**Job Variables**
34
35.. zuul:jobvar:: zuul_work_dir
36 :default: {{ zuul.project.src_dir }}
37
38 The project directory. Serves as the base for
39 :zuul:jobvar:`build-docker-image.docker_images.context`.
40
41.. zuul:jobvar:: docker_images
42 :type: list
43
44 A list of images to build. Each item in the list should have:
45
46 .. zuul:jobvar:: context
47
48 The docker build context; this should be a directory underneath
49 :zuul:jobvar:`build-docker-image.zuul_work_dir`.
50
51 .. zuul:jobvar:: repository
52
53 The name of the target repository in dockerhub for the
54 image. Supply this even if the image is not going to be
55 uploaded (it will be tagged with this in the local
56 registry).
57
58 .. zuul:jobvar:: path
59
60 Optional: the directory that should be passed to docker build.
61 Useful for building images with a Dockerfile in the context
62 directory but a source repository elsewhere.
63
64 .. zuul:jobvar:: build_args
65 :type: list
66
67 Optional: a list of values to pass to the docker ``--build-arg``
68 parameter.
69
70 .. zuul:jobvar:: target
71
72 Optional: the target for a multi-stage build.
73
74 .. zuul:jobvar:: tags
75 :type: list
76 :default: ['latest']
77
78 A list of tags to be added to the image when promoted.
79
80.. _anchors: https://yaml.org/spec/1.2/spec.html#&%20anchor//
diff --git a/playbooks/docker-image/credentials.rst b/playbooks/docker-image/credentials.rst
new file mode 100644
index 0000000..4587dbf
--- /dev/null
+++ b/playbooks/docker-image/credentials.rst
@@ -0,0 +1,22 @@
1.. zuul:jobvar:: docker_credentials
2 :type: dict
3
4 This is expected to be a Zuul Secret with these keys:
5
6 .. zuul:jobvar:: username
7
8 The Docker Hub username.
9
10 .. zuul:jobvar:: password
11
12 The Docker Hub password.
13
14 .. zuul:jobvar:: repository
15
16 Optional; if supplied this is a regular expression which
17 restricts to what repositories the image may be uploaded. The
18 following example allows projects to upload images to
19 repositories within an organization based on their own names::
20
21 repository: "^myorgname/{{ zuul.project.short_name }}.*"
22
diff --git a/playbooks/docker-image/pre.yaml b/playbooks/docker-image/pre.yaml
new file mode 100644
index 0000000..52f5b5b
--- /dev/null
+++ b/playbooks/docker-image/pre.yaml
@@ -0,0 +1,3 @@
1- hosts: all
2 roles:
3 - install-docker
diff --git a/playbooks/docker-image/promote.yaml b/playbooks/docker-image/promote.yaml
new file mode 100644
index 0000000..8160bf4
--- /dev/null
+++ b/playbooks/docker-image/promote.yaml
@@ -0,0 +1,3 @@
1- hosts: localhost
2 roles:
3 - promote-docker-image
diff --git a/playbooks/docker-image/run.yaml b/playbooks/docker-image/run.yaml
new file mode 100644
index 0000000..d3525ad
--- /dev/null
+++ b/playbooks/docker-image/run.yaml
@@ -0,0 +1,3 @@
1- hosts: all
2 roles:
3 - build-docker-image
diff --git a/playbooks/docker-image/upload.yaml b/playbooks/docker-image/upload.yaml
new file mode 100644
index 0000000..712f726
--- /dev/null
+++ b/playbooks/docker-image/upload.yaml
@@ -0,0 +1,3 @@
1- hosts: all
2 roles:
3 - upload-docker-image
diff --git a/roles/build-docker-image/common.rst b/roles/build-docker-image/common.rst
index 45484a9..affb19f 100644
--- a/roles/build-docker-image/common.rst
+++ b/roles/build-docker-image/common.rst
@@ -20,8 +20,8 @@ production if the change is successful.
20The :zuul:role:`promote-docker-image` role is designed to be used in a 20The :zuul:role:`promote-docker-image` role is designed to be used in a
21`promote` pipeline. It requires no nodes and runs very quickly on the 21`promote` pipeline. It requires no nodes and runs very quickly on the
22Zuul executor. It simply re-tags a previously uploaded image for a 22Zuul executor. It simply re-tags a previously uploaded image for a
23change with whatever tags are supplied by the 23change with whatever tags are supplied by
24:zuul:rolevar:`build-docker-image.docker_images.context`. It also 24:zuul:rolevar:`build-docker-image.docker_images.tags`. It also
25removes the change ID tag from the repository in Docker Hub, and 25removes the change ID tag from the repository in Docker Hub, and
26removes any similar change ID tags more than 24 hours old. This keeps 26removes any similar change ID tags more than 24 hours old. This keeps
27the repository tidy in the case that gated changes fail to merge after 27the repository tidy in the case that gated changes fail to merge after
@@ -88,7 +88,7 @@ using this role.
88 Useful for building images with a Dockerfile in the context 88 Useful for building images with a Dockerfile in the context
89 directory but a source repository elsewhere. 89 directory but a source repository elsewhere.
90 90
91 .. zuul:jobvar:: build_args 91 .. zuul:rolevar:: build_args
92 :type: list 92 :type: list
93 93
94 Optional: a list of values to pass to the docker ``--build-arg`` 94 Optional: a list of values to pass to the docker ``--build-arg``
@@ -98,7 +98,7 @@ using this role.
98 98
99 Optional: the target for a multi-stage build. 99 Optional: the target for a multi-stage build.
100 100
101 .. zuul:jobvar:: tags 101 .. zuul:rolevar:: tags
102 :type: list 102 :type: list
103 :default: ['latest'] 103 :default: ['latest']
104 104
diff --git a/zuul.yaml b/zuul.yaml
index 761951e..2d1aa57 100644
--- a/zuul.yaml
+++ b/zuul.yaml
@@ -21,6 +21,36 @@
21 post-run: playbooks/unittests/post.yaml 21 post-run: playbooks/unittests/post.yaml
22 22
23- job: 23- job:
24 name: build-docker-image
25 description: |
26 Build a docker image.
27
28 .. include:: ../../playbooks/docker-image/README.rst
29 pre-run: playbooks/docker-image/pre.yaml
30 run: playbooks/docker-image/run.yaml
31
32- job:
33 name: upload-docker-image
34 parent: build-docker-image
35 description: |
36 Build and upload a docker image.
37
38 .. include:: ../../playbooks/docker-image/README.rst
39 .. include:: ../../playbooks/docker-image/credentials.rst
40 post-run: playbooks/zuul/docker-image/upload.yaml
41
42- job:
43 name: promote-docker-image
44 description: |
45 Retag a previously-uploaded docker image.
46
47 .. include:: ../../playbooks/docker-image/README.rst
48 .. include:: ../../playbooks/docker-image/credentials.rst
49 run: playbooks/zuul/build-image/promote.yaml
50 nodeset:
51 nodes: []
52
53- job:
24 name: tox 54 name: tox
25 parent: unittests 55 parent: unittests
26 description: | 56 description: |