Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport adding latest_major and latest_minor tags #3644

Merged
merged 5 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 20 additions & 23 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,40 +191,37 @@ deploy_to_reliability_env:
UPSTREAM_PROJECT_NAME: $CI_PROJECT_NAME
UPSTREAM_COMMIT_SHA: $CI_COMMIT_SHA

deploy_to_docker_registries:
prepare_image_destinations:
stage: deploy
tags: ["arch:amd64"]
image: $DOCKER_REGISTRY/images/mirror/ruby:3.2.2
rules:
- if: "$POPULATE_CACHE"
- if: '$POPULATE_CACHE'
when: never
- if: $CI_COMMIT_TAG =~ /^v(\d+)\.(\d+)\.(\d+)$/ # Exclude prerelease
when: delayed
start_in: 1 day
- if: $CI_COMMIT_TAG =~ /^v(\d+)\.(\d+)\.(\d+)$/ # Exclude prerelease
when: always
- when: manual
allow_failure: true
trigger:
project: DataDog/public-images
branch: main
strategy: depend
variables:
IMG_SOURCES: ghcr.io/datadog/dd-trace-rb/dd-lib-ruby-init:$CI_COMMIT_TAG
IMG_DESTINATIONS: dd-lib-ruby-init:$CI_COMMIT_TAG
IMG_SIGNING: "false"
script:
- ruby -v
- gem -v
- bundle -v
- ./.gitlab/check_gem_presence.rb $CI_COMMIT_TAG
- echo "IMG_DESTINATIONS=$(./.gitlab/prepare_image_destinations.rb dd-lib-ruby-init $CI_COMMIT_TAG)" >> build.env
artifacts:
reports:
dotenv: build.env

deploy_latest_tag_to_docker_registries:
deploy_to_docker_registries:
stage: deploy
rules:
- if: "$POPULATE_CACHE"
when: never
- if: $CI_COMMIT_TAG =~ /^v(\d+)\.(\d+)\.(\d+)$/ && $CI_COMMIT_BRANCH == 'master' # Exclude prerelease and only for master branch
when: delayed
start_in: 1 day
- when: manual
allow_failure: true
needs:
- job: prepare_image_destinations
artifacts: true
trigger:
project: DataDog/public-images
branch: main
strategy: depend
variables:
IMG_SOURCES: ghcr.io/datadog/dd-trace-rb/dd-lib-ruby-init:$CI_COMMIT_TAG
IMG_DESTINATIONS: dd-lib-ruby-init:latest
IMG_DESTINATIONS: $IMG_DESTINATIONS
IMG_SIGNING: "false"
37 changes: 37 additions & 0 deletions .gitlab/check_gem_presence.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env ruby

require 'bundler/inline'

gemfile { gem 'gems', source: 'https://rubygems.org' }

require 'rubygems'
require 'gems'

version = ARGV[0].chomp
version = version.delete_prefix('v') if version.start_with?('v')

candidate = Gem::Version.new(version)

retry_count = 0
max_retries = 60
interval = 60

loop do
versions = Gems.versions('ddtrace').map { |h| Gem::Version.new(h['number']) }

if versions.include?(candidate)
puts "Gem version #{candidate} found!"
exit 0
else
retry_count += 1
puts "Attempt(#{retry_count}): Gem 'ddtrace' version '#{candidate}' not found."

if retry_count >= max_retries
puts "Max retries(#{max_retries}) reached, stopping..."
exit 1
else
puts "Retrying in #{interval} seconds..."
sleep interval
end
end
end
44 changes: 44 additions & 0 deletions .gitlab/prepare_image_destinations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env ruby

require 'bundler/inline'

gemfile { gem 'gems', source: 'https://rubygems.org' }

require 'rubygems'
require 'gems'

image_name = ARGV[0].chomp
version = ARGV[1].chomp
version = version.delete_prefix('v') if version.start_with?('v')

candidate = Gem::Version.new(version)
versions = Gems.versions('ddtrace').map { |h| Gem::Version.new(h['number']) }

# Make sure candidate has already been published to 'https://rubygems.org'
unless versions.include?(candidate)
warn "Version #{candidate} not found in RubyGems"
exit 1
end

# Skip pre-releases
if candidate.prerelease?
warn 'No tags for pre-releases'
exit 1
end

major, minor, = candidate.to_s.split('.')
current_major_versions = versions.select { |v| v.to_s.start_with?("#{major}.") }

tags = []

# `ddtrace` is the gem name on 1.x-stable branch, releasing from this branch means it won't be tagged with `latest`
#
# `latest` tag will be carried over by 2.x version of the gem named `datadog` on `master` branch
tags << "v#{major}" if current_major_versions.all? { |v| candidate >= v }
tags << "v#{major}.#{minor}"
tags << "v#{candidate}"

# $stdout.puts "tags: #{tags}" # Uncomment for debugging

destinations = tags.map { |tag| "#{image_name}:#{tag}" }
$stdout.puts destinations.join(',')
Loading