Skip to content
This repository was archived by the owner on Jun 29, 2023. It is now read-only.

Commit a310f06

Browse files
Support get_latest_build_number in the GCS Artifact Registry driver (#9)
Enable referencing the latest build with `latest` when using the `build` flag when using the GCS artifact registry. Reviewers: rpere, rfaugeroux, joshk
1 parent f0793c1 commit a310f06

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

lib/kube_deploy_tools/artifact_registry/driver_gcs.rb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,21 @@ def get_local_artifact_path(name:, flavor:, local_dir:)
2929
local_artifact_path
3030
end
3131

32+
def get_registry_build_path(project:)
33+
# NOTE: If the naming format changes, it represents a breaking change
34+
# where all past clients will not be able to list/download new builds
35+
# and new clients will not be able to list/download old builds. Change
36+
# with caution.
37+
#
38+
"#{@bucket}/project/#{project}/build"
39+
end
40+
3241
def get_registry_artifact_path(name:, flavor:, project:, build_number:)
3342
# NOTE(joshk): If the naming format changes, it represents a breaking
3443
# change where all past clients will not be able to download new builds and
3544
# new clients will not be able to download old builds. Change with caution.
3645
#
37-
"#{@bucket}/project/#{project}/build/#{build_number}/artifact/#{get_artifact_name(name: name, flavor: flavor)}"
46+
"#{get_registry_build_path(project: project)}/#{build_number}/artifact/#{get_artifact_name(name: name, flavor: flavor)}"
3847
end
3948

4049
def get_artifact_name(name:, flavor:)
@@ -84,6 +93,18 @@ def download_artifact(input_path, output_dir_path)
8493
output_path
8594
end
8695

96+
def get_latest_build_number(project)
97+
out = Shellrunner.check_call('gsutil', 'ls', get_registry_build_path(project: project))
98+
99+
# pick out the build numbers from the list
100+
build_regex = /([0-9]+)\/$/
101+
build_entries = out.scan(build_regex)
102+
103+
build_entries.
104+
map { |x| x[0].to_s.to_i }.
105+
max.to_s
106+
end
107+
87108
def upload(local_dir:, name:, flavor:, project:, build_number:)
88109
# Pack up contents of each flavor_dir to a correctly named artifact.
89110
flavor_dir = File.join(local_dir, "#{name}_#{flavor}")

0 commit comments

Comments
 (0)