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 | |
| require "json" | |
| require "net/http" | |
| require "uri" | |
| require "yaml" | |
| CONFIG = YAML.load_file("config/deploy.yml") | |
| ACCESSORIES = CONFIG["accessories"] | |
| 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") | |
| response = Net::HTTP.get_response(url) | |
| if response.is_a?(Net::HTTPSuccess) | |
| data = JSON.parse(response.body) | |
| # Take only 20 results, it should be enough | |
| data["results"].take(20).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