Revise docker-get-container-tag-script macro
[releng/global-jjb.git] / docs / jjb / lf-docker-jobs.rst
1 ###########
2 Docker Jobs
3 ###########
4
5 Job Groups
6 ==========
7
8 .. include:: ../job-groups.rst
9
10 Below is a list of Docker job groups:
11
12 .. literalinclude:: ../../jjb/lf-docker-job-groups.yaml
13    :language: yaml
14
15
16 Macros
17 ======
18
19 lf-docker-get-container-tag
20 ---------------------------
21
22 Chooses a tag to label the container image based on the
23 'container-tag-method' parameter using the global-jjb script
24 docker-get-container-tag.sh. Use one of the following methods:
25
26 If container-tag-method: latest, the literal string 'latest' is used.
27
28 If container-tag-method: git-describe, the tag is obtained using the
29 git describe command on the repository, which requires that the repository
30 has a git tag. For example, if the most recent tag is 'v0.48.1', this
31 method yields a string like 'v0.48.1' or 'v0.48.1-25-gaee2dcb'.
32
33 If container-tag-method: yaml-file, the tag is obtained from the YAML file
34 'container-tag.yaml' in the docker-root directory using the top-level entry
35 'tag'. Alternately specify the directory with the YAML file in parameter
36 'container-tag-yaml-dir'. An example file appears next.
37
38 Example container-tag.yaml file:
39
40 .. code-block:: yaml
41
42    ---
43    tag: 1.0.0
44
45
46 Optionally, teams can supply their own script to choose the docker
47 tag. Pass the shell script path in optional configuration parameter
48 'docker-get-container-tag-script' which by default is the path to
49 file docker-get-container-tag.sh. The script must create the file
50 'env_docker_inject.txt' in the workspace with a line that assigns a
51 value to shell variable DOCKER_IMAGE_TAG, as shown next.
52
53 Example env_docker_inject.txt file:
54
55 .. code-block:: shell
56
57     DOCKER_IMAGE_TAG=1.0.0
58
59
60 lf-docker-build
61 ---------------
62
63 Calls docker build to build the container.
64
65 lf-docker-push
66 --------------
67
68 Calls docker-push.sh script to push docker images.
69
70 Job Templates
71 =============
72
73 Docker Verify
74 -------------
75
76 Executes a docker build task.
77
78 :Template Names:
79
80     - {project-name}-docker-verify-{stream}
81     - gerrit-docker-verify
82     - github-docker-verify
83
84 :Comment Trigger: **recheck|reverify** post a comment with one of the
85     triggers to launch this job manually. Do not include any other
86     text or vote in the same comment.
87
88 :Required parameters:
89
90     :build-node: The node to run build on.
91     :container-public-registry: Docker registry source with base images.
92     :docker-name: Name of the Docker image.
93     :jenkins-ssh-credential: Credential to use for SSH. (Generally should
94         be configured in defaults.yaml)
95     :mvn-settings: Maven settings.xml file containing credentials to use.
96
97 :Optional parameters:
98
99     :branch: Git branch to fetch for the build. (default: master)
100     :build-days-to-keep: Days to keep build logs in Jenkins. (default: 7)
101     :build-timeout: Timeout in minutes before aborting build. (default: 60)
102     :container-tag-method: Specifies the docker tag-choosing method.
103         Options are "latest", "git-describe" or "yaml-file".
104         Option git-describe requires a git tag to exist in the repository.
105         Option yaml-file requires a file "container-tag.yaml" to exist in the repository.
106         (default: latest)
107     :container-tag-yaml-dir: Directory with container-tag.yaml. (default: $DOCKER_ROOT)
108     :docker-build-args: Additional arguments for the docker build command.
109     :docker-get-container-tag-script: Path to script that chooses docker tag.
110         (default: ../shell/docker-get-container-tag.sh)
111     :docker-root: Build directory within the repo. (default: $WORKSPACE, the repo root)
112     :git-url: URL clone project from. (default: $GIT_URL/$PROJECT)
113     :pre_docker_build_script: Build script to execute before the main verify
114         builder steps. (default: a string with only a comment)
115     :post_docker_build_script: Build script to execute after the main verify
116         builder steps. (default: a string with only a comment)
117     :stream: Keyword that can be used to represent a release code-name.
118         Often the same as the branch. (default: master)
119     :submodule-recursive: Whether to checkout submodules recursively.
120         (default: true)
121     :submodule-timeout: Timeout (in minutes) for checkout operation.
122         (default: 10)
123
124     :gerrit_verify_triggers: Override Gerrit Triggers.
125     :gerrit_trigger_file_paths: Override Gerrit file paths which can be
126         used to filter which file modifications will trigger a build.
127     :github_included_regions: Override Github file paths which can be
128         used to filter which file modifications will trigger a build;
129         must match parameter gerrit_trigger_file_paths
130
131
132 container-tag.yaml example:
133
134 .. code-block:: yaml
135
136    ---
137    tag: 1.0.0
138
139 Docker Merge
140 ------------
141
142 Executes a docker build task and publishes the resulting images to a specified Docker registry.
143
144 :Template Names:
145
146     - {project-name}-docker-merge-{stream}
147     - gerrit-docker-merge
148     - github-docker-merge
149
150 :Comment Trigger: **remerge** post a comment with the trigger to launch
151     this job manually. Do not include any other text or vote in the
152     same comment.
153
154 :Required parameters:
155
156     :build-node: The node to run build on.
157     :container-public-registry: Docker registry source with base images.
158     :container-push-registry: Docker registry target for the deploy action.
159     :docker-name: Name of the Docker image.
160     :jenkins-ssh-credential: Credential to use for SSH. (Generally should
161         be configured in defaults.yaml)
162     :mvn-settings: Maven settings.xml file containing credentials to use.
163
164 :Optional parameters:
165
166     :branch: Git branch to fetch for the build. (default: master)
167     :build-days-to-keep: Days to keep build logs in Jenkins. (default: 7)
168     :build-timeout: Timeout in minutes before aborting build. (default: 60)
169     :container-tag-method: Specifies the docker tag-choosing method.
170         Options are "latest", "git-describe" or "yaml-file".
171         Option git-describe requires a git tag to exist in the repository.
172         Option yaml-file requires a file "container-tag.yaml" to exist in the repository.
173         (default: latest)
174     :container-tag-yaml-dir: Directory with container-tag.yaml. (default: $DOCKER_ROOT)
175     :cron: Cron schedule when to trigger the job. This parameter also
176         supports multiline input via YAML pipe | character in cases where
177         one may want to provide more than 1 cron timer. No default. Use
178         '@daily' to run daily or 'H H * * 0' to run weekly.
179     :docker-build-args: Additional arguments for the docker build command.
180     :docker-get-container-tag-script: Path to script that chooses docker tag.
181         (default: ../shell/docker-get-container-tag.sh)
182     :docker-root: Build directory within the repo. (default: $WORKSPACE, the repo root)
183     :git-url: URL clone project from. (default: $GIT_URL/$PROJECT)
184     :pre_docker_build_script: Build script to execute before the main merge
185         builder steps. (default: a string with only a comment)
186     :post_docker_build_script: Build script to execute after the main merge
187         builder steps. (default: a string with only a comment)
188     :stream: Keyword that can be used to represent a release code-name.
189         Often the same as the branch. (default: master)
190     :submodule-recursive: Whether to checkout submodules recursively.
191         (default: true)
192     :submodule-timeout: Timeout (in minutes) for checkout operation.
193         (default: 10)
194
195     :gerrit_merge_triggers: Override Gerrit Triggers.
196     :gerrit_trigger_file_paths: Override Gerrit file paths which can be
197         used to filter which file modifications will trigger a build.
198     :github_included_regions: Override Github file paths which can be
199         used to filter which file modifications will trigger a build;
200         must match parameter gerrit_trigger_file_paths
201
202 Sample container-tag.yaml File
203 ------------------------------
204
205 .. code-block:: yaml
206
207    ---
208    tag: 1.0.0