Skip to content

Commit d49f3cb

Browse files
authored
Support for rules_oci 2.x (#40)
1 parent 7c0d44a commit d49f3cb

File tree

4 files changed

+58
-34
lines changed

4 files changed

+58
-34
lines changed

gitops/extensions.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ TODO: implement a proper toolchain resolution mechanism in bzlmod
66
load("//gitops/private:extension_utils.bzl", "extension_utils")
77
load("//gitops/private:host_repo.bzl", "host_repo")
88
load(
9-
":repositories.bzl",
9+
":toolchains.bzl",
1010
"DEFAULT_KUSTOMIZE_REPOSITORY",
1111
"DEFAULT_KUSTOMIZE_VERSION",
1212
"register_kustomize_toolchains",

gitops/repositories.bzl

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@ GtiOps rules repositories initialization
1515
load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies", "aspect_bazel_lib_register_toolchains")
1616
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
1717
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
18-
load("@rules_gitops//skylib/kustomize:kustomize.bzl", "download_kustomize", "kustomize_setup")
18+
load("@rules_gitops//skylib/kustomize:kustomize.bzl", "kustomize_setup")
1919
load("@rules_oci//oci:dependencies.bzl", "rules_oci_dependencies")
2020
load("@rules_oci//oci:repositories.bzl", "LATEST_CRANE_VERSION", "oci_register_toolchains")
2121
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
22-
load("//gitops/private:kustomize_toolchain.bzl", "KUSTOMIZE_PLATFORMS", "kustomize_host_alias_repo", "kustomize_platform_repo", "kustomize_toolchains_repo", _DEFAULT_KUSTOMIZE_VERSION = "DEFAULT_KUSTOMIZE_VERSION")
23-
24-
DEFAULT_KUSTOMIZE_VERSION = _DEFAULT_KUSTOMIZE_VERSION
22+
load(
23+
":toolchains.bzl",
24+
_register_kustomize_toolchains = "register_kustomize_toolchains",
25+
_DEFAULT_KUSTOMIZE_REPOSITORY = "DEFAULT_KUSTOMIZE_REPOSITORY",
26+
_DEFAULT_KUSTOMIZE_VERSION = "DEFAULT_KUSTOMIZE_VERSION",
27+
)
2528

2629
def rules_gitops_repositories():
2730
"""Initializes Declares workspaces the GitOps rules depend on.
@@ -43,31 +46,7 @@ def rules_gitops_repositories():
4346
crane_version = LATEST_CRANE_VERSION,
4447
)
4548

46-
DEFAULT_KUSTOMIZE_REPOSITORY = "kustomize"
47-
48-
def register_kustomize_toolchains(name = DEFAULT_KUSTOMIZE_REPOSITORY, version = DEFAULT_KUSTOMIZE_VERSION, register = True):
49-
"""Registers kustomize toolchain and repositories
50-
51-
Args:
52-
name: override the prefix for the generated toolchain repositories
53-
version: the version of kustomize to execute (see https://github.com/kubernetes-sigs/kustomize/releases)
54-
register: whether to call through to native.register_toolchains.
55-
Should be True for WORKSPACE users, but false when used under bzlmod extension
56-
"""
57-
58-
download_kustomize(name = "kustomize_bin")
59-
for [platform, meta] in KUSTOMIZE_PLATFORMS.items():
60-
kustomize_platform_repo(
61-
name = "%s_%s" % (name, platform),
62-
platform = platform,
63-
version = version,
64-
)
65-
if register:
66-
native.register_toolchains("@%s_toolchains//:%s_toolchain" % (name, platform))
67-
68-
kustomize_host_alias_repo(name = name)
69-
70-
kustomize_toolchains_repo(
71-
name = "%s_toolchains" % name,
72-
user_repository_name = name,
73-
)
49+
# Re-host for backwards compatiblity
50+
register_kustomize_toolchains = _register_kustomize_toolchains
51+
DEFAULT_KUSTOMIZE_REPOSITORY = _DEFAULT_KUSTOMIZE_REPOSITORY
52+
DEFAULT_KUSTOMIZE_VERSION = _DEFAULT_KUSTOMIZE_VERSION

gitops/toolchains.bzl

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright 2020 Adobe. All rights reserved.
2+
# This file is licensed to you under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License. You may obtain a copy
4+
# of the License at http://www.apache.org/licenses/LICENSE-2.0
5+
6+
# Unless required by applicable law or agreed to in writing, software distributed under
7+
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
8+
# OF ANY KIND, either express or implied. See the License for the specific language
9+
# governing permissions and limitations under the License.
10+
11+
"""
12+
Toolchain registration macros.
13+
"""
14+
load("//skylib/kustomize:kustomize.bzl", "download_kustomize")
15+
load("//gitops/private:kustomize_toolchain.bzl", "KUSTOMIZE_PLATFORMS", "kustomize_host_alias_repo", "kustomize_platform_repo", "kustomize_toolchains_repo", _DEFAULT_KUSTOMIZE_VERSION = "DEFAULT_KUSTOMIZE_VERSION")
16+
17+
DEFAULT_KUSTOMIZE_VERSION = _DEFAULT_KUSTOMIZE_VERSION
18+
DEFAULT_KUSTOMIZE_REPOSITORY = "kustomize"
19+
20+
def register_kustomize_toolchains(name = DEFAULT_KUSTOMIZE_REPOSITORY, version = DEFAULT_KUSTOMIZE_VERSION, register = True):
21+
"""Registers kustomize toolchain and repositories
22+
23+
Args:
24+
name: override the prefix for the generated toolchain repositories
25+
version: the version of kustomize to execute (see https://github.com/kubernetes-sigs/kustomize/releases)
26+
register: whether to call through to native.register_toolchains.
27+
Should be True for WORKSPACE users, but false when used under bzlmod extension
28+
"""
29+
30+
download_kustomize(name = "kustomize_bin")
31+
for [platform, meta] in KUSTOMIZE_PLATFORMS.items():
32+
kustomize_platform_repo(
33+
name = "%s_%s" % (name, platform),
34+
platform = platform,
35+
version = version,
36+
)
37+
if register:
38+
native.register_toolchains("@%s_toolchains//:%s_toolchain" % (name, platform))
39+
40+
kustomize_host_alias_repo(name = name)
41+
42+
kustomize_toolchains_repo(
43+
name = "%s_toolchains" % name,
44+
user_repository_name = name,
45+
)

push_oci/push_oci.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ push_oci_rule = rule(
9595
default = Label("//push_oci:tag.sh.tpl"),
9696
allow_single_file = True,
9797
)},
98-
toolchains = oci_push_lib.toolchains,
98+
toolchains = ["@aspect_bazel_lib//lib:yq_toolchain_type"] + oci_push_lib.toolchains,
9999
executable = True,
100100
# provides = [GitopsPushInfo, DefaultInfo],
101101
)

0 commit comments

Comments
 (0)