-
-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add an example for custom registry (#71)
Co-authored-by: Alex Eagle <[email protected]>
- Loading branch information
Showing
14 changed files
with
497 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
e2e |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
load("@bazel_gazelle//:def.bzl", "gazelle", "gazelle_binary") | ||
|
||
gazelle_binary( | ||
name = "gazelle_bin", | ||
languages = [ | ||
"@bazel_gazelle//language/go", | ||
], | ||
) | ||
|
||
# gazelle:prefix example.com/custom_registry | ||
gazelle( | ||
name = "gazelle", | ||
gazelle = "gazelle_bin", | ||
) | ||
|
||
gazelle( | ||
name = "update-repos", | ||
args = [ | ||
"-from_file=go.mod", | ||
"-to_macro=deps.bzl%go_dependencies", | ||
"-prune", | ||
], | ||
command = "update-repos", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Using rules_oci with a custom registry implementation. | ||
|
||
rules_oci uses `crane` to build container images which needs to talk to a registry in order to perform operations. for this reason rules_oci | ||
runs a local registry instance with each action and performs operation within that registry. by default this is done by using | ||
[zot](https://github.com/project-zot/zot) which only supports oci media types. this becomes a problem if other image formats are used such as `docker v2` and `docker v1` | ||
|
||
This example demonstrates usage of an alternative registry implementation that allows both `oci` and `docker` specs, allowing seamless usage of docker images. | ||
Since there's no prebuilt binaries available for go-containerregistrys registry implementation, it has to be built using rules_go and a small main script. | ||
|
||
## references | ||
|
||
https://github.com/project-zot/zot/issues/724 | ||
https://github.com/google/go-containerregistry/issues/1579 | ||
https://github.com/distribution/distribution/issues/3714 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
||
local_repository( | ||
name = "contrib_rules_oci", | ||
path = "../../", | ||
) | ||
|
||
load("@contrib_rules_oci//oci:dependencies.bzl", "rules_oci_dependencies") | ||
|
||
# Fetch our "runtime" dependencies which users need as well | ||
rules_oci_dependencies() | ||
|
||
load("@contrib_rules_oci//oci:repositories.bzl", "LATEST_CRANE_VERSION", "LATEST_ZOT_VERSION", "oci_register_toolchains") | ||
|
||
# A registry that accepts both Docker and OCI media types. | ||
register_toolchains("//registry:registry_toolchain") | ||
|
||
oci_register_toolchains( | ||
name = "oci", | ||
crane_version = LATEST_CRANE_VERSION, | ||
zot_version = LATEST_ZOT_VERSION, | ||
) | ||
|
||
############################################ | ||
# Gazelle and Go | ||
|
||
http_archive( | ||
name = "io_bazel_rules_go", | ||
sha256 = "099a9fb96a376ccbbb7d291ed4ecbdfd42f6bc822ab77ae6f1b5cb9e914e94fa", | ||
urls = [ | ||
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip", | ||
"https://github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip", | ||
], | ||
) | ||
|
||
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") | ||
|
||
go_rules_dependencies() | ||
|
||
go_register_toolchains(version = "1.17.2") | ||
|
||
http_archive( | ||
name = "bazel_gazelle", | ||
sha256 = "de69a09dc70417580aabf20a28619bb3ef60d038470c7cf8442fafcf627c21cb", | ||
urls = [ | ||
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.24.0/bazel-gazelle-v0.24.0.tar.gz", | ||
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.24.0/bazel-gazelle-v0.24.0.tar.gz", | ||
], | ||
) | ||
|
||
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") | ||
load("//:deps.bzl", "go_dependencies") | ||
|
||
# gazelle:repository_macro deps.bzl%go_dependencies | ||
go_dependencies() | ||
|
||
gazelle_dependencies() | ||
|
||
# Rules pkg | ||
http_archive( | ||
name = "rules_pkg", | ||
sha256 = "451e08a4d78988c06fa3f9306ec813b836b1d076d0f055595444ba4ff22b867f", | ||
urls = [ | ||
"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.7.1/rules_pkg-0.7.1.tar.gz", | ||
"https://github.com/bazelbuild/rules_pkg/releases/download/0.7.1/rules_pkg-0.7.1.tar.gz", | ||
], | ||
) | ||
|
||
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") | ||
|
||
rules_pkg_dependencies() | ||
|
||
load("@contrib_rules_oci//oci:pull.bzl", "oci_pull") | ||
|
||
oci_pull( | ||
name = "distroless_static", | ||
digest = "sha256:c3c3d0230d487c0ad3a0d87ad03ee02ea2ff0b3dcce91ca06a1019e07de05f12", | ||
image = "gcr.io/distroless/static", | ||
platforms = [ | ||
"linux/amd64", | ||
"linux/arm64", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,243 @@ | ||
load("@bazel_gazelle//:deps.bzl", "go_repository") | ||
|
||
def go_dependencies(): | ||
go_repository( | ||
name = "com_github_azure_go_ansiterm", | ||
importpath = "github.com/Azure/go-ansiterm", | ||
sum = "h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=", | ||
version = "v0.0.0-20210617225240-d185dfc1b5a1", | ||
) | ||
go_repository( | ||
name = "com_github_containerd_stargz_snapshotter_estargz", | ||
importpath = "github.com/containerd/stargz-snapshotter/estargz", | ||
sum = "h1:+7nYmHJb0tEkcRaAW+MHqoKaJYZmkikupxCqVtmPuY0=", | ||
version = "v0.12.1", | ||
) | ||
go_repository( | ||
name = "com_github_cpuguy83_go_md2man_v2", | ||
importpath = "github.com/cpuguy83/go-md2man/v2", | ||
sum = "h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=", | ||
version = "v2.0.2", | ||
) | ||
go_repository( | ||
name = "com_github_docker_cli", | ||
importpath = "github.com/docker/cli", | ||
sum = "h1:lWQbHSHUFs7KraSN2jOJK7zbMS2jNCHI4mt4xUFUVQ4=", | ||
version = "v20.10.20+incompatible", | ||
) | ||
go_repository( | ||
name = "com_github_docker_distribution", | ||
importpath = "github.com/docker/distribution", | ||
sum = "h1:Q50tZOPR6T/hjNsyc9g8/syEs6bk8XXApsHjKukMl68=", | ||
version = "v2.8.1+incompatible", | ||
) | ||
go_repository( | ||
name = "com_github_docker_docker", | ||
importpath = "github.com/docker/docker", | ||
sum = "h1:kH9tx6XO+359d+iAkumyKDc5Q1kOwPuAUaeri48nD6E=", | ||
version = "v20.10.20+incompatible", | ||
) | ||
go_repository( | ||
name = "com_github_docker_docker_credential_helpers", | ||
importpath = "github.com/docker/docker-credential-helpers", | ||
sum = "h1:xtCHsjxogADNZcdv1pKUHXryefjlVRqWqIhk/uXJp0A=", | ||
version = "v0.7.0", | ||
) | ||
go_repository( | ||
name = "com_github_docker_go_connections", | ||
importpath = "github.com/docker/go-connections", | ||
sum = "h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ=", | ||
version = "v0.4.0", | ||
) | ||
go_repository( | ||
name = "com_github_docker_go_units", | ||
importpath = "github.com/docker/go-units", | ||
sum = "h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=", | ||
version = "v0.5.0", | ||
) | ||
go_repository( | ||
name = "com_github_gogo_protobuf", | ||
importpath = "github.com/gogo/protobuf", | ||
sum = "h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=", | ||
version = "v1.3.2", | ||
) | ||
go_repository( | ||
name = "com_github_golang_protobuf", | ||
importpath = "github.com/golang/protobuf", | ||
sum = "h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=", | ||
version = "v1.5.2", | ||
) | ||
go_repository( | ||
name = "com_github_google_go_cmp", | ||
importpath = "github.com/google/go-cmp", | ||
sum = "h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=", | ||
version = "v0.5.9", | ||
) | ||
go_repository( | ||
name = "com_github_google_go_containerregistry", | ||
importpath = "github.com/google/go-containerregistry", | ||
sum = "h1:y1C7Z3e149OJbOPDBxLYR8ITPz8dTKqQwjErKVHJC8k=", | ||
version = "v0.13.0", | ||
) | ||
go_repository( | ||
name = "com_github_inconshreveable_mousetrap", | ||
importpath = "github.com/inconshreveable/mousetrap", | ||
sum = "h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc=", | ||
version = "v1.0.1", | ||
) | ||
go_repository( | ||
name = "com_github_klauspost_compress", | ||
importpath = "github.com/klauspost/compress", | ||
sum = "h1:Lcadnb3RKGin4FYM/orgq0qde+nc15E5Cbqg4B9Sx9c=", | ||
version = "v1.15.11", | ||
) | ||
go_repository( | ||
name = "com_github_microsoft_go_winio", | ||
importpath = "github.com/Microsoft/go-winio", | ||
sum = "h1:slsWYD/zyx7lCXoZVlvQrj0hPTM1HI4+v1sIda2yDvg=", | ||
version = "v0.6.0", | ||
) | ||
go_repository( | ||
name = "com_github_mitchellh_go_homedir", | ||
importpath = "github.com/mitchellh/go-homedir", | ||
sum = "h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=", | ||
version = "v1.1.0", | ||
) | ||
go_repository( | ||
name = "com_github_moby_term", | ||
importpath = "github.com/moby/term", | ||
sum = "h1:yH0SvLzcbZxcJXho2yh7CqdENGMQe73Cw3woZBpPli0=", | ||
version = "v0.0.0-20210610120745-9d4ed1856297", | ||
) | ||
go_repository( | ||
name = "com_github_morikuni_aec", | ||
importpath = "github.com/morikuni/aec", | ||
sum = "h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=", | ||
version = "v1.0.0", | ||
) | ||
go_repository( | ||
name = "com_github_opencontainers_go_digest", | ||
importpath = "github.com/opencontainers/go-digest", | ||
sum = "h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=", | ||
version = "v1.0.0", | ||
) | ||
go_repository( | ||
name = "com_github_opencontainers_image_spec", | ||
importpath = "github.com/opencontainers/image-spec", | ||
sum = "h1:2zx/Stx4Wc5pIPDvIxHXvXtQFW/7XWJGmnM7r3wg034=", | ||
version = "v1.1.0-rc2", | ||
) | ||
go_repository( | ||
name = "com_github_pkg_errors", | ||
importpath = "github.com/pkg/errors", | ||
sum = "h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=", | ||
version = "v0.9.1", | ||
) | ||
go_repository( | ||
name = "com_github_russross_blackfriday_v2", | ||
importpath = "github.com/russross/blackfriday/v2", | ||
sum = "h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=", | ||
version = "v2.1.0", | ||
) | ||
go_repository( | ||
name = "com_github_sirupsen_logrus", | ||
importpath = "github.com/sirupsen/logrus", | ||
sum = "h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=", | ||
version = "v1.9.0", | ||
) | ||
go_repository( | ||
name = "com_github_spf13_cobra", | ||
importpath = "github.com/spf13/cobra", | ||
sum = "h1:42a0n6jwCot1pUmomAp4T7DeMD+20LFv4Q54pxLf2LI=", | ||
version = "v1.6.0", | ||
) | ||
go_repository( | ||
name = "com_github_spf13_pflag", | ||
importpath = "github.com/spf13/pflag", | ||
sum = "h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=", | ||
version = "v1.0.5", | ||
) | ||
go_repository( | ||
name = "com_github_vbatts_tar_split", | ||
importpath = "github.com/vbatts/tar-split", | ||
sum = "h1:Via6XqJr0hceW4wff3QRzD5gAk/tatMw/4ZA7cTlIME=", | ||
version = "v0.11.2", | ||
) | ||
go_repository( | ||
name = "com_google_cloud_go_compute", | ||
importpath = "cloud.google.com/go/compute", | ||
sum = "h1:aoLIYaA1fX3ywihqpBk2APQKOo20nXsp1GEZQbx5Jk4=", | ||
version = "v1.10.0", | ||
) | ||
go_repository( | ||
name = "in_gopkg_check_v1", | ||
importpath = "gopkg.in/check.v1", | ||
sum = "h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=", | ||
version = "v1.0.0-20201130134442-10cb98267c6c", | ||
) | ||
go_repository( | ||
name = "in_gopkg_yaml_v3", | ||
importpath = "gopkg.in/yaml.v3", | ||
sum = "h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=", | ||
version = "v3.0.1", | ||
) | ||
go_repository( | ||
name = "org_golang_google_appengine", | ||
importpath = "google.golang.org/appengine", | ||
sum = "h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=", | ||
version = "v1.6.7", | ||
) | ||
go_repository( | ||
name = "org_golang_google_protobuf", | ||
importpath = "google.golang.org/protobuf", | ||
sum = "h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=", | ||
version = "v1.28.1", | ||
) | ||
go_repository( | ||
name = "org_golang_x_mod", | ||
importpath = "golang.org/x/mod", | ||
sum = "h1:b9gGHsz9/HhJ3HF5DHQytPpuwocVTChQJK3AvoLRD5I=", | ||
version = "v0.6.0", | ||
) | ||
go_repository( | ||
name = "org_golang_x_net", | ||
importpath = "golang.org/x/net", | ||
sum = "h1:hZ/3BUoy5aId7sCpA/Tc5lt8DkFgdVS2onTpJsZ/fl0=", | ||
version = "v0.1.0", | ||
) | ||
go_repository( | ||
name = "org_golang_x_oauth2", | ||
importpath = "golang.org/x/oauth2", | ||
sum = "h1:isLCZuhj4v+tYv7eskaN4v/TM+A1begWWgyVJDdl1+Y=", | ||
version = "v0.1.0", | ||
) | ||
go_repository( | ||
name = "org_golang_x_sync", | ||
importpath = "golang.org/x/sync", | ||
sum = "h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=", | ||
version = "v0.1.0", | ||
) | ||
go_repository( | ||
name = "org_golang_x_sys", | ||
importpath = "golang.org/x/sys", | ||
sum = "h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=", | ||
version = "v0.1.0", | ||
) | ||
go_repository( | ||
name = "org_golang_x_time", | ||
importpath = "golang.org/x/time", | ||
sum = "h1:7zkz7BUtwNFFqcowJ+RIgu2MaV/MapERkDIy+mwPyjs=", | ||
version = "v0.0.0-20210723032227-1f47c861a9ac", | ||
) | ||
go_repository( | ||
name = "org_golang_x_tools", | ||
importpath = "golang.org/x/tools", | ||
sum = "h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU=", | ||
version = "v0.1.12", | ||
) | ||
go_repository( | ||
name = "tools_gotest_v3", | ||
importpath = "gotest.tools/v3", | ||
sum = "h1:4AuOwCGf4lLR9u3YOe2awrHygurzhO/HeQ6laiA6Sx0=", | ||
version = "v3.0.3", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module example.com/custom_registry | ||
|
||
go 1.19 | ||
|
||
require github.com/google/go-containerregistry v0.13.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
github.com/containerd/stargz-snapshotter/estargz v0.12.1 h1:+7nYmHJb0tEkcRaAW+MHqoKaJYZmkikupxCqVtmPuY0= | ||
github.com/docker/cli v20.10.20+incompatible h1:lWQbHSHUFs7KraSN2jOJK7zbMS2jNCHI4mt4xUFUVQ4= | ||
github.com/docker/distribution v2.8.1+incompatible h1:Q50tZOPR6T/hjNsyc9g8/syEs6bk8XXApsHjKukMl68= | ||
github.com/docker/docker v20.10.20+incompatible h1:kH9tx6XO+359d+iAkumyKDc5Q1kOwPuAUaeri48nD6E= | ||
github.com/docker/docker-credential-helpers v0.7.0 h1:xtCHsjxogADNZcdv1pKUHXryefjlVRqWqIhk/uXJp0A= | ||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= | ||
github.com/google/go-containerregistry v0.13.0 h1:y1C7Z3e149OJbOPDBxLYR8ITPz8dTKqQwjErKVHJC8k= | ||
github.com/google/go-containerregistry v0.13.0/go.mod h1:J9FQ+eSS4a1aC2GNZxvNpbWhgp0487v+cgiilB4FqDo= | ||
github.com/klauspost/compress v1.15.11 h1:Lcadnb3RKGin4FYM/orgq0qde+nc15E5Cbqg4B9Sx9c= | ||
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= | ||
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= | ||
github.com/opencontainers/image-spec v1.1.0-rc2 h1:2zx/Stx4Wc5pIPDvIxHXvXtQFW/7XWJGmnM7r3wg034= | ||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= | ||
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= | ||
github.com/vbatts/tar-split v0.11.2 h1:Via6XqJr0hceW4wff3QRzD5gAk/tatMw/4ZA7cTlIME= | ||
golang.org/x/mod v0.6.0 h1:b9gGHsz9/HhJ3HF5DHQytPpuwocVTChQJK3AvoLRD5I= | ||
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= | ||
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U= | ||
golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU= |
Oops, something went wrong.