|
3 | 3 |
|
4 | 4 | The `ImagePolicy` type gives rules for selecting a "latest" image from a scanned
|
5 | 5 | `ImageRepository`. This can be used to drive automation, as with the
|
6 |
| -[image-automation-controller][]; or more generally, to inform other processes of the state of an |
| 6 | +[image-automation-controller][]; |
| 7 | +or more generally, to inform other processes of the state of an |
7 | 8 | image repository.
|
8 | 9 |
|
9 | 10 | ## Specification
|
@@ -31,7 +32,6 @@ type ImagePolicySpec struct {
|
31 | 32 | The field `ImageRepositoryRef` names an `ImageRepository` object in the same namespace. It is this
|
32 | 33 | object that provides the scanned image metadata for the policy to use in selecting an image.
|
33 | 34 |
|
34 |
| - |
35 | 35 | ### Policy
|
36 | 36 |
|
37 | 37 | The ImagePolicy field specifies how to choose a latest image given the image metadata. The choice is
|
@@ -94,8 +94,8 @@ type TagFilter struct {
|
94 | 94 | The `FilterTags` field gives you the opportunity to filter the image tags _before_ they are
|
95 | 95 | considered by the policy rule.
|
96 | 96 |
|
97 |
| -The `Pattern` field takes a regular expression which can match anywhere in the tag string. Only tags |
98 |
| -that match the pattern are considered by the policy rule. |
| 97 | +The `Pattern` field takes a [regular expression][regex-go] which can match anywhere in the tag string. |
| 98 | +Only tags that match the pattern are considered by the policy rule. |
99 | 99 |
|
100 | 100 | The optional `Extract` value will be expanded for each tag that matches the pattern. The resulting
|
101 | 101 | values will be supplied to the policy rule instead of the original tags. If `Extract` is empty, then
|
@@ -124,5 +124,77 @@ The `LatestImage` field contains the image selected by the policy rule, when it
|
124 | 124 | There is one condition that may be present: the GitOps toolkit-standard `ReadyCondition`. This will
|
125 | 125 | be marked as true when the policy rule has selected an image.
|
126 | 126 |
|
| 127 | +## Examples |
| 128 | + |
| 129 | +Select the latest `dev` branch build tagged as `<BRANCH>-<BUILD-ID>` (alphabetical): |
| 130 | + |
| 131 | +```yaml |
| 132 | +kind: ImagePolicy |
| 133 | +spec: |
| 134 | + filterTags: |
| 135 | + pattern: '^dev-(?P<id>.*)' |
| 136 | + extract: '$id' |
| 137 | + policy: |
| 138 | + alphabetical: |
| 139 | + order: asc |
| 140 | +``` |
| 141 | +
|
| 142 | +Select the latest stable version (semver): |
| 143 | +
|
| 144 | +```yaml |
| 145 | +kind: ImagePolicy |
| 146 | +spec: |
| 147 | + policy: |
| 148 | + semver: |
| 149 | + range: '>=1.0.0' |
| 150 | +``` |
| 151 | +
|
| 152 | +Select the latest stable patch version in the 1.x range (semver): |
| 153 | +
|
| 154 | +```yaml |
| 155 | +kind: ImagePolicy |
| 156 | +spec: |
| 157 | + policy: |
| 158 | + semver: |
| 159 | + range: '>=1.0.0 <2.0.0' |
| 160 | +``` |
| 161 | +
|
| 162 | +Select the latest version including pre-releases (semver): |
| 163 | +
|
| 164 | +```yaml |
| 165 | +kind: ImagePolicy |
| 166 | +spec: |
| 167 | + policy: |
| 168 | + semver: |
| 169 | + range: '>=1.0.0-0' |
| 170 | +``` |
| 171 | +
|
| 172 | +Select the latest release candidate (semver): |
| 173 | +
|
| 174 | +```yaml |
| 175 | +kind: ImagePolicy |
| 176 | +spec: |
| 177 | + filterTags: |
| 178 | + pattern: '.*-rc.*' |
| 179 | + policy: |
| 180 | + semver: |
| 181 | + range: '^1.x-0' |
| 182 | +``` |
| 183 | +
|
| 184 | +Select the latest release tagged as `RELEASE.<RFC3339-TIMESTAMP>` |
| 185 | +e.g. [Minio](https://hub.docker.com/r/minio/minio) (alphabetical): |
| 186 | + |
| 187 | +```yaml |
| 188 | +kind: ImagePolicy |
| 189 | +spec: |
| 190 | + filterTags: |
| 191 | + pattern: '^RELEASE\.(?P<timestamp>.*)Z$' |
| 192 | + extract: '$timestamp' |
| 193 | + policy: |
| 194 | + alphabetical: |
| 195 | + order: asc |
| 196 | +``` |
| 197 | + |
127 | 198 | [image-automation-controller]: https://github.com/image-automation-controller
|
128 | 199 | [semver-range]: https://github.com/Masterminds/semver#checking-version-constraints
|
| 200 | +[regex-go]: https://golang.org/pkg/regexp/syntax |
0 commit comments