Last active
August 30, 2024 18:46
-
-
Save luizkowalski/6e7eb3b318dacc01c80754d2599f47ee to your computer and use it in GitHub Desktop.
Check if there are any new images available for Kamal accessories
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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