Skip to content

Commit af9674a

Browse files
authored
CLOUDP-83092: Add release task for init containers (#433)
1 parent 56a8d85 commit af9674a

File tree

5 files changed

+110
-15
lines changed

5 files changed

+110
-15
lines changed

.evergreen.yml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ functions:
120120
- quay_user_name
121121
- quay_password
122122
- image_name
123+
- release
123124
working_dir: mongodb-kubernetes-operator
124125
binary: scripts/ci/build_and_push_image_sonar.sh
125126

@@ -345,15 +346,25 @@ tasks:
345346
new_image: quay.io/mongodb/mongodb-kubernetes-operator
346347
image_type: mongodb-kubernetes-operator
347348

348-
- name: release_version_upgrade_hook
349+
350+
- name: release_version_upgrade_post_start_hook
349351
commands:
350352
- func: clone
351353
- func: setup_virtualenv
352-
- func: release_docker_image
354+
- func: build_and_push_image_sonar
355+
vars:
356+
image_type: version-post-start-hook-init
357+
release: true
358+
359+
360+
- name: release_readiness_probe
361+
commands:
362+
- func: clone
363+
- func: setup_virtualenv
364+
- func: build_and_push_image_sonar
353365
vars:
354-
old_image: quay.io/mongodb/community-operator-version-upgrade-post-start-hook
355-
new_image: quay.io/mongodb/mongodb-kubernetes-operator-version-upgrade-post-start-hook
356-
image_type: version-upgrade-hook
366+
image_type: readiness-probe-init
367+
release: true
357368

358369

359370
buildvariants:
@@ -433,4 +444,5 @@ buildvariants:
433444
- ubuntu1604-test
434445
tasks:
435446
- name: release_operator
436-
- name: release_version_upgrade_hook
447+
- name: release_version_upgrade_post_start_hook
448+
- name: release_readiness_probe

inventory.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ images:
1111
- name: agent-template-ubuntu
1212
task_type: dockerfile_template
1313
distro: ubuntu
14+
tags: ["ubuntu"]
1415

1516
inputs:
1617
- agent_version
@@ -24,6 +25,7 @@ images:
2425
- name: agent-ubuntu-build
2526
task_type: docker_build
2627
dockerfile: scripts/dev/templates/agent/Dockerfile.ubuntu-$(inputs.params.version_id)
28+
tags: ["ubuntu"]
2729

2830
labels:
2931
quay.expires-after: 48h
@@ -42,6 +44,7 @@ images:
4244
- name: agent-template-ubi
4345
task_type: dockerfile_template
4446
distro: ubi
47+
tags: ["ubi"]
4548

4649
inputs:
4750
- agent_version
@@ -56,6 +59,7 @@ images:
5659
- name: agent-ubi-build
5760
task_type: docker_build
5861
dockerfile: scripts/dev/templates/agent/Dockerfile.ubi-$(inputs.params.version_id)
62+
tags: ["ubi"]
5963

6064
labels:
6165
quay.expires-after: 48h
@@ -73,6 +77,7 @@ images:
7377
- name: readiness-probe-init-build
7478
task_type: docker_build
7579
dockerfile: scripts/dev/dockerfiles/Dockerfile.readiness
80+
tags: ["readiness-probe"]
7681

7782
labels:
7883
quay.expires-after: 48h
@@ -81,6 +86,22 @@ images:
8186
- registry: $(inputs.params.registry)/mongodb-kubernetes-readinessprobe-dev
8287
tag: $(inputs.params.version_id)
8388

89+
- name: readiness-probe-init-release
90+
task_type: tag_image
91+
tags: ["release", "readiness-probe"]
92+
93+
inputs:
94+
- release_version
95+
96+
source:
97+
registry: $(inputs.params.registry)/mongodb-kubernetes-readinessprobe-dev
98+
tag: $(inputs.params.version_id)
99+
100+
destination:
101+
- registry: $(inputs.params.registry)/mongodb-kubernetes-readinessprobe
102+
tag: $(inputs.params.release_version)
103+
104+
84105
- name: version-post-start-hook-init
85106
vars:
86107
context: .
@@ -89,10 +110,26 @@ images:
89110
- name: version-post-start-hook-init-build
90111
task_type: docker_build
91112
dockerfile: scripts/dev/dockerfiles/Dockerfile.versionhook
113+
tags: ["post-start-hook"]
92114

93115
labels:
94116
quay.expires-after: 48h
95117

96118
output:
97119
- registry: $(inputs.params.registry)/mongodb-kubernetes-operator-version-upgrade-post-start-hook-dev
98120
tag: $(inputs.params.version_id)
121+
122+
- name: version-post-start-hook-init-build-release
123+
task_type: tag_image
124+
tags: ["release", "post-start-hook"]
125+
126+
inputs:
127+
- release_version
128+
129+
source:
130+
registry: $(inputs.params.registry)/mongodb-kubernetes-operator-version-upgrade-post-start-hook-dev
131+
tag: $(inputs.params.version_id)
132+
133+
destination:
134+
- registry: $(inputs.params.registry)/mongodb-kubernetes-operator-version-upgrade-post-start-hook
135+
tag: $(inputs.params.release_version)

pipeline.py

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,16 @@ def build_agent_image_ubi(config: DevConfig) -> None:
2727
args = {
2828
"agent_version": release["agent"]["version"],
2929
"tools_version": release["agent"]["tools_version"],
30-
"tools_distro": "ubuntu1604-x86_64",
31-
"agent_distro": "linux_x86_64",
30+
"tools_distro": "rhel70-x86_64",
31+
"agent_distro": "rhel7_x86_64",
3232
"registry": config.repo_url,
3333
}
34+
35+
config.ensure_tag_is_run("ubi")
36+
3437
sonar_build_image(
3538
image_name,
39+
config,
3640
args=args,
3741
)
3842

@@ -44,36 +48,55 @@ def build_agent_image_ubuntu(config: DevConfig) -> None:
4448
args = {
4549
"agent_version": release["agent"]["version"],
4650
"tools_version": release["agent"]["tools_version"],
47-
"tools_distro": "rhel70-x86_64",
48-
"agent_distro": "rhel7_x86_64",
51+
"tools_distro": "ubuntu1604-x86_64",
52+
"agent_distro": "linux_x86_64",
4953
"registry": config.repo_url,
5054
}
55+
56+
config.ensure_tag_is_run("ubuntu")
57+
5158
sonar_build_image(
5259
image_name,
60+
config,
5361
args=args,
5462
)
5563

5664

5765
def build_readiness_probe_image(config: DevConfig) -> None:
66+
with open("release.json") as f:
67+
release = json.loads(f.read())
68+
69+
config.ensure_tag_is_run("readiness-probe")
70+
5871
sonar_build_image(
5972
"readiness-probe-init",
73+
config,
6074
args={
6175
"registry": config.repo_url,
76+
"release_version": release["readiness-probe"],
6277
},
6378
)
6479

6580

6681
def build_version_post_start_hook_image(config: DevConfig) -> None:
82+
with open("release.json") as f:
83+
release = json.loads(f.read())
84+
85+
config.ensure_tag_is_run("post-start-hook")
86+
6787
sonar_build_image(
6888
"version-post-start-hook-init",
89+
config,
6990
args={
7091
"registry": config.repo_url,
92+
"release_version": release["version-upgrade-hook"],
7193
},
7294
)
7395

7496

7597
def sonar_build_image(
7698
image_name: str,
99+
config: DevConfig,
77100
args: Optional[Dict[str, str]] = None,
78101
inventory: str = "inventory.yaml",
79102
) -> None:
@@ -82,14 +105,15 @@ def sonar_build_image(
82105
image_name,
83106
build_args=args,
84107
inventory=inventory,
85-
include_tags=[],
86-
skip_tags=[],
108+
include_tags=config.include_tags,
109+
skip_tags=config.skip_tags,
87110
)
88111

89112

90113
def _parse_args() -> argparse.Namespace:
91114
parser = argparse.ArgumentParser()
92115
parser.add_argument("--image-name", type=str)
116+
parser.add_argument("--release", type=bool)
93117
return parser.parse_args()
94118

95119

@@ -103,14 +127,24 @@ def main() -> int:
103127
)
104128
return 1
105129

130+
config = load_config()
131+
132+
# by default we do not want to run any release tasks. We must explicitly
133+
# use the --release flag to run them.
134+
config.ensure_skip_tag("release")
135+
136+
# specify --release to release the image
137+
if args.release:
138+
config.ensure_tag_is_run("release")
139+
106140
image_build_function = {
107141
"agent-ubi": build_agent_image_ubi,
108142
"agent-ubuntu": build_agent_image_ubuntu,
109143
"readiness-probe-init": build_readiness_probe_image,
110144
"version-post-start-hook-init": build_version_post_start_hook_image,
111145
}[image_name]
112146

113-
image_build_function(load_config())
147+
image_build_function(config)
114148
return 0
115149

116150

scripts/ci/build_and_push_image_sonar.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ set +x
77
echo "${quay_password:?}" | docker login "-u=${quay_user_name:?}" quay.io --password-stdin
88

99
# shellcheck disable=SC2154
10-
python3 pipeline.py --image-name "${image_name}"
10+
python3 pipeline.py --image-name "${image_name}" --release "${release:-false}"

scripts/dev/dev_config.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from __future__ import annotations
2-
from typing import Dict, Optional
2+
from typing import Dict, Optional, List
33
from enum import Enum
44
import json
55
import os
@@ -33,6 +33,14 @@ class DevConfig:
3333
def __init__(self, config: Dict, distro: Distro):
3434
self._config = config
3535
self._distro = distro
36+
self.include_tags: List[str] = []
37+
self.skip_tags: List[str] = []
38+
39+
def ensure_tag_is_run(self, tag: str) -> None:
40+
if tag not in self.include_tags:
41+
self.include_tags.append(tag)
42+
if tag in self.skip_tags:
43+
self.skip_tags.remove(tag)
3644

3745
@property
3846
def namespace(self) -> str:
@@ -64,6 +72,10 @@ def agent_image(self) -> str:
6472
return self._config["agent_image_ubi"]
6573
return self._config["agent_image_ubuntu"]
6674

75+
def ensure_skip_tag(self, tag: str) -> None:
76+
if tag not in self.skip_tags:
77+
self.skip_tags.append(tag)
78+
6779

6880
def load_config(
6981
config_file_path: Optional[str] = None, distro: Distro = Distro.UBUNTU

0 commit comments

Comments
 (0)