Skip to content

Commit 65ff6be

Browse files
authored
Fix ci docker update (#4805)
* update docker and helm update task with new pattern + add exception for CI
1 parent be1ae13 commit 65ff6be

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

tasks/dev.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939

4040
NAMESPACE = Namespace.DEV
4141

42+
VERSION_PATTERN_DOCKER = (
43+
r"\$\{INFRAHUB_DOCKER_IMAGE:-registry\.opsmill\.io/opsmill/infrahub\}:\$\{VERSION:-[\d\.\-a-zA-Z]+\}"
44+
)
45+
VERSION_PATTERN_HELM = r'^appVersion:\s*("?)([\d\.\-a-zA-Z]+)\1$'
46+
4247

4348
@task(optional=["database"])
4449
def build(
@@ -194,34 +199,39 @@ def get_version_from_pyproject() -> str:
194199
def update_helm_chart(context: Context, chart_file: str | None = "helm/Chart.yaml") -> None:
195200
"""Update helm/Chart.yaml with the current version from pyproject.toml."""
196201
version = get_version_from_pyproject()
197-
version_pattern = r"^appVersion:\s*[\d\.\-a-zA-Z]+"
202+
version_pattern = VERSION_PATTERN_HELM
198203

199-
def replace_version(match: str) -> str:
200-
return f"appVersion: {version}"
204+
def replace_version(match: re.Match) -> str:
205+
return f'appVersion: "{version}"'
201206

202207
chart_path = Path(chart_file)
203208
chart_yaml = chart_path.read_text(encoding="utf-8")
209+
updated_chart_yaml, count = re.subn(version_pattern, replace_version, chart_yaml, flags=re.MULTILINE)
204210

205-
updated_chart_yaml = re.sub(version_pattern, replace_version, chart_yaml, flags=re.MULTILINE)
206-
chart_path.write_text(updated_chart_yaml, encoding="utf-8")
211+
if count == 0:
212+
raise ValueError(f"Pattern not found in {chart_file}; no updates made.")
207213

214+
chart_path.write_text(updated_chart_yaml, encoding="utf-8")
208215
print(f"{chart_file} updated with appVersion {version}")
209216

210217

211218
@task
212219
def update_docker_compose(context: Context, docker_file: str | None = "docker-compose.yml") -> None:
213220
"""Update docker-compose.yml with the current version from pyproject.toml."""
214221
version = get_version_from_pyproject()
215-
version_pattern = r"registry.opsmill.io/opsmill/infrahub:\$\{VERSION:-[\d\.\-a-zA-Z]+\}"
222+
version_pattern = VERSION_PATTERN_DOCKER
216223

217224
def replace_version(match: str) -> str:
218-
return f"registry.opsmill.io/opsmill/infrahub:${{VERSION:-{version}}}"
225+
return f"${{INFRAHUB_DOCKER_IMAGE:-registry.opsmill.io/opsmill/infrahub}}:${{VERSION:-{version}}}"
219226

220227
docker_path = Path(docker_file)
221228
docker_compose = docker_path.read_text(encoding="utf-8")
222-
updated_docker_compose = re.sub(version_pattern, replace_version, docker_compose)
223-
docker_path.write_text(updated_docker_compose, encoding="utf-8")
229+
updated_docker_compose, count = re.subn(version_pattern, replace_version, docker_compose)
224230

231+
if count == 0:
232+
raise ValueError(f"Pattern not found in {docker_file}; no updates made.")
233+
234+
docker_path.write_text(updated_docker_compose, encoding="utf-8")
225235
print(f"{docker_file} updated with version {version}")
226236

227237

0 commit comments

Comments
 (0)