Skip to content

Instantly share code, notes, and snippets.

@luizkowalski
Last active August 30, 2024 18:46
Show Gist options
  • Select an option

  • Save luizkowalski/6e7eb3b318dacc01c80754d2599f47ee to your computer and use it in GitHub Desktop.

Select an option

Save luizkowalski/6e7eb3b318dacc01c80754d2599f47ee to your computer and use it in GitHub Desktop.
Check if there are any new images available for Kamal accessories
#!/usr/bin/env ruby
# frozen_string_literal: true
# lives in .kamal/update
require "json"
require "net/http"
require "uri"
require "yaml"
CONFIG = YAML.load_file("config/deploy.yml")
ACCESSORIES = CONFIG["accessories"]
MAX_RESULTS = 30
ACCESSORIES.each_value do |configs|
image, tag = configs["image"].split(":")
next puts "πŸ˜” Skipping #{image}, not supported...yet\n\n" if image.start_with?("gcr.io", "ghcr.io", "quay.io")
image = image.gsub("lscr.io/", "") # Remove `lscr.io/` from linuxserver images
namespace, repository = image.include?("/") ? image.split("/") : ["library", image]
puts "πŸ‘€ Checking image updates for #{image} (Current version: #{tag})"
url = URI("https://hub.docker.com/v2/repositories/#{namespace}/#{repository}/tags?page_size=#{MAX_RESULTS}")
response = Net::HTTP.get_response(url)
if response.is_a?(Net::HTTPSuccess)
data = JSON.parse(response.body)
data["results"].each do |result|
if Gem::Version.new(tag) < Gem::Version.new(result["name"])
# when tag is `11.2.0-ubuntu`, Gem::Version.new("11.2.0-ubuntu") < Gem::Version.new("11.2.0") and it's not a new version
next if tag.start_with?(result["name"])
break puts " πŸŽ‰ New version available: #{result['name']}"
end
rescue StandardError
# Skip, `Gem::Version.new` fails for "latest" tag for example
next
end
puts "\n"
else
puts "πŸ’£ Error: #{response.code}\n\n"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment