Preview a template change of a container
POST/containers/:containerId/template/preview
Shows what changing the template of this resource to the given target would do, without changing anything (read-only:
nothing is written, no branch is created and no build is started). Takes the same body as the matching
PUT .../template change operation, including includePaths.
Intended flow:
- Call this operation with the target
id,version,custom(andpropertiesif needed). - Show the user the
effectswithactor: PLATFORM(what CodeNOW will do itself), theeffectswithactor: USER(what the user must do) and the diff of the files withmanagedBy: REPOSITORY. - If the user wants to see a scaffold file from
otherFiles, read it on demand withPOST .../template/preview/file(same body withoutincludePaths, plus itspath). - Let the user choose which files go into the change branch:
files[]withselectable: trueandotherFilesthat are not asymlink..codenow.yamlis always included. Call this operation again with them inincludePathsto see the resultingoutcomeand effects. - Only after the user confirms, call
PUT .../templatewith the same body. The resource switches to the new template immediately; the files go to a new branch the user merges into the default branch themselves.
Submitting the resource's current template + version is not an error: thevsCurrentTemplatecomparisons come backIDENTICAL;vsRepositorystill shows where the repository differs from the template.
Response:
repository:branch(the default branch) andcommitthe preview was computed against; there is no lock, the branch may move before the change.advancedMode:truewhen advanced mode is on (advancedMode.enabledin the branch's.codenow.yaml),falsewhen it is off.nullwhen the target template declares no advanced mode setting (e.g.docker-generic,helm-genericand other runnable templates; libraries, containers). Which files the user has to handle is decided per file bymanagedBy, not by this flag.
files[]:pathis relative to the resource root. For a different template the list is the platform-owned set.codenow.yaml,Dockerfile, thehelm/directory. For the same template at a new version it also covers every other rendered file when the current version could be rendered, withmanagedBy: REPOSITORYand onlyvsCurrentTemplate(old version against new version).
managedBysays who keeps a file up to date after the change; decide per file on it, never onadvancedModealone:.codenow.yamlis alwaysPLATFORM: the change merges it and always commits it to the change branch.REPOSITORY: the user's own file. The repository's copy is authoritative; CodeNOW does not render it at build time. Its diff is a change the user has to make: include the path inincludePathsor apply the diff by hand. This covers four cases:
(1) theDockerfileand thehelm/files when the resource's advanced mode is on (advancedMode.enabledin the default branch's.codenow.yaml; application components and agents only);
(2) for a runnable target template (e.g.docker-generic,helm-generic), for every kind: theDockerfilewhen the template needs a Dockerfile, thehelm/files when it needs helm files. This holds regardless of advanced mode: with advanced mode off they are still the user's files; do not ignore their diff;
(3) a container'sDockerfile, always;
(4) the other template files. They appear infiles[]only when the target is the same template as the current one (a version change) and the current version could be rendered. For a different template they are listed only inotherFiles[], which has nomanagedBy.PLATFORM(any otherDockerfileorhelm/file): rendered by CodeNOW from the template at every build and never part of the change branch; its diff is informational.
selectable:truewhen the target template renders the path, the path is not.codenow.yaml, the file ismanagedBy: REPOSITORY, and it can be replaced in the repository: it is not a symbolic link and not below one, no repository file sits at a parent path, and no repository directory sits at the path itself. Such a path may be put intoincludePaths. Identical content does not make a file unselectable; an unchanged file is simply not part of the commit. A file that only the previous version renders isREPOSITORYbut not selectable.
symlink: true when the path is a symbolic link in the repository or lies below a linked directory (e.g.
helm is a link ⇒ helm/values.yaml). Such a path is never read (no
comparison with the repository is returned for it), is not selectable, and naming it in includePaths answers
400 E7018.
Each file has up to two comparisons, omitted where they do not apply, each {result, current, target}:
vsCurrentTemplate compares the current template's rendering with the target (omitted everywhere when the current version is
no longer available — effect CURRENT_TEMPLATE_UNAVAILABLE); vsRepository compares the repository's file with the
target (platform-owned files only). For .codenow.yaml the vsRepository target is the merged file the change will
commit (omitted when the repository has no .codenow.yaml — effect CODENOW_YAML_ABSENT).
result is CHANGED, IDENTICAL, TARGET_ONLY (only the target has the file) or
OTHER_ONLY (only the current template or the repository has it). current and target are the
base64-encoded file contents, null where the file does not exist.
otherFiles[]: every file the target template renders outside the platform-owned set (the application scaffold), names only, in both cases (so with the same template, when the current version could be rendered, they are also infiles[]);inRepository: whether the path already exists;binary: the content cannot be represented as text;symlink: the path is a symbolic link in the repository or lies below a linked directory — it is never read and cannot be put intoincludePaths(400E7018). CodeNOW does not require these files; each other one can be put intoincludePathswhen it can be replaced in the repository (a repository file at a parent path or a directory at the path answers 400E7018), or the user applies it by hand as far as the resource needs it. The content of one comes fromPOST .../template/preview/file; the content of a binary file is not returned; to get the file, include its path inincludePathsso it is committed to the branch.outcome: what confirming the change with thisincludePathswould do —branch(the name of the branch the change creates, starting withcodenow/change-template-;nullwhen nothing would be committed),branchExists(true: the change would fail with 409E7019; the user merges or deletes the branch first),baseBranchandbaseCommitit would start from,pathsthe commit would change (included files identical to the repository are skipped; empty: no branch would be created).effects[]:{code, actor, message, key, value, previousValue, defaultValue}; the last four are optional strings, omitted when they do not apply. Key oncode(the list may grow);messageis end-user English.
actor: PLATFORM— CodeNOW does it itself:BRANCH_CREATED: the selected files are committed to the new branch;CI_FILES_RENDERED_AT_NEXT_BUILD: thePLATFORMDockerfile/helm/files are rendered from the new template at the next build;CODENOW_YAML_MERGED:.codenow.yamlis merged with the new template, not overwritten;CODENOW_YAML_ABSENT: the repository has no.codenow.yaml;PIPELINE_CHANGED: a pipeline that still equals the old template's default follows the new template's default. Carrieskey,previousValue→value(the target default);PIPELINE_DEFAULT_KEPT: the pipeline equals the previous template's default and the new template has none, so it is kept. Carrieskey,value;CI_PROPERTY_CHANGED: a CI setting that still equals the old template's default follows the new template's default. Carrieskey,previousValue→value,defaultValue(=value);CI_PROPERTY_ADDED: a CI setting the current template does not declare is added with the target template's default. Carrieskey,value,defaultValue(=value);CI_PROPERTY_DROPPED: a CI setting the new template no longer declares is removed. Carrieskey,previousValue; novalue;CI_PROPERTY_DEFAULT_KEPT: the CI setting's value equals the previous template's default and the new template has none, so it is kept. Carrieskey,value;CURRENT_TEMPLATE_UNAVAILABLE: the current template version is no longer available;vsCurrentTemplateis omitted everywhere.
actor: USER— the user has to do it:MERGE_BRANCH: review the new branch and merge it into the default branch;BRANCH_EXISTS: the branch already exists; merge or delete it before confirming;TEMPLATE_SWITCHED_BEFORE_MERGE: the resource is on the new template at once, while the default branch keeps the old files until the merge;APPLY_REPOSITORY_CHANGES: changedmanagedBy: REPOSITORYDockerfile/helm/files are not included; include them or apply the changes by hand. Not raised when only other files differ;PIPELINE_KEPT: a customised pipeline is kept; the message names the new default. Carrieskey,value(the user's pipeline),defaultValue(what the new template would use; absent when it has none);CI_PROPERTY_KEPT: a customised CI setting is kept; reported only when its default changed between the templates or the current template is unknown. Carrieskey,value(the user's value),defaultValue(what the new template would use; absent when it has none or it is blank);CODENOW_YAML_NOT_MERGED: the repository's.codenow.yamlcould not be parsed; CodeNOW leaves it as it is and the user adapts it by hand;OTHER_TEMPLATE_FILES: the target template renders further files (otherFiles); they are committed only when included.
Every pipeline effect (PIPELINE_…) and CI setting effect (CI_PROPERTY_…) carrieskey, the dotted.codenow.yamlpath, plus the fields named in its line. Effects outside these two families carry none of the four fields.
Errors (problem+json, parameters.errorId): the same validation as the change — 400 E7011 /
E7001 / E7018 or a property / not-ready rejection, 403, 404 — so a preview tells whether the change would be accepted;
400 E7020 the target template itself cannot be rendered (context: templateId, version,
path; the message names the template, the file and the line). Nothing was changed. Do not retry and do not vary
properties: tell the user.
502 E7014 when the repository is unreachable or the resource's SCM provider / repository cannot be resolved (no partial
preview; retry later, or check the resource's SCM settings if it persists), or when the resource's own path in the repository runs
through a symbolic link (refused; retrying does not help); 502 without errorId when the preview is larger
than the API passes on; 504 when CodeNOW did not answer in time (nothing changed; retry later). A running build or an existing branch
does not block a preview: it never returns 409 (an existing branch shows as outcome.branchExists).
Containers have a single platform template: the id is always container with
custom: false, and the version is any existing one (see /templates/container/versions),
e.g. template.latestVersion from the container detail or list.
Request
Responses
- 200
- 400
- 401
- 403
- 404
- 429
- 500
- 502
- 504
What the change would do; nothing was changed
The change (or its preview) was rejected. Coded rejections carry parameters.errorId and parameters.context (key/value pairs) in the problem+json body:
E7011the template is not valid for this resource type (context:templateId,customTemplate,resourceType);E7001the version does not exist (context:id,version).E7020the target template itself cannot be rendered (context:templateId,version,path; the message names the template, the file and the line). Nothing was changed. Do not retry and do not varyproperties: tell the user.
E7018anincludePathsentry is not offered: not afiles[]path withselectable: true, nor anotherFilespath that can be replaced in the repository (a symbolic link or below one, a repository file at a parent path, a repository directory at the path). Run the preview again and pick again (context:path)..codenow.yamlinincludePathsis ignored, never this error.
Without anerrorId: a template property failed validation (same as on creation), or the resource is not ready.
No valid API key provided.
The caller may not edit the resource.
The resource does not exist (or not under this parent). Nothing was changed.
Too many requests hit the API too quickly. We recommend an exponential backoff of your requests.
Something went wrong on CodeNOW's end.
E7014 the repository's default branch could not be read, or the resource's SCM provider / repository cannot be resolved,
or the resource's own path in the repository runs through a symbolic link (refused; retrying does not help) (context: appComponentId); no partial preview. Retry later, or check the resource's SCM settings if it persists.
Without errorId: the answer is larger than the API passes on; nothing was changed.
CodeNOW did not answer in time; nothing was changed. Retry later.