From ca7c5f586fb950e7215497b3af3da5829827c67d Mon Sep 17 00:00:00 2001 From: Aleksey Pesternikov Date: Thu, 18 Apr 2024 07:50:48 -0700 Subject: [PATCH 1/7] add resolved_push, resolved_binary and gitopsdir --- MODULE.bazel.lock | 1086 ++++++++++++++++- e2e/MODULE.bazel | 1 + gitops/git/git.go | 35 +- gitops/prer/BUILD | 1 + gitops/prer/create_gitops_prs.go | 158 ++- go.mod | 1 + go.sum | 2 + testing/it_sidecar/stern/BUILD | 1 - transitions/tests/BUILD.bazel | 9 +- vendor/golang.org/x/sync/LICENSE | 27 + vendor/golang.org/x/sync/errgroup/BUILD | 13 + vendor/golang.org/x/sync/errgroup/errgroup.go | 135 ++ vendor/golang.org/x/sync/errgroup/go120.go | 13 + .../golang.org/x/sync/errgroup/pre_go120.go | 14 + vendor/modules.txt | 3 + 15 files changed, 1426 insertions(+), 73 deletions(-) create mode 100644 vendor/golang.org/x/sync/LICENSE create mode 100644 vendor/golang.org/x/sync/errgroup/BUILD create mode 100644 vendor/golang.org/x/sync/errgroup/errgroup.go create mode 100644 vendor/golang.org/x/sync/errgroup/go120.go create mode 100644 vendor/golang.org/x/sync/errgroup/pre_go120.go diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index b93eec91..2b896671 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -1337,7 +1337,7 @@ "moduleExtensions": { "//gitops:extensions.bzl%toolchains": { "general": { - "bzlTransitiveDigest": "5Wg3kxup7pYafCf0D82azWWCB3UgJlGHWwJmdsdcV8w=", + "bzlTransitiveDigest": "/KFZ+KYw6367WVIaxpvoWEu3rc/Di+QzhIiiwhYhq2c=", "accumulatedFileDigests": {}, "envVariables": {}, "generatedRepoSpecs": { @@ -2228,6 +2228,1090 @@ ] } }, + "@@gazelle~0.35.0//:extensions.bzl%go_deps": { + "general": { + "bzlTransitiveDigest": "zP01muRk4s4xWGK3gNPXOyDMQkOPsIhu99akeKWFFQ0=", + "accumulatedFileDigests": { + "@@//:go.mod": "169c9ff372c5087e38629b2e5edbde807eac8e844d04a0be2810b1263b247297", + "@@rules_go~0.44.0//:go.mod": "15454724af1504c4ce1782c2a7f423d596a1d8490125eb7c5bd9c95fea1991f0", + "@@//:go.sum": "cfe8b20daf96b2f559e27689c77c72c1dd2c45e4984f541e53d237795174a341", + "@@gazelle~0.35.0//:go.mod": "48dc6e771c3028ee1c18b9ffc81e596fd5f6d7e0016c5ef280e30f2821f60473", + "@@rules_go~0.44.0//:go.sum": "b5938730bf7d3581421928b0385d99648dd9634becead96fca0594ac491b2f49", + "@@gazelle~0.35.0//:go.sum": "7c4460e8ecb5dd8691a51d4fa2e9e4751108b933636497ce46db499fc2e7a88d" + }, + "envVariables": {}, + "generatedRepoSpecs": { + "org_golang_x_tools_go_vcs": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~org_golang_x_tools_go_vcs", + "importpath": "golang.org/x/tools/go/vcs", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:cOIJqWBl99H1dH5LWizPa+0ImeeJq3t3cJjaeOWUAL4=", + "replace": "", + "version": "v0.1.0-deprecated" + } + }, + "com_github_fsnotify_fsnotify": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~com_github_fsnotify_fsnotify", + "importpath": "github.com/fsnotify/fsnotify", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=", + "replace": "", + "version": "v1.7.0" + } + }, + "com_github_hashicorp_go_retryablehttp": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~com_github_hashicorp_go_retryablehttp", + "importpath": "github.com/hashicorp/go-retryablehttp", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:AcYqCvkpalPnPF2pn0KamgwamS42TqUDDYFRKq/RAd0=", + "replace": "", + "version": "v0.7.2" + } + }, + "io_k8s_sigs_structured_merge_diff_v4": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~io_k8s_sigs_structured_merge_diff_v4", + "importpath": "sigs.k8s.io/structured-merge-diff/v4", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:PRbqxJClWWYMNV1dhaG4NsibJbArud9kFxnAMREiWFE=", + "replace": "", + "version": "v4.2.3" + } + }, + "io_k8s_client_go": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~io_k8s_client_go", + "importpath": "k8s.io/client-go", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:87CXzYJnAMGaa/IDDfRdhTzxk/wzGZ+/HUQpqgVSZXU=", + "replace": "", + "version": "v0.26.1" + } + }, + "com_github_modern_go_reflect2": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~com_github_modern_go_reflect2", + "importpath": "github.com/modern-go/reflect2", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=", + "replace": "", + "version": "v1.0.2" + } + }, + "org_golang_x_net": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~org_golang_x_net", + "importpath": "golang.org/x/net", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg=", + "replace": "", + "version": "v0.18.0" + } + }, + "com_github_spf13_pflag": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~com_github_spf13_pflag", + "importpath": "github.com/spf13/pflag", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=", + "replace": "", + "version": "v1.0.5" + } + }, + "io_k8s_api": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~io_k8s_api", + "importpath": "k8s.io/api", + "build_directives": [ + "gazelle:proto disable" + ], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:f+SWYiPd/GsiWwVRz+NbFyCgvv75Pk9NK6dlkZgpCRQ=", + "replace": "", + "version": "v0.26.1" + } + }, + "in_gopkg_inf_v0": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~in_gopkg_inf_v0", + "importpath": "gopkg.in/inf.v0", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=", + "replace": "", + "version": "v0.9.1" + } + }, + "org_golang_x_oauth2": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~org_golang_x_oauth2", + "importpath": "golang.org/x/oauth2", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:HuArIo48skDwlrvM3sEdHXElYslAMsf3KwRkkW4MC4s=", + "replace": "", + "version": "v0.5.0" + } + }, + "com_github_google_gofuzz": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~com_github_google_gofuzz", + "importpath": "github.com/google/gofuzz", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=", + "replace": "", + "version": "v1.2.0" + } + }, + "in_gopkg_yaml_v2": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~in_gopkg_yaml_v2", + "importpath": "gopkg.in/yaml.v2", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=", + "replace": "", + "version": "v2.4.0" + } + }, + "io_k8s_sigs_json": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~io_k8s_sigs_json", + "importpath": "sigs.k8s.io/json", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=", + "replace": "", + "version": "v0.0.0-20221116044647-bc3834ca7abd" + } + }, + "com_github_google_gnostic": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~com_github_google_gnostic", + "importpath": "github.com/google/gnostic", + "build_directives": [ + "gazelle:proto disable" + ], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:ZK/5VhkoX835RikCHpSUJV9a+S3e1zLh59YnyWeBW+0=", + "replace": "", + "version": "v0.6.9" + } + }, + "com_github_josharian_intern": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~com_github_josharian_intern", + "importpath": "github.com/josharian/intern", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=", + "replace": "", + "version": "v1.0.0" + } + }, + "org_golang_x_sync": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~org_golang_x_sync", + "importpath": "golang.org/x/sync", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=", + "replace": "", + "version": "v0.7.0" + } + }, + "com_github_golang_mock": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~com_github_golang_mock", + "importpath": "github.com/golang/mock", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:YojYx61/OLFsiv6Rw1Z96LpldJIy31o+UHmwAUMJ6/U=", + "replace": "", + "version": "v1.7.0-rc.1" + } + }, + "org_golang_google_appengine": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~org_golang_google_appengine", + "importpath": "google.golang.org/appengine", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=", + "replace": "", + "version": "v1.6.7" + } + }, + "com_github_imdario_mergo": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~com_github_imdario_mergo", + "importpath": "github.com/imdario/mergo", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk=", + "replace": "", + "version": "v0.3.13" + } + }, + "com_github_modern_go_concurrent": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~com_github_modern_go_concurrent", + "importpath": "github.com/modern-go/concurrent", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=", + "replace": "", + "version": "v0.0.0-20180306012644-bacd9c7ef1dd" + } + }, + "org_golang_x_term": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~org_golang_x_term", + "importpath": "golang.org/x/term", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:n2a8QNdAb0sZNpU9R1ALUXBbY+w51fCQDN+7EdxNBsY=", + "replace": "", + "version": "v0.5.0" + } + }, + "org_golang_google_protobuf": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~org_golang_google_protobuf", + "importpath": "google.golang.org/protobuf", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=", + "replace": "", + "version": "v1.31.0" + } + }, + "org_golang_x_mod": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~org_golang_x_mod", + "importpath": "golang.org/x/mod", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=", + "replace": "", + "version": "v0.14.0" + } + }, + "com_github_google_go_github_v32": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~com_github_google_go_github_v32", + "importpath": "github.com/google/go-github/v32", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:GWkQOdXqviCPx7Q7Fj+KyPoGm4SwHRh8rheoPhd27II=", + "replace": "", + "version": "v32.1.0" + } + }, + "com_github_json_iterator_go": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~com_github_json_iterator_go", + "importpath": "github.com/json-iterator/go", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=", + "replace": "", + "version": "v1.1.12" + } + }, + "in_gopkg_yaml_v3": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~in_gopkg_yaml_v3", + "importpath": "gopkg.in/yaml.v3", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=", + "replace": "", + "version": "v3.0.1" + } + }, + "org_golang_x_crypto": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~org_golang_x_crypto", + "importpath": "golang.org/x/crypto", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc=", + "replace": "", + "version": "v0.6.0" + } + }, + "com_github_golang_protobuf": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~com_github_golang_protobuf", + "importpath": "github.com/golang/protobuf", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=", + "replace": "", + "version": "v1.5.3" + } + }, + "com_github_google_go_querystring": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~com_github_google_go_querystring", + "importpath": "github.com/google/go-querystring", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=", + "replace": "", + "version": "v1.1.0" + } + }, + "com_github_munnerz_goautoneg": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~com_github_munnerz_goautoneg", + "importpath": "github.com/munnerz/goautoneg", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=", + "replace": "", + "version": "v0.0.0-20191010083416-a7dc8b61c822" + } + }, + "io_k8s_kube_openapi": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~io_k8s_kube_openapi", + "importpath": "k8s.io/kube-openapi", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:oFDpQ7FfzinCtrFOl4izwOWsdTprlS2A9IXBENMW0UA=", + "replace": "", + "version": "v0.0.0-20230217203603-ff9a8e8fa21d" + } + }, + "com_github_moby_spdystream": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~com_github_moby_spdystream", + "importpath": "github.com/moby/spdystream", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:cjW1zVyyoiM0T7b6UoySUFqzXMoqRckQtXwGPiBhOM8=", + "replace": "", + "version": "v0.2.0" + } + }, + "com_github_ghodss_yaml": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~com_github_ghodss_yaml", + "importpath": "github.com/ghodss/yaml", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=", + "replace": "", + "version": "v1.0.0" + } + }, + "org_golang_x_time": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~org_golang_x_time", + "importpath": "golang.org/x/time", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=", + "replace": "", + "version": "v0.3.0" + } + }, + "org_golang_google_grpc_cmd_protoc_gen_go_grpc": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~org_golang_google_grpc_cmd_protoc_gen_go_grpc", + "importpath": "google.golang.org/grpc/cmd/protoc-gen-go-grpc", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:rNBFJjBCOgVr9pWD7rs/knKL4FRTKgpZmsRfV214zcA=", + "replace": "", + "version": "v1.3.0" + } + }, + "com_github_go_openapi_jsonpointer": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~com_github_go_openapi_jsonpointer", + "importpath": "github.com/go-openapi/jsonpointer", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:eCs3fxoIi3Wh6vtgmLTOjdhSpiqphQ+DaPn38N2ZdrE=", + "replace": "", + "version": "v0.19.6" + } + }, + "com_github_bmatcuk_doublestar_v4": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~com_github_bmatcuk_doublestar_v4", + "importpath": "github.com/bmatcuk/doublestar/v4", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:FH9SifrbvJhnlQpztAx++wlkk70QBf0iBWDwNy7PA4I=", + "replace": "", + "version": "v4.6.1" + } + }, + "com_github_pmezard_go_difflib": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~com_github_pmezard_go_difflib", + "importpath": "github.com/pmezard/go-difflib", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=", + "replace": "", + "version": "v1.0.0" + } + }, + "com_github_davecgh_go_spew": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~com_github_davecgh_go_spew", + "importpath": "github.com/davecgh/go-spew", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=", + "replace": "", + "version": "v1.1.1" + } + }, + "org_golang_x_tools": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~org_golang_x_tools", + "importpath": "golang.org/x/tools", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:zdAyfUGbYmuVokhzVmghFl2ZJh5QhcfebBgmVPFYA+8=", + "replace": "", + "version": "v0.15.0" + } + }, + "com_github_bazelbuild_buildtools": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~com_github_bazelbuild_buildtools", + "importpath": "github.com/bazelbuild/buildtools", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:2Gc2Q6hVR1SJ8bBI9Ybzoggp8u/ED2WkM4MfvEIn9+c=", + "replace": "", + "version": "v0.0.0-20231115204819-d4c9dccdfbb1" + } + }, + "org_golang_google_genproto": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~org_golang_google_genproto", + "importpath": "google.golang.org/genproto", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:W12Pwm4urIbRdGhMEg2NM9O3TWKjNcxQhs46V0ypf/k=", + "replace": "", + "version": "v0.0.0-20231127180814-3a041ad873d4" + } + }, + "com_github_gogo_protobuf": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~com_github_gogo_protobuf", + "importpath": "github.com/gogo/protobuf", + "build_directives": [ + "gazelle:proto disable" + ], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=", + "replace": "", + "version": "v1.3.2" + } + }, + "com_github_emicklei_go_restful_v3": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~com_github_emicklei_go_restful_v3", + "importpath": "github.com/emicklei/go-restful/v3", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:rc42Y5YTp7Am7CS630D7JmhRjq4UlEUuEKfrDac4bSQ=", + "replace": "", + "version": "v3.10.1" + } + }, + "org_golang_google_grpc": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~org_golang_google_grpc", + "importpath": "google.golang.org/grpc", + "build_directives": [ + "gazelle:proto disable" + ], + "build_file_generation": "on", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:Z5Iec2pjwb+LEOqzpB2MR12/eKFhDPhuqW91O+4bwUk=", + "replace": "", + "version": "v1.59.0" + } + }, + "com_github_go_openapi_swag": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~com_github_go_openapi_swag", + "importpath": "github.com/go-openapi/swag", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:yMBqmnQ0gyZvEb/+KzuWZOXgllrXT4SADYbvDaXHv/g=", + "replace": "", + "version": "v0.22.3" + } + }, + "com_github_hashicorp_go_cleanhttp": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~com_github_hashicorp_go_cleanhttp", + "importpath": "github.com/hashicorp/go-cleanhttp", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=", + "replace": "", + "version": "v0.5.2" + } + }, + "org_golang_google_genproto_googleapis_rpc": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~org_golang_google_genproto_googleapis_rpc", + "importpath": "google.golang.org/genproto/googleapis/rpc", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:ultW7fxlIvee4HYrtnaRPon9HpEgFk5zYpmfMgtKB5I=", + "replace": "", + "version": "v0.0.0-20231120223509-83a465c0220f" + } + }, + "com_github_google_go_cmp": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~com_github_google_go_cmp", + "importpath": "github.com/google/go-cmp", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=", + "replace": "", + "version": "v0.6.0" + } + }, + "io_k8s_sigs_yaml": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~io_k8s_sigs_yaml", + "importpath": "sigs.k8s.io/yaml", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=", + "replace": "", + "version": "v1.3.0" + } + }, + "com_github_go_logr_logr": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~com_github_go_logr_logr", + "importpath": "github.com/go-logr/logr", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=", + "replace": "", + "version": "v1.2.3" + } + }, + "org_golang_x_text": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~org_golang_x_text", + "importpath": "golang.org/x/text", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=", + "replace": "", + "version": "v0.14.0" + } + }, + "com_github_mailru_easyjson": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~com_github_mailru_easyjson", + "importpath": "github.com/mailru/easyjson", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=", + "replace": "", + "version": "v0.7.7" + } + }, + "io_k8s_klog_v2": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~io_k8s_klog_v2", + "importpath": "k8s.io/klog/v2", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:VkTxIV/FjRXn1fgNNcKGM8cfmL1Z33ZjXRTVxKCoF5M=", + "replace": "", + "version": "v2.90.0" + } + }, + "io_k8s_utils": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~io_k8s_utils", + "importpath": "k8s.io/utils", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:kmDqav+P+/5e1i9tFfHq1qcF3sOrDp+YEkVDAHu7Jwk=", + "replace": "", + "version": "v0.0.0-20230220204549-a5ecb0141aa5" + } + }, + "com_github_xanzy_go_gitlab": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~com_github_xanzy_go_gitlab", + "importpath": "github.com/xanzy/go-gitlab", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:CH1Q7NDklqZllox4ICVF4PwlhQGfPtE+w08Jsb74ZX0=", + "replace": "", + "version": "v0.80.2" + } + }, + "io_k8s_apimachinery": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~io_k8s_apimachinery", + "importpath": "k8s.io/apimachinery", + "build_directives": [ + "gazelle:proto disable" + ], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:8EZ/eGJL+hY/MYCNwhmDzVqq2lPl3N3Bo8rvweJwXUQ=", + "replace": "", + "version": "v0.26.1" + } + }, + "bazel_gazelle_go_repository_config": { + "bzlFile": "@@gazelle~0.35.0//internal/bzlmod:go_deps.bzl", + "ruleClassName": "_go_repository_config", + "attributes": { + "name": "gazelle~0.35.0~go_deps~bazel_gazelle_go_repository_config", + "importpaths": { + "com_github_ghodss_yaml": "github.com/ghodss/yaml", + "com_github_golang_protobuf": "github.com/golang/protobuf", + "com_github_google_go_cmp": "github.com/google/go-cmp", + "com_github_google_go_github_v32": "github.com/google/go-github/v32", + "com_github_xanzy_go_gitlab": "github.com/xanzy/go-gitlab", + "org_golang_x_oauth2": "golang.org/x/oauth2", + "io_k8s_api": "k8s.io/api", + "io_k8s_apimachinery": "k8s.io/apimachinery", + "io_k8s_client_go": "k8s.io/client-go", + "com_github_davecgh_go_spew": "github.com/davecgh/go-spew", + "com_github_emicklei_go_restful_v3": "github.com/emicklei/go-restful/v3", + "com_github_go_logr_logr": "github.com/go-logr/logr", + "com_github_go_openapi_jsonpointer": "github.com/go-openapi/jsonpointer", + "com_github_go_openapi_jsonreference": "github.com/go-openapi/jsonreference", + "com_github_go_openapi_swag": "github.com/go-openapi/swag", + "com_github_gogo_protobuf": "github.com/gogo/protobuf", + "com_github_google_gnostic": "github.com/google/gnostic", + "com_github_google_go_querystring": "github.com/google/go-querystring", + "com_github_google_gofuzz": "github.com/google/gofuzz", + "com_github_hashicorp_go_cleanhttp": "github.com/hashicorp/go-cleanhttp", + "com_github_hashicorp_go_retryablehttp": "github.com/hashicorp/go-retryablehttp", + "com_github_imdario_mergo": "github.com/imdario/mergo", + "com_github_josharian_intern": "github.com/josharian/intern", + "com_github_json_iterator_go": "github.com/json-iterator/go", + "com_github_mailru_easyjson": "github.com/mailru/easyjson", + "com_github_moby_spdystream": "github.com/moby/spdystream", + "com_github_modern_go_concurrent": "github.com/modern-go/concurrent", + "com_github_modern_go_reflect2": "github.com/modern-go/reflect2", + "com_github_munnerz_goautoneg": "github.com/munnerz/goautoneg", + "com_github_spf13_pflag": "github.com/spf13/pflag", + "org_golang_x_crypto": "golang.org/x/crypto", + "org_golang_x_net": "golang.org/x/net", + "org_golang_x_sync": "golang.org/x/sync", + "org_golang_x_sys": "golang.org/x/sys", + "org_golang_x_term": "golang.org/x/term", + "org_golang_x_text": "golang.org/x/text", + "org_golang_x_time": "golang.org/x/time", + "org_golang_google_appengine": "google.golang.org/appengine", + "org_golang_google_protobuf": "google.golang.org/protobuf", + "in_gopkg_inf_v0": "gopkg.in/inf.v0", + "in_gopkg_yaml_v2": "gopkg.in/yaml.v2", + "in_gopkg_yaml_v3": "gopkg.in/yaml.v3", + "io_k8s_klog_v2": "k8s.io/klog/v2", + "io_k8s_kube_openapi": "k8s.io/kube-openapi", + "io_k8s_utils": "k8s.io/utils", + "io_k8s_sigs_json": "sigs.k8s.io/json", + "io_k8s_sigs_structured_merge_diff_v4": "sigs.k8s.io/structured-merge-diff/v4", + "io_k8s_sigs_yaml": "sigs.k8s.io/yaml", + "com_github_golang_mock": "github.com/golang/mock", + "org_golang_x_tools": "golang.org/x/tools", + "org_golang_google_genproto": "google.golang.org/genproto", + "org_golang_google_grpc": "google.golang.org/grpc", + "org_golang_google_grpc_cmd_protoc_gen_go_grpc": "google.golang.org/grpc/cmd/protoc-gen-go-grpc", + "org_golang_x_mod": "golang.org/x/mod", + "org_golang_google_genproto_googleapis_rpc": "google.golang.org/genproto/googleapis/rpc", + "com_github_bazelbuild_buildtools": "github.com/bazelbuild/buildtools", + "com_github_bmatcuk_doublestar_v4": "github.com/bmatcuk/doublestar/v4", + "com_github_fsnotify_fsnotify": "github.com/fsnotify/fsnotify", + "com_github_pmezard_go_difflib": "github.com/pmezard/go-difflib", + "org_golang_x_tools_go_vcs": "golang.org/x/tools/go/vcs", + "@rules_go~0.44.0": "github.com/bazelbuild/rules_go", + "@gazelle~0.35.0": "github.com/bazelbuild/bazel-gazelle" + }, + "module_names": { + "@rules_go~0.44.0": "rules_go", + "@gazelle~0.35.0": "gazelle" + }, + "build_naming_conventions": {} + } + }, + "org_golang_x_sys": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~org_golang_x_sys", + "importpath": "golang.org/x/sys", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=", + "replace": "", + "version": "v0.15.0" + } + }, + "com_github_go_openapi_jsonreference": { + "bzlFile": "@@gazelle~0.35.0//internal:go_repository.bzl", + "ruleClassName": "go_repository", + "attributes": { + "name": "gazelle~0.35.0~go_deps~com_github_go_openapi_jsonreference", + "importpath": "github.com/go-openapi/jsonreference", + "build_directives": [], + "build_file_generation": "auto", + "build_extra_args": [], + "patches": [], + "patch_args": [], + "sum": "h1:3sVjiK66+uXK/6oQ8xgcRKcFgQ5KXa2KvnJRumpMGbE=", + "replace": "", + "version": "v0.20.2" + } + } + }, + "moduleExtensionMetadata": { + "explicitRootModuleDirectDeps": [ + "com_github_ghodss_yaml", + "com_github_golang_protobuf", + "com_github_google_go_cmp", + "com_github_google_go_github_v32", + "com_github_xanzy_go_gitlab", + "org_golang_x_oauth2", + "io_k8s_api", + "io_k8s_apimachinery", + "io_k8s_client_go" + ], + "explicitRootModuleDirectDevDeps": [], + "useAllRepos": "NO" + }, + "recordedRepoMappingEntries": [ + [ + "gazelle~0.35.0", + "bazel_tools", + "bazel_tools" + ] + ] + } + }, "@@gazelle~0.35.0//internal/bzlmod:non_module_deps.bzl%non_module_deps": { "general": { "bzlTransitiveDigest": "l49A97WIxQpEMKarHXTjDf5XjDqTUJdkp15mOXd/Gj0=", diff --git a/e2e/MODULE.bazel b/e2e/MODULE.bazel index f9144331..b9c37104 100644 --- a/e2e/MODULE.bazel +++ b/e2e/MODULE.bazel @@ -1,6 +1,7 @@ bazel_dep(name = "rules_go", version = "0.46.0", repo_name = "io_bazel_rules_go") bazel_dep(name = "bazel_skylib", version = "1.5.0") bazel_dep(name = "rules_oci", version = "1.7.2") + oci = use_extension("@rules_oci//oci:extensions.bzl", "oci") oci.pull( name = "go_image_static", diff --git a/gitops/git/git.go b/gitops/git/git.go index 7e282564..7fbe081b 100644 --- a/gitops/git/git.go +++ b/gitops/git/git.go @@ -13,7 +13,6 @@ package git import ( "fmt" - "io/ioutil" "log" "os" oe "os/exec" @@ -22,10 +21,6 @@ import ( "github.com/fasterci/rules_gitops/gitops/exec" ) -var ( - git = "git" -) - // Clone clones a repository. Pass the full repository name, such as // "https://aleksey.pesternikov@bitbucket.tubemogul.info/scm/tm/repo.git" as the repo. // Cloned directory will be clean of local changes with primaryBranch branch checked out. @@ -34,7 +29,7 @@ var ( // mirrorDir: optional (if not empty) local mirror of the repository func Clone(repo, dir, mirrorDir, primaryBranch, gitopsPath string) (*Repo, error) { if err := os.RemoveAll(dir); err != nil { - return nil, fmt.Errorf("Unable to clone repo: %w", err) + return nil, fmt.Errorf("unable to clone repo: %w", err) } if mirrorDir != "" { exec.Mustex("", "git", "clone", "-n", "--reference", mirrorDir, repo, dir) @@ -43,8 +38,8 @@ func Clone(repo, dir, mirrorDir, primaryBranch, gitopsPath string) (*Repo, error } exec.Mustex(dir, "git", "config", "--local", "core.sparsecheckout", "true") genPath := fmt.Sprintf("%s/\n", gitopsPath) - if err := ioutil.WriteFile(filepath.Join(dir, ".git/info/sparse-checkout"), []byte(genPath), 0644); err != nil { - return nil, fmt.Errorf("Unable to create .git/info/sparse-checkout: %w", err) + if err := os.WriteFile(filepath.Join(dir, ".git/info/sparse-checkout"), []byte(genPath), 0644); err != nil { + return nil, fmt.Errorf("unable to create .git/info/sparse-checkout: %w", err) } exec.Mustex(dir, "git", "checkout", primaryBranch) @@ -53,6 +48,30 @@ func Clone(repo, dir, mirrorDir, primaryBranch, gitopsPath string) (*Repo, error }, nil } +func CloneOrCheckout(repo, dir, mirrorDir, primaryBranch, gitopsPath string) (r *Repo, err error) { + if _, err = os.Stat(dir + "/.git"); os.IsNotExist(err) { + if err = os.MkdirAll(filepath.Dir(dir), os.ModePerm); err != nil && !os.IsExist(err) { + return nil, err + } + if mirrorDir != "" { + exec.Mustex("", "git", "clone", "-n", "--reference", mirrorDir, repo, dir) + } else { + exec.Mustex("", "git", "clone", "-n", repo, dir) + } + + } else { + //existing repo + exec.Mustex(dir, "git", "remote", "set-url", "origin", repo) + exec.Mustex(dir, "git", "fetch", "origin", "--prune") + exec.Mustex(dir, "git", "reset", "--hard") + } + exec.Mustex(dir, "git", "checkout", "-f", primaryBranch) + + return &Repo{ + Dir: dir, + }, nil +} + // Repo is a clone of a git repository. Create with Clone, and don't // forget to clean it up after. type Repo struct { diff --git a/gitops/prer/BUILD b/gitops/prer/BUILD index 2684dd2e..98314927 100644 --- a/gitops/prer/BUILD +++ b/gitops/prer/BUILD @@ -27,6 +27,7 @@ go_library( "//gitops/git/github:go_default_library", "//gitops/git/gitlab:go_default_library", "//vendor/github.com/golang/protobuf/proto:go_default_library", + "//vendor/golang.org/x/sync/errgroup:go_default_library", ], ) diff --git a/gitops/prer/create_gitops_prs.go b/gitops/prer/create_gitops_prs.go index 5ac47c42..a5d41a21 100644 --- a/gitops/prer/create_gitops_prs.go +++ b/gitops/prer/create_gitops_prs.go @@ -15,7 +15,6 @@ import ( "flag" "fmt" "io" - "io/ioutil" "log" "os" oe "os/exec" @@ -30,6 +29,7 @@ import ( "github.com/fasterci/rules_gitops/gitops/git/bitbucket" "github.com/fasterci/rules_gitops/gitops/git/github" "github.com/fasterci/rules_gitops/gitops/git/gitlab" + "golang.org/x/sync/errgroup" proto "github.com/golang/protobuf/proto" ) @@ -56,8 +56,9 @@ var ( workspace = flag.String("workspace", "", "path to workspace root") repo = flag.String("git_repo", "", "git repo location") gitMirror = flag.String("git_mirror", "", "git mirror location, like /mnt/mirror/bitbucket.tubemogul.info/tm/repo.git for jenkins") - gitopsPath = flag.String("gitops_path", "cloud", "location to store files in repo.") + gitopsPath = flag.String("gitops_path", "cloud", "location to store files in repo") gitopsTmpDir = flag.String("gitops_tmpdir", os.TempDir(), "location to check out git tree with /cloud.") + gitopsdir string target = flag.String("target", "//... except //experimental/...", "target to scan. Useful for debugging only") pushParallelism = flag.Int("push_parallelism", 1, "Number of image pushes to perform concurrently") prInto = flag.String("gitops_pr_into", "master", "use this branch as the source branch and target for deployment PR") @@ -65,18 +66,24 @@ var ( prTitle = flag.String("gitops_pr_title", "", "a title for deployment PR") branchName = flag.String("branch_name", "unknown", "Branch name to use in commit message") gitCommit = flag.String("git_commit", "unknown", "Git commit to use in commit message") + deployBranchPrefix = flag.String("deploy_branch_prefix", "deploy/", "prefix to add to all deployment branch names") deploymentBranchSuffix = flag.String("deployment_branch_suffix", "", "suffix to add to all deployment branch names") gitHost = flag.String("git_server", "bitbucket", "the git server api to use. 'bitbucket', 'github' or 'gitlab'") gitopsKind SliceFlags gitopsRuleName SliceFlags gitopsRuleAttr SliceFlags dryRun = flag.Bool("dry_run", false, "Do not create PRs, just print what would be done") + resolvedPushes SliceFlags + resolvedBinaries SliceFlags ) func init() { flag.Var(&gitopsKind, "gitops_dependencies_kind", "dependency kind(s) to run during gitops phase. Can be specified multiple times. Default is 'k8s_container_push'") flag.Var(&gitopsRuleName, "gitops_dependencies_name", "dependency name(s) to run during gitops phase. Can be specified multiple times. Default is empty") flag.Var(&gitopsRuleAttr, "gitops_dependencies_attr", "dependency attribute(s) to run during gitops phase. Use attribute=value format. Can be specified multiple times. Default is empty") + flag.Var(&resolvedPushes, "resolved_push", "list of resolved push binaries to run. Can be specified multiple times. format is cmd/binary/to/run/command. Default is empty") + flag.Var(&resolvedBinaries, "resolved_binary", "list of resolved gitops binaries to run. Can be specified multiple times. format is releasetrain:cmd/binary/to/run/command. Default is empty") + flag.StringVar(&gitopsdir, "gitopsdir", "", "do not use temporary directory for gitops, use this directory instead") } func bazelQuery(query string) *analysis.CqueryResult { @@ -123,21 +130,32 @@ func main() { log.Fatalf("unknown vcs host: %s", *gitHost) } - q := fmt.Sprintf("attr(deployment_branch, \".+\", attr(release_branch_prefix, \"%s\", kind(gitops, %s)))", *releaseBranch, *target) - qr := bazelQuery(q) releaseTrains := make(map[string][]string) - for _, t := range qr.Results { - var releaseTrain string - for _, a := range t.Target.GetRule().GetAttribute() { - if a.GetName() == "deployment_branch" { - releaseTrain = a.GetStringValue() + if len(resolvedBinaries) > 0 { + for _, rb := range resolvedBinaries { + releaseTrain, bin, found := strings.Cut(rb, ":") + if !found { + log.Fatalf("resolved_binaries: invalid resolved_binary format: %s", rb) } + releaseTrains[releaseTrain] = append(releaseTrains[releaseTrain], bin) + } + } else { + + q := fmt.Sprintf("attr(deployment_branch, \".+\", attr(release_branch_prefix, \"%s\", kind(gitops, %s)))", *releaseBranch, *target) + qr := bazelQuery(q) + for _, t := range qr.Results { + var releaseTrain string + for _, a := range t.Target.GetRule().GetAttribute() { + if a.GetName() == "deployment_branch" { + releaseTrain = a.GetStringValue() + } + } + releaseTrains[releaseTrain] = append(releaseTrains[releaseTrain], t.Target.Rule.GetName()) + } + if (len(releaseTrains)) == 0 { + log.Println("No matching targets found") + return } - releaseTrains[releaseTrain] = append(releaseTrains[releaseTrain], t.Target.Rule.GetName()) - } - if (len(releaseTrains)) == 0 { - log.Println("No matching targets found") - return } for train, targets := range releaseTrains { @@ -147,12 +165,15 @@ func main() { } } - gitopsdir, err := ioutil.TempDir(*gitopsTmpDir, "gitops") - if err != nil { - log.Fatalf("Unable to create tempdir in %s: %v", *gitopsTmpDir, err) + if gitopsdir == "" { + var err error + gitopsdir, err = os.MkdirTemp(*gitopsTmpDir, "gitops") + if err != nil { + log.Fatalf("Unable to create tempdir in %s: %v", *gitopsTmpDir, err) + } + defer os.RemoveAll(gitopsdir) } - defer os.RemoveAll(gitopsdir) - workdir, err := git.Clone(*repo, gitopsdir, *gitMirror, *prInto, *gitopsPath) + workdir, err := git.CloneOrCheckout(*repo, gitopsdir, *gitMirror, *prInto, *gitopsPath) if err != nil { log.Fatalf("Unable to clone repo: %v", err) } @@ -162,7 +183,7 @@ func main() { for train, targets := range releaseTrains { log.Println("train", train) - branch := fmt.Sprintf("deploy/%s%s", train, *deploymentBranchSuffix) + branch := fmt.Sprintf("%s%s%s", *deployBranchPrefix, train, *deploymentBranchSuffix) newBranch := workdir.SwitchToBranch(branch, *prInto) if !newBranch { // Find if we need to recreate the branch because target was deleted @@ -197,53 +218,66 @@ func main() { } // Push images + if len(resolvedPushes) > 0 { + var eg errgroup.Group + eg.SetLimit(*pushParallelism) + for _, rp := range resolvedPushes { + cmd := rp + eg.Go(func() error { + exec.Mustex("", cmd) + return nil + }) + } + eg.Wait() + } else { - // Create space separated set('//a' '//b' ... '//z') of targets. - // Target names need to be quoted to protect from + and other special characters - depsList := "set('" + strings.Join(updatedGitopsTargets, "' '") + "')" - var qv []string - for _, kind := range gitopsKind { - q := fmt.Sprintf("kind(%s, deps(%s))", kind, depsList) - qv = append(qv, q) - } - for _, name := range gitopsRuleName { - q := fmt.Sprintf("filter(%s, deps(%s))", name, depsList) - qv = append(qv, q) - } - for _, attr := range gitopsRuleAttr { - name, value, found := strings.Cut(attr, "=") - if !found { - value = ".*" + // Create space separated set('//a' '//b' ... '//z') of targets. + // Target names need to be quoted to protect from + and other special characters + depsList := "set('" + strings.Join(updatedGitopsTargets, "' '") + "')" + var qv []string + for _, kind := range gitopsKind { + q := fmt.Sprintf("kind(%s, deps(%s))", kind, depsList) + qv = append(qv, q) + } + for _, name := range gitopsRuleName { + q := fmt.Sprintf("filter(%s, deps(%s))", name, depsList) + qv = append(qv, q) + } + for _, attr := range gitopsRuleAttr { + name, value, found := strings.Cut(attr, "=") + if !found { + value = ".*" + } + q := fmt.Sprintf("attr(%s, %s, deps(%s))", name, value, depsList) + qv = append(qv, q) } - q := fmt.Sprintf("attr(%s, %s, deps(%s))", name, value, depsList) - qv = append(qv, q) - } - query := strings.Join(qv, " union ") - qr = bazelQuery(query) - targetsCh := make(chan string) - var wg sync.WaitGroup - wg.Add(*pushParallelism) - for i := 0; i < *pushParallelism; i++ { - go func() { - defer wg.Done() - for target := range targetsCh { - bin := bazel.TargetToExecutable(target) - fi, err := os.Stat(bin) - if err == nil && fi.Mode().IsRegular() { - exec.Mustex("", bin) - } else { - log.Println("target", target, "is not a file, running as a command") - exec.Mustex("", *bazelCmd, "run", target) + query := strings.Join(qv, " union ") + qr := bazelQuery(query) + targetsCh := make(chan string) + var wg sync.WaitGroup + wg.Add(*pushParallelism) + for i := 0; i < *pushParallelism; i++ { + go func() { + defer wg.Done() + for target := range targetsCh { + bin := bazel.TargetToExecutable(target) + fi, err := os.Stat(bin) + if err == nil && fi.Mode().IsRegular() { + exec.Mustex("", bin) + } else { + log.Println("target", target, "is not a file, running as a command") + exec.Mustex("", *bazelCmd, "run", target) + } } - } - }() - } - for _, t := range qr.Results { - targetsCh <- t.Target.Rule.GetName() + }() + } + for _, t := range qr.Results { + targetsCh <- t.Target.Rule.GetName() + } + close(targetsCh) + wg.Wait() } - close(targetsCh) - wg.Wait() if *dryRun { log.Println("dry-run: updated gitops branches: ", updatedGitopsBranches) diff --git a/go.mod b/go.mod index b991c4aa..facd499b 100644 --- a/go.mod +++ b/go.mod @@ -38,6 +38,7 @@ require ( github.com/spf13/pflag v1.0.5 // indirect golang.org/x/crypto v0.6.0 // indirect golang.org/x/net v0.7.0 // indirect + golang.org/x/sync v0.7.0 // indirect golang.org/x/sys v0.5.0 // indirect golang.org/x/term v0.5.0 // indirect golang.org/x/text v0.7.0 // indirect diff --git a/go.sum b/go.sum index 2984c924..7f4ccca8 100644 --- a/go.sum +++ b/go.sum @@ -175,6 +175,8 @@ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/testing/it_sidecar/stern/BUILD b/testing/it_sidecar/stern/BUILD index 1d70d1ff..f1d3c7b1 100644 --- a/testing/it_sidecar/stern/BUILD +++ b/testing/it_sidecar/stern/BUILD @@ -17,6 +17,5 @@ go_library( "//vendor/k8s.io/apimachinery/pkg/watch:go_default_library", "//vendor/k8s.io/client-go/kubernetes:go_default_library", "//vendor/k8s.io/client-go/kubernetes/typed/core/v1:go_default_library", - "//vendor/k8s.io/client-go/rest:go_default_library", ], ) diff --git a/transitions/tests/BUILD.bazel b/transitions/tests/BUILD.bazel index 3b46cbce..0b005cdc 100644 --- a/transitions/tests/BUILD.bazel +++ b/transitions/tests/BUILD.bazel @@ -104,7 +104,7 @@ diff_test( go_binary( name = "test_transition_binary", - embed = [":transitions_lib"], + embed = [":go_default_library"], tags = ["manual"], visibility = ["//visibility:public"], ) @@ -149,3 +149,10 @@ go_library( importpath = "github.com/aspect-build/bazel-lib/lib/tests/transitions", visibility = ["//visibility:private"], ) + +go_library( + name = "go_default_library", + srcs = ["main.go"], + importpath = "github.com/fasterci/rules_gitops/transitions/tests", + visibility = ["//visibility:private"], +) diff --git a/vendor/golang.org/x/sync/LICENSE b/vendor/golang.org/x/sync/LICENSE new file mode 100644 index 00000000..6a66aea5 --- /dev/null +++ b/vendor/golang.org/x/sync/LICENSE @@ -0,0 +1,27 @@ +Copyright (c) 2009 The Go Authors. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Google Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/golang.org/x/sync/errgroup/BUILD b/vendor/golang.org/x/sync/errgroup/BUILD new file mode 100644 index 00000000..e487d8e5 --- /dev/null +++ b/vendor/golang.org/x/sync/errgroup/BUILD @@ -0,0 +1,13 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "go_default_library", + srcs = [ + "errgroup.go", + "go120.go", + "pre_go120.go", + ], + importmap = "github.com/fasterci/rules_gitops/vendor/golang.org/x/sync/errgroup", + importpath = "golang.org/x/sync/errgroup", + visibility = ["//visibility:public"], +) diff --git a/vendor/golang.org/x/sync/errgroup/errgroup.go b/vendor/golang.org/x/sync/errgroup/errgroup.go new file mode 100644 index 00000000..948a3ee6 --- /dev/null +++ b/vendor/golang.org/x/sync/errgroup/errgroup.go @@ -0,0 +1,135 @@ +// Copyright 2016 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package errgroup provides synchronization, error propagation, and Context +// cancelation for groups of goroutines working on subtasks of a common task. +// +// [errgroup.Group] is related to [sync.WaitGroup] but adds handling of tasks +// returning errors. +package errgroup + +import ( + "context" + "fmt" + "sync" +) + +type token struct{} + +// A Group is a collection of goroutines working on subtasks that are part of +// the same overall task. +// +// A zero Group is valid, has no limit on the number of active goroutines, +// and does not cancel on error. +type Group struct { + cancel func(error) + + wg sync.WaitGroup + + sem chan token + + errOnce sync.Once + err error +} + +func (g *Group) done() { + if g.sem != nil { + <-g.sem + } + g.wg.Done() +} + +// WithContext returns a new Group and an associated Context derived from ctx. +// +// The derived Context is canceled the first time a function passed to Go +// returns a non-nil error or the first time Wait returns, whichever occurs +// first. +func WithContext(ctx context.Context) (*Group, context.Context) { + ctx, cancel := withCancelCause(ctx) + return &Group{cancel: cancel}, ctx +} + +// Wait blocks until all function calls from the Go method have returned, then +// returns the first non-nil error (if any) from them. +func (g *Group) Wait() error { + g.wg.Wait() + if g.cancel != nil { + g.cancel(g.err) + } + return g.err +} + +// Go calls the given function in a new goroutine. +// It blocks until the new goroutine can be added without the number of +// active goroutines in the group exceeding the configured limit. +// +// The first call to return a non-nil error cancels the group's context, if the +// group was created by calling WithContext. The error will be returned by Wait. +func (g *Group) Go(f func() error) { + if g.sem != nil { + g.sem <- token{} + } + + g.wg.Add(1) + go func() { + defer g.done() + + if err := f(); err != nil { + g.errOnce.Do(func() { + g.err = err + if g.cancel != nil { + g.cancel(g.err) + } + }) + } + }() +} + +// TryGo calls the given function in a new goroutine only if the number of +// active goroutines in the group is currently below the configured limit. +// +// The return value reports whether the goroutine was started. +func (g *Group) TryGo(f func() error) bool { + if g.sem != nil { + select { + case g.sem <- token{}: + // Note: this allows barging iff channels in general allow barging. + default: + return false + } + } + + g.wg.Add(1) + go func() { + defer g.done() + + if err := f(); err != nil { + g.errOnce.Do(func() { + g.err = err + if g.cancel != nil { + g.cancel(g.err) + } + }) + } + }() + return true +} + +// SetLimit limits the number of active goroutines in this group to at most n. +// A negative value indicates no limit. +// +// Any subsequent call to the Go method will block until it can add an active +// goroutine without exceeding the configured limit. +// +// The limit must not be modified while any goroutines in the group are active. +func (g *Group) SetLimit(n int) { + if n < 0 { + g.sem = nil + return + } + if len(g.sem) != 0 { + panic(fmt.Errorf("errgroup: modify limit while %v goroutines in the group are still active", len(g.sem))) + } + g.sem = make(chan token, n) +} diff --git a/vendor/golang.org/x/sync/errgroup/go120.go b/vendor/golang.org/x/sync/errgroup/go120.go new file mode 100644 index 00000000..f93c740b --- /dev/null +++ b/vendor/golang.org/x/sync/errgroup/go120.go @@ -0,0 +1,13 @@ +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build go1.20 + +package errgroup + +import "context" + +func withCancelCause(parent context.Context) (context.Context, func(error)) { + return context.WithCancelCause(parent) +} diff --git a/vendor/golang.org/x/sync/errgroup/pre_go120.go b/vendor/golang.org/x/sync/errgroup/pre_go120.go new file mode 100644 index 00000000..88ce3343 --- /dev/null +++ b/vendor/golang.org/x/sync/errgroup/pre_go120.go @@ -0,0 +1,14 @@ +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build !go1.20 + +package errgroup + +import "context" + +func withCancelCause(parent context.Context) (context.Context, func(error)) { + ctx, cancel := context.WithCancel(parent) + return ctx, func(error) { cancel() } +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 2a7547a9..e309e32a 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -117,6 +117,9 @@ golang.org/x/net/proxy ## explicit; go 1.17 golang.org/x/oauth2 golang.org/x/oauth2/internal +# golang.org/x/sync v0.7.0 +## explicit; go 1.18 +golang.org/x/sync/errgroup # golang.org/x/sys v0.5.0 ## explicit; go 1.17 golang.org/x/sys/internal/unsafeheader From a3cf66a80f2e4344a6ccc95723a91997dbc57dbd Mon Sep 17 00:00:00 2001 From: Aleksey Pesternikov Date: Thu, 18 Apr 2024 13:31:28 -0700 Subject: [PATCH 2/7] cleanup local deploy branches if remotes are gone or not created yet --- gitops/exec/exec.go | 5 +++-- gitops/git/git.go | 30 +++++++++++++++++++++++++++--- gitops/prer/create_gitops_prs.go | 2 +- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/gitops/exec/exec.go b/gitops/exec/exec.go index cb0b5ae5..3be02e50 100644 --- a/gitops/exec/exec.go +++ b/gitops/exec/exec.go @@ -31,10 +31,11 @@ func Ex(dir, name string, arg ...string) (output string, err error) { // Mustex executes the command name arg... in directory dir // it will exit with fatal error if execution was not successful -func Mustex(dir, name string, arg ...string) { - _, err := Ex(dir, name, arg...) +func Mustex(dir, name string, arg ...string) string { + ret, err := Ex(dir, name, arg...) if err != nil { log.Fatalf("ERROR: %s", err) } + return ret } diff --git a/gitops/git/git.go b/gitops/git/git.go index 7fbe081b..2b3e2f0e 100644 --- a/gitops/git/git.go +++ b/gitops/git/git.go @@ -17,6 +17,7 @@ import ( "os" oe "os/exec" "path/filepath" + "strings" "github.com/fasterci/rules_gitops/gitops/exec" ) @@ -48,8 +49,10 @@ func Clone(repo, dir, mirrorDir, primaryBranch, gitopsPath string) (*Repo, error }, nil } -func CloneOrCheckout(repo, dir, mirrorDir, primaryBranch, gitopsPath string) (r *Repo, err error) { +func CloneOrCheckout(repo, dir, mirrorDir, primaryBranch, gitopsPath, branchPrefix string) (r *Repo, err error) { + newRepo := false if _, err = os.Stat(dir + "/.git"); os.IsNotExist(err) { + newRepo = true if err = os.MkdirAll(filepath.Dir(dir), os.ModePerm); err != nil && !os.IsExist(err) { return nil, err } @@ -58,20 +61,41 @@ func CloneOrCheckout(repo, dir, mirrorDir, primaryBranch, gitopsPath string) (r } else { exec.Mustex("", "git", "clone", "-n", repo, dir) } - } else { //existing repo exec.Mustex(dir, "git", "remote", "set-url", "origin", repo) - exec.Mustex(dir, "git", "fetch", "origin", "--prune") exec.Mustex(dir, "git", "reset", "--hard") } exec.Mustex(dir, "git", "checkout", "-f", primaryBranch) + if !newRepo { + PruneLocalBranches(dir, branchPrefix) + } return &Repo{ Dir: dir, }, nil } +// PruneLocalBranches removes local branches not present in the remote repository +func PruneLocalBranches(dir, branchprefix string) { + exec.Mustex(dir, "git", "fetch", "origin", "--prune") + branches := exec.Mustex(dir, "git", "for-each-ref", "--format", "%(refname) %(upstream:track)", "refs/heads/"+branchprefix) + // returned format: + // refs/heads/deploy/dev [gone] + // refs/heads/deploy/prod [gone] + // refs/heads/master + v := strings.Split(branches, "\n") + for _, line := range v { + line := strings.TrimSpace(line) + ref, remote, ok := strings.Cut(line, " ") + if (!ok || remote == "[gone]") && strings.HasPrefix(ref, "refs/heads/"+branchprefix) { + ref = strings.TrimPrefix(ref, "refs/heads/") + exec.Mustex(dir, "git", "branch", "-D", ref) + } + + } +} + // Repo is a clone of a git repository. Create with Clone, and don't // forget to clean it up after. type Repo struct { diff --git a/gitops/prer/create_gitops_prs.go b/gitops/prer/create_gitops_prs.go index a5d41a21..87e1b126 100644 --- a/gitops/prer/create_gitops_prs.go +++ b/gitops/prer/create_gitops_prs.go @@ -173,7 +173,7 @@ func main() { } defer os.RemoveAll(gitopsdir) } - workdir, err := git.CloneOrCheckout(*repo, gitopsdir, *gitMirror, *prInto, *gitopsPath) + workdir, err := git.CloneOrCheckout(*repo, gitopsdir, *gitMirror, *prInto, *gitopsPath, *deployBranchPrefix) if err != nil { log.Fatalf("Unable to clone repo: %v", err) } From f6cfc821e1d199a3065ac2ceb9bf0e67cb220b3f Mon Sep 17 00:00:00 2001 From: Aleksey Pesternikov Date: Fri, 9 Aug 2024 12:21:50 -0700 Subject: [PATCH 3/7] update_vendor --- MODULE.bazel.lock | 52 +------------------ go.mod | 2 +- go.sum | 4 +- vendor/golang.org/x/sync/LICENSE | 4 +- vendor/golang.org/x/sync/errgroup/BUILD | 6 ++- vendor/golang.org/x/sync/errgroup/errgroup.go | 13 +++-- vendor/modules.txt | 4 +- 7 files changed, 21 insertions(+), 64 deletions(-) diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 14f30bfc..5005bee3 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -1678,7 +1678,7 @@ "moduleExtensions": { "//gitops:extensions.bzl%toolchains": { "general": { - "bzlTransitiveDigest": "lYLYpl8Olz+0KEMZGJoRl4qsxo8SZN/RZzUhX7BwZtU=", + "bzlTransitiveDigest": "7KoML+gmGc0zw78Cvm/P9ybt0yMKHvqdlM+SHqm6cn4=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, "envVariables": {}, @@ -1742,16 +1742,6 @@ } }, "recordedRepoMappingEntries": [ - [ - "", - "aspect_bazel_lib", - "aspect_bazel_lib~" - ], - [ - "", - "bazel_gazelle", - "gazelle~" - ], [ "", "bazel_skylib", @@ -1761,46 +1751,6 @@ "", "rules_gitops", "" - ], - [ - "", - "rules_oci", - "rules_oci~" - ], - [ - "", - "rules_pkg", - "rules_pkg~" - ], - [ - "aspect_bazel_lib~", - "bazel_tools", - "bazel_tools" - ], - [ - "bazel_skylib~", - "bazel_skylib", - "bazel_skylib~" - ], - [ - "gazelle~", - "bazel_tools", - "bazel_tools" - ], - [ - "rules_oci~", - "aspect_bazel_lib", - "aspect_bazel_lib~" - ], - [ - "rules_oci~", - "bazel_tools", - "bazel_tools" - ], - [ - "rules_pkg~", - "bazel_tools", - "bazel_tools" ] ] } diff --git a/go.mod b/go.mod index 1e46ff38..f874875d 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/google/go-github/v32 v32.1.0 github.com/xanzy/go-gitlab v0.80.2 golang.org/x/oauth2 v0.8.0 + golang.org/x/sync v0.8.0 k8s.io/api v0.26.1 k8s.io/apimachinery v0.26.1 k8s.io/client-go v0.26.1 @@ -53,7 +54,6 @@ require ( github.com/vbatts/tar-split v0.11.3 // indirect golang.org/x/crypto v0.14.0 // indirect golang.org/x/net v0.17.0 // indirect - golang.org/x/sync v0.2.0 // indirect golang.org/x/sys v0.15.0 // indirect golang.org/x/term v0.13.0 // indirect golang.org/x/text v0.13.0 // indirect diff --git a/go.sum b/go.sum index 0f3c2543..be0f134b 100644 --- a/go.sum +++ b/go.sum @@ -213,8 +213,8 @@ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI= -golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/vendor/golang.org/x/sync/LICENSE b/vendor/golang.org/x/sync/LICENSE index 6a66aea5..2a7cf70d 100644 --- a/vendor/golang.org/x/sync/LICENSE +++ b/vendor/golang.org/x/sync/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2009 The Go Authors. All rights reserved. +Copyright 2009 The Go Authors. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are @@ -10,7 +10,7 @@ notice, this list of conditions and the following disclaimer. copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google LLC nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. diff --git a/vendor/golang.org/x/sync/errgroup/BUILD b/vendor/golang.org/x/sync/errgroup/BUILD index d3d95e61..e487d8e5 100644 --- a/vendor/golang.org/x/sync/errgroup/BUILD +++ b/vendor/golang.org/x/sync/errgroup/BUILD @@ -2,7 +2,11 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library") go_library( name = "go_default_library", - srcs = ["errgroup.go"], + srcs = [ + "errgroup.go", + "go120.go", + "pre_go120.go", + ], importmap = "github.com/fasterci/rules_gitops/vendor/golang.org/x/sync/errgroup", importpath = "golang.org/x/sync/errgroup", visibility = ["//visibility:public"], diff --git a/vendor/golang.org/x/sync/errgroup/errgroup.go b/vendor/golang.org/x/sync/errgroup/errgroup.go index cbee7a4e..948a3ee6 100644 --- a/vendor/golang.org/x/sync/errgroup/errgroup.go +++ b/vendor/golang.org/x/sync/errgroup/errgroup.go @@ -4,6 +4,9 @@ // Package errgroup provides synchronization, error propagation, and Context // cancelation for groups of goroutines working on subtasks of a common task. +// +// [errgroup.Group] is related to [sync.WaitGroup] but adds handling of tasks +// returning errors. package errgroup import ( @@ -20,7 +23,7 @@ type token struct{} // A zero Group is valid, has no limit on the number of active goroutines, // and does not cancel on error. type Group struct { - cancel func() + cancel func(error) wg sync.WaitGroup @@ -43,7 +46,7 @@ func (g *Group) done() { // returns a non-nil error or the first time Wait returns, whichever occurs // first. func WithContext(ctx context.Context) (*Group, context.Context) { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := withCancelCause(ctx) return &Group{cancel: cancel}, ctx } @@ -52,7 +55,7 @@ func WithContext(ctx context.Context) (*Group, context.Context) { func (g *Group) Wait() error { g.wg.Wait() if g.cancel != nil { - g.cancel() + g.cancel(g.err) } return g.err } @@ -76,7 +79,7 @@ func (g *Group) Go(f func() error) { g.errOnce.Do(func() { g.err = err if g.cancel != nil { - g.cancel() + g.cancel(g.err) } }) } @@ -105,7 +108,7 @@ func (g *Group) TryGo(f func() error) bool { g.errOnce.Do(func() { g.err = err if g.cancel != nil { - g.cancel() + g.cancel(g.err) } }) } diff --git a/vendor/modules.txt b/vendor/modules.txt index b0a0a663..f9579642 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -212,8 +212,8 @@ golang.org/x/net/proxy ## explicit; go 1.17 golang.org/x/oauth2 golang.org/x/oauth2/internal -# golang.org/x/sync v0.2.0 -## explicit +# golang.org/x/sync v0.8.0 +## explicit; go 1.18 golang.org/x/sync/errgroup # golang.org/x/sys v0.15.0 ## explicit; go 1.18 From 3704e843c3c1b23b2f32d55df752f9f7d9700f33 Mon Sep 17 00:00:00 2001 From: Aleksey Pesternikov Date: Mon, 12 Aug 2024 18:42:14 -0700 Subject: [PATCH 4/7] run prer from a rule --- gitops/create_gitops_prs.tpl.sh | 7 ++ gitops/git/git.go | 19 +++-- gitops/gitops.bzl | 132 +++++++++++++++++++++++++++++++ gitops/prer/create_gitops_prs.go | 2 +- gitops/update_gitops_targets.sh | 20 +++++ 5 files changed, 169 insertions(+), 11 deletions(-) create mode 100644 gitops/create_gitops_prs.tpl.sh create mode 100644 gitops/gitops.bzl create mode 100755 gitops/update_gitops_targets.sh diff --git a/gitops/create_gitops_prs.tpl.sh b/gitops/create_gitops_prs.tpl.sh new file mode 100644 index 00000000..12ea8f47 --- /dev/null +++ b/gitops/create_gitops_prs.tpl.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -x +set -e + +GIT_COMMIT=$(git rev-parse HEAD) + +%{prer} --git_commit=$GIT_COMMIT %{params} "${@}" diff --git a/gitops/git/git.go b/gitops/git/git.go index 2b3e2f0e..6f2238a6 100644 --- a/gitops/git/git.go +++ b/gitops/git/git.go @@ -68,7 +68,8 @@ func CloneOrCheckout(repo, dir, mirrorDir, primaryBranch, gitopsPath, branchPref } exec.Mustex(dir, "git", "checkout", "-f", primaryBranch) if !newRepo { - PruneLocalBranches(dir, branchPrefix) + exec.Mustex(dir, "git", "fetch", "origin", "--prune") + DeleteLocalBranches(dir, branchPrefix) } return &Repo{ @@ -76,19 +77,17 @@ func CloneOrCheckout(repo, dir, mirrorDir, primaryBranch, gitopsPath, branchPref }, nil } -// PruneLocalBranches removes local branches not present in the remote repository -func PruneLocalBranches(dir, branchprefix string) { - exec.Mustex(dir, "git", "fetch", "origin", "--prune") - branches := exec.Mustex(dir, "git", "for-each-ref", "--format", "%(refname) %(upstream:track)", "refs/heads/"+branchprefix) +// DeleteLocalBranches removes local branches by prefix. +func DeleteLocalBranches(dir, branchprefix string) { + branches := exec.Mustex(dir, "git", "for-each-ref", "--format", "%(refname)", "refs/heads/"+branchprefix) // returned format: - // refs/heads/deploy/dev [gone] - // refs/heads/deploy/prod [gone] + // refs/heads/deploy/dev + // refs/heads/deploy/prod // refs/heads/master v := strings.Split(branches, "\n") for _, line := range v { - line := strings.TrimSpace(line) - ref, remote, ok := strings.Cut(line, " ") - if (!ok || remote == "[gone]") && strings.HasPrefix(ref, "refs/heads/"+branchprefix) { + ref := strings.TrimSpace(line) + if strings.HasPrefix(ref, "refs/heads/"+branchprefix) { ref = strings.TrimPrefix(ref, "refs/heads/") exec.Mustex(dir, "git", "branch", "-D", ref) } diff --git a/gitops/gitops.bzl b/gitops/gitops.bzl new file mode 100644 index 00000000..a0dda84f --- /dev/null +++ b/gitops/gitops.bzl @@ -0,0 +1,132 @@ +load("@rules_gitops//gitops:provider.bzl", "GitopsArtifactsInfo") + +def __create_gitops_prs_impl(ctx): + src_by_train = {} + for src in ctx.attr.srcs: + gai = src[GitopsArtifactsInfo] + if not gai.deployment_branch in src_by_train: + src_by_train[gai.deployment_branch] = [] + src_by_train[gai.deployment_branch].append(src.files_to_run.executable) + + # print("src_by_train:", src_by_train) + trans_img_pushes = depset(transitive = [obj[GitopsArtifactsInfo].image_pushes for obj in ctx.attr.srcs if obj.files_to_run.executable]).to_list() + params = "" + for deployment_branch in src_by_train.keys(): + executables = src_by_train[deployment_branch] + for exe in executables: + params += "--resolved_binary {}:{} ".format(deployment_branch, exe.short_path) + for exe in trans_img_pushes: + params += "--resolved_push {} ".format(exe.files_to_run.executable.short_path) + if ctx.attr.release_branch: + params += "--release_branch {} ".format(ctx.attr.release_branch) + if ctx.attr.git_repo: + params += "--git_repo {} ".format(ctx.attr.git_repo) + if ctx.attr.gitops_path: + params += "--gitops_path {} ".format(ctx.attr.gitops_path) + if ctx.attr.gitopsdir: + params += "--gitopsdir {} ".format(ctx.attr.gitopsdir) + params += "--push_parallelism {} ".format(ctx.attr.push_parallelism) + if ctx.attr.gitops_pr_into: + params += "--gitops_pr_into {} ".format(ctx.attr.gitops_pr_into) + if ctx.attr.deploy_branch_prefix: + params += "--deploy_branch_prefix {} ".format(ctx.attr.deploy_branch_prefix) + if ctx.attr.deployment_branch_suffix: + params += "--deployment_branch_suffix {} ".format(ctx.attr.deployment_branch_suffix) + if ctx.attr.git_server: + params += "--git_server {} ".format(ctx.attr.git_server) + if ctx.attr.dry_run: + params += "--dry_run " + if ctx.attr.github_repo_owner: + params += "--github_repo_owner {} ".format(ctx.attr.github_repo_owner) + if ctx.attr.github_repo: + params += "--github_repo {} ".format(ctx.attr.github_repo) + + ctx.actions.expand_template( + template = ctx.file._tpl, + substitutions = { + "%{params}": params, + "%{prer}": ctx.executable._prer.short_path, + }, + output = ctx.outputs.executable, + ) + runfiles = ctx.runfiles(files = ctx.files.srcs) + transitive_runfiles = [] + for target in ctx.attr.srcs: + transitive_runfiles.append(target[DefaultInfo].default_runfiles) + transitive_runfiles.append(ctx.attr._prer[DefaultInfo].default_runfiles) + for obj in trans_img_pushes: + transitive_runfiles.append(obj[DefaultInfo].default_runfiles) + runfiles = runfiles.merge_all(transitive_runfiles) + return [ + DefaultInfo( + executable = ctx.outputs.executable, + runfiles = runfiles, + ), + ] + +create_gitops_prs = rule( + doc = """Rule to all required gitops prs for a given k8s_deploy targets + Typical usage is to combine this rule with k8s_deploy to create a single executable that + push images to registry and creates gitops prs + """, + implementation = __create_gitops_prs_impl, + attrs = { + "srcs": attr.label_list( + mandatory = True, + allow_files = False, + providers = [GitopsArtifactsInfo], + doc = "List of gitops targets generated by k8s_deploy. Use update_gitops_targets.sh to update", + ), + "git_repo": attr.string( + doc = "gitops repo to create PRs in.", + ), + "gitops_path": attr.string( + doc = "location to store files in repo.", + ), + "gitopsdir": attr.string( + doc = "do not use temporary directory for gitops, use this directory instead.", + ), + "push_parallelism": attr.int( + doc = "number of parallel pushes to registry", + default = 4, + ), + "gitops_pr_into": attr.string( + doc = "use this branch as the source branch and target for deployment PR", + default = "main", + ), + "release_branch": attr.string( + doc = "release branch to create PRs in.", + ), + "deploy_branch_prefix": attr.string( + doc = "prefix for deployment branches", + ), + "deployment_branch_suffix": attr.string( + doc = "suffix for deployment branches", + ), + "git_server": attr.string( + doc = "git server to create PRs in.", + default = "github", + ), + "dry_run": attr.bool( + doc = "dry run mode", + default = False, + ), + "github_repo_owner": attr.string( + doc = "github repo owner to create PRs in.", + ), + "github_repo": attr.string( + doc = "github repo to create PRs in.", + ), + "_tpl": attr.label( + default = Label("@rules_gitops//gitops:create_gitops_prs.tpl.sh"), + allow_single_file = True, + ), + "_prer": attr.label( + default = Label("@rules_gitops//gitops/prer:create_gitops_prs"), + allow_single_file = True, + cfg = "exec", + executable = True, + ), + }, + executable = True, +) diff --git a/gitops/prer/create_gitops_prs.go b/gitops/prer/create_gitops_prs.go index 87e1b126..64470e11 100644 --- a/gitops/prer/create_gitops_prs.go +++ b/gitops/prer/create_gitops_prs.go @@ -288,7 +288,7 @@ func main() { for _, branch := range updatedGitopsBranches { if *dryRun { - log.Println("dry-run: skipping PR creation: branch ", branch, "into ", *prInto) + log.Println("dry-run: skipping PR creation: branch", branch, "into", *prInto) continue } diff --git a/gitops/update_gitops_targets.sh b/gitops/update_gitops_targets.sh new file mode 100755 index 00000000..f4834d9f --- /dev/null +++ b/gitops/update_gitops_targets.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +# +# Update the gitops targets in the repository. +# This script should be copied to your repository and updated to reflect the local configuration. +# +# CONFIGURATION: +RELEASE_BRANCH=main +TARGET="//..." + +set -euo pipefail +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +q="attr(deployment_branch, \".+\", attr(release_branch_prefix, \"${RELEASE_BRANCH}\", kind(gitops, ${TARGET})))" + +targets=$(bazel query ${q} --output label --noshow_progress) +#convert to ordered starlark array +targets=$(echo "${targets}" | sort | awk '{print " \"" $0 "\","}') +echo "GITOPS_TARGETS_${RELEASE_BRANCH} = [ +${targets} +]" > "${SCRIPT_DIR}/targets.bzl" + From ceaa5527de485fd0ee0dd1e35e839d5a4a07da3c Mon Sep 17 00:00:00 2001 From: Aleksey Pesternikov Date: Sun, 24 Nov 2024 16:37:12 -0800 Subject: [PATCH 5/7] export required file --- gitops/BUILD.bazel | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gitops/BUILD.bazel b/gitops/BUILD.bazel index f2324192..43a7eec5 100644 --- a/gitops/BUILD.bazel +++ b/gitops/BUILD.bazel @@ -12,6 +12,8 @@ load("//gitops/private:kustomize_toolchain.bzl", "current_kustomize_toolchain") package(default_visibility = ["//visibility:public"]) +exports_files(["create_gitops_prs.tpl.sh"]) + toolchain_type( name = "kustomize_toolchain_type", ) From 5ac572a3a3a35a4c5eb57d8ede9f62bba24d824d Mon Sep 17 00:00:00 2001 From: Aleksey Pesternikov Date: Sun, 24 Nov 2024 18:10:55 -0800 Subject: [PATCH 6/7] less noise in push output --- mirror/mirror_image.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mirror/mirror_image.sh b/mirror/mirror_image.sh index 3e87f418..af853dbf 100644 --- a/mirror/mirror_image.sh +++ b/mirror/mirror_image.sh @@ -1,4 +1,4 @@ -#!/bin/bash -x +#!/usr/bin/env bash set -eu function guess_runfiles() { From caaf48ef858f726100ef353c824af918433f51fa Mon Sep 17 00:00:00 2001 From: Aleksey Pesternikov Date: Sun, 24 Nov 2024 19:02:29 -0800 Subject: [PATCH 7/7] do not build with bazel 6 since it is not supported --- .fasterci/config.yaml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.fasterci/config.yaml b/.fasterci/config.yaml index 557e3a84..9f65c136 100644 --- a/.fasterci/config.yaml +++ b/.fasterci/config.yaml @@ -1,5 +1,4 @@ workflows: - - &build_workflow name: Faster CI / build (default bazel ver) on: @@ -43,6 +42,6 @@ workflows: - --test_size_filters=-large,-enormous - <<: *build_workflow - name: Faster CI / build (6.5.0) + name: Faster CI / build (7.4.1) env: - USE_BAZEL_VERSION: "6.5.0" + USE_BAZEL_VERSION: "7.4.1"