...
1# Migrating existing third party containers
2
3## Converting from Starlark dictionaries to `third_party_container_dep` rules
4
5All existing third party containers that live in Starlark dictionaries will
6need to be migrated to the new `third_party_container_dep` rules.
7
8To migrate existing dictionaries:
9
101. Take an existing dictionary in an `images.bzl` file like:
11
12 ```python
13 IMAGES = {
14 "alpine-new": {
15 "DIGEST": "sha256:abcdef12345iamarealsha",
16 "REPO": "path/to/alpine",
17 "REGISTRY": "gcr.io",
18 },
19 "ubuntu-new": {
20 "TAG": "v10.0",
21 "DIGEST": "sha256:abcdef12345iamarealsha",
22 "REPO": "path/to/ubuntu",
23 "REGISTRY": "gcr.io",
24 }
25 }
26 ```
27
281. Like in the base documentation, create a new function to wrap the
29dependencies:
30`images.bzl`
31
32 ```python
33 load("//hack/build/rules/container:third_party_images.bzl", "third_party_container_dep")
34
35 def my_images():
36 # deps go here
37 ```
38
391. For each dictionary item, substitute each value into the corresponding
40fields in the `third_party_container_dep` rule:
41**NOTES:**
42
43 - The key of the dictionary (`alpine-new` for example) must have its `-`'s
44 replaced with `_` (`alpine_new`) when moving to the `image_name` field in
45 `third_party_container_dep`. There is a guard in the `third_party_container_dep`
46 rule that will error if not formatted correctly.
47 - Existing references to constants like `MY_REGISTRY` can be used for the
48 corresponding rule value.
49 - Unfortunately, anything besides constants cannot be resolved by the Gazelle
50 plugin, for example `format()` string functions. Feel free to reach out to the
51 foundation team for assistance if needed.
52
53 `images.bzl`
54
55 ```python
56 load("//hack/build/rules/container:third_party_images.bzl", "third_party_container_dep")
57 load("//:constants.bzl", "MY_REGISTRY")
58
59 def my_images():
60 third_party_container_dep(
61 image_name = "alpine_new",
62 digest = "sha256:abcdef12345iamarealsha",
63 repository = "path/to/alpine",
64 registry = "gcr.io",
65 )
66 third_party_container_dep(
67 image_name = "ubuntu_new",
68 tag = "v10.0",
69 digest = "sha256:abcdef12345iamarealsha",
70 repository = "path/to/ubuntu",
71 registry = MY_REGISTRY,
72 )
73 ```
74
751. Once you have replaced the dictionary items with rules, add your new function
76to the `hack/deps/images.bzl` file:
77
78 ```python
79 load("//path/to:my_images.bzl", "my_images")
80
81 def third_party_images():
82 base_images()
83 calico_images()
84 # your new function here
85 my_images()
86 ```
View as plain text