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

Commit

Permalink
Support get_latest_build_number in the GCS Artifact Registry driver (#9)
Browse files Browse the repository at this point in the history
Enable referencing the latest build with `latest` when using the `build`
flag when using the GCS artifact registry.

Reviewers: rpere, rfaugeroux, joshk
  • Loading branch information
navyapothineni committed Oct 23, 2020
1 parent f0793c1 commit a310f06
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion lib/kube_deploy_tools/artifact_registry/driver_gcs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,21 @@ def get_local_artifact_path(name:, flavor:, local_dir:)
local_artifact_path
end

def get_registry_build_path(project:)
# NOTE: If the naming format changes, it represents a breaking change
# where all past clients will not be able to list/download new builds
# and new clients will not be able to list/download old builds. Change
# with caution.
#
"#{@bucket}/project/#{project}/build"
end

def get_registry_artifact_path(name:, flavor:, project:, build_number:)
# NOTE(joshk): If the naming format changes, it represents a breaking
# change where all past clients will not be able to download new builds and
# new clients will not be able to download old builds. Change with caution.
#
"#{@bucket}/project/#{project}/build/#{build_number}/artifact/#{get_artifact_name(name: name, flavor: flavor)}"
"#{get_registry_build_path(project: project)}/#{build_number}/artifact/#{get_artifact_name(name: name, flavor: flavor)}"
end

def get_artifact_name(name:, flavor:)
Expand Down Expand Up @@ -84,6 +93,18 @@ def download_artifact(input_path, output_dir_path)
output_path
end

def get_latest_build_number(project)
out = Shellrunner.check_call('gsutil', 'ls', get_registry_build_path(project: project))

# pick out the build numbers from the list
build_regex = /([0-9]+)\/$/
build_entries = out.scan(build_regex)

build_entries.
map { |x| x[0].to_s.to_i }.
max.to_s
end

def upload(local_dir:, name:, flavor:, project:, build_number:)
# Pack up contents of each flavor_dir to a correctly named artifact.
flavor_dir = File.join(local_dir, "#{name}_#{flavor}")
Expand Down

0 comments on commit a310f06

Please sign in to comment.