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
# 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 do |name, configs|
image, tag = configs["image"].split(":")
if image.start_with?("gcr.io")
puts "Skipping #{image}, not supported yet"
next
end
puts "Checking image updates for #{image} (Current version: #{tag})"
image = image.gsub("lscr.io/", "") # Remove `lscr.io/` from linuxserver images
url = URI("https://hub.docker.com/v2/repositories/#{image}/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"])
if tag.start_with?(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
end
puts " ~> New version available: #{result["name"]}"
break
end
rescue
# Skip
next
end
else
puts "Error: #{response.code}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment