Instructions for modifying Dockerfile templates
All Dockerfiles and Readmes are generated from Cottle templates in
the eng/dockerfile-templates and eng/readme-templates directories respectively.
Cottle syntax
Templating
All text is plain text by default. Text inside double curly braces {{ }} is template code.
Writing just {{value}} emits the evaluated value.
You can also have expressions inside template blocks which do more complicated logic.
Template code can have multiple lines in it, separated by the line ending ^ character.
The final line in a template block should not use the line ending character.
Comments inside a template block start with _ and follow the same line ending rules.
Comments can span multiple lines.
Template data sources
VARIABLES: Variables from manifest.versions.json. Access with VARIABLES["name"].
ARGS: Passed into template via InsertTemplate(...) function. Access with ARGS["name"]
Common functions
- Assign value:
set name to <expression>.
- Assign function
set func(arg1, arg2) to:{{ ... }} defines an inline function; use return <expr> inside.
- String functions:
cat(a, b, ...)
join(list, sep)
split(str, sep)
slice(list, start, end).
- Collections:
len(list),
find(haystack, needle) returns index or -1.
- Ternary expression:
when(condition, valueIfTrue, valueIfFalse).
Conditionals
Boolean expressions:
- Operators:
=, !=, >, <, >=, <=, logical &&, ||, and negation !.
- Equality uses single
= inside expressions (context-specific to Cottle) rather than ==.
If statement:
{{if condition:VALUE}}
Compound conditionals:
{{if ((condition1 && condition2) || condition3):VALUE}}
Multiple conditions:
{{if condition1:VALUE1^
elif condition2:VALUE2^
else:VALUE3}}
After the colon :, all whitespace is treated as literal until the next line ending character ^.
You can also nest template blocks:
{{if condition1:{{if condition2:VALUE}}}}
1---2name: dockerfile-and-readme-templating3description: Modify Cottle templates that generate Dockerfiles and READMEs in dotnet/dotnet-docker.4---56# Instructions for modifying Dockerfile templates78All Dockerfiles and Readmes are generated from [Cottle](https://github.com/r3c/cottle) templates in9the `eng/dockerfile-templates` and `eng/readme-templates` directories respectively.1011## Cottle syntax1213### Templating1415All text is plain text by default. Text inside double curly braces `{{ }}` is template code.16Writing just `{{value}}` emits the evaluated value.17You can also have expressions inside template blocks which do more complicated logic.18Template code can have multiple lines in it, separated by the line ending `^` character.19The final line in a template block should not use the line ending character.20Comments inside a template block start with `_` and follow the same line ending rules.21Comments can span multiple lines.2223### Template data sources2425- `VARIABLES`: Variables from `manifest.versions.json`. Access with `VARIABLES["name"]`.26- `ARGS`: Passed into template via `InsertTemplate(...)` function. Access with `ARGS["name"]`2728### Common functions2930- Assign value: `set name to <expression>`.31- Assign function `set func(arg1, arg2) to:{{ ... }}` defines an inline function; use `return <expr>` inside.32- String functions:33 - `cat(a, b, ...)`34 - `join(list, sep)`35 - `split(str, sep)`36 - `slice(list, start, end)`.37- Collections:38 - `len(list)`,39 - `find(haystack, needle)` returns index or -1.40- Ternary expression: `when(condition, valueIfTrue, valueIfFalse)`.4142### Conditionals4344Boolean expressions:4546- Operators: `=`, `!=`, `>`, `<`, `>=`, `<=`, logical `&&`, `||`, and negation `!`.47- Equality uses single `=` inside expressions (context-specific to Cottle) rather than `==`.4849If statement:5051```cottle52{{if condition:VALUE}}53```5455Compound conditionals:5657```cottle58{{if ((condition1 && condition2) || condition3):VALUE}}59```6061Multiple conditions:6263```cottle64{{if condition1:VALUE1^65elif condition2:VALUE2^66else:VALUE3}}67```6869After the colon `:`, all whitespace is treated as literal until the next line ending character `^`.7071You can also nest template blocks:7273```cottle74{{if condition1:{{if condition2:VALUE}}}}75```