|
| 1 | +## |
| 2 | +## mkimage.sh wrapper. |
| 3 | +## usage: |
| 4 | +## |
| 5 | +## git clone --branch v19.03.15 --depth 1 https://github.com/docker/docker-ce.git ~/go/src/github.com/docker/docker-ce |
| 6 | +## rake mkimage TAG=minimum2scp/debian:latest |
| 7 | +## |
| 8 | + |
| 9 | +require 'erb' |
| 10 | +require 'json' |
| 11 | +require 'rake/clean' |
| 12 | +require 'tmpdir' |
| 13 | +require 'tempfile' |
| 14 | + |
| 15 | +CLOBBER.include 'build.log', 'debian-packages.json', 'README.md' |
| 16 | + |
| 17 | +task :default => ['README.md'] |
| 18 | + |
| 19 | +desc 'create mkimage.sh log file' |
| 20 | +file 'build.log' do |
| 21 | + Rake::Task[:mkimage].invoke |
| 22 | +end |
| 23 | + |
| 24 | +desc 'run mkimage.sh' |
| 25 | +task :mkimage do |
| 26 | + tag_option = ENV['TAG'] ? "-t #{ENV['TAG']}" : '' |
| 27 | + debootstrap_options = %w[ |
| 28 | + --arch=amd64 --variant=minbase --components=main --no-merged-usr |
| 29 | + ] |
| 30 | + debootstrap_options << "--cache-dir=#{ENV['DEBOOTSTRAP_CACHE_DIR']}" if ENV['DEBOOTSTRAP_CACHE_DIR'] |
| 31 | + debootstrap_options << 'bookworm' << 'http://deb.debian.org/debian' |
| 32 | + debootstrap_options = debootstrap_options.join(' ') |
| 33 | + env = ENV.select{|k,v| ['TMPDIR', 'http_proxy'].include?(k) }.map{|k,v| "#{k}=#{v}"}.join(' ') |
| 34 | + mkimage_sh = [ |
| 35 | + "#{ENV.fetch('GOPATH', "#{ENV['HOME']}/go")}/src/github.com/moby/moby/contrib/mkimage.sh", |
| 36 | + "#{ENV.fetch('GOPATH', "#{ENV['HOME']}/go")}/src/github.com/docker/docker-ce/components/engine/contrib/mkimage.sh", |
| 37 | + # '/usr/share/docker-ce/contrib/mkimage.sh', |
| 38 | + ].find{|f| File.executable?(f) } |
| 39 | + unless mkimage_sh |
| 40 | + raise "mkimage.sh not found" |
| 41 | + end |
| 42 | + sh "sudo #{env} #{mkimage_sh} #{tag_option} debootstrap #{debootstrap_options} | tee build.log" |
| 43 | +end |
| 44 | + |
| 45 | +desc 'update debian-packages.json' |
| 46 | +file 'debian-packages.json' => ['build.log'] do |t| |
| 47 | + tag = ENV['TAG'] || 'minimum2scp/debian:latest' |
| 48 | + tmpfile = Tempfile.new('packages') |
| 49 | + tmpfile.close |
| 50 | + fields = %w[ |
| 51 | + Architecture Conflicts Breaks Depends Enhances Essential Installed-Size Origin Package |
| 52 | + Pre-Depends Priority Provides Recommends Replace Section Status Suggests Version |
| 53 | + binary:Package binary:Summary db:Status-Abbrev db:Status-Want db:Status-Status db:Status-Eflag |
| 54 | + source:Package source:Version |
| 55 | + ] |
| 56 | + field_fmt = fields.map{|f| "${#{f}}"}.join("\\t") + "\\n" |
| 57 | + sh %Q[docker run --rm #{tag} dpkg-query -f '#{field_fmt}' -W > #{tmpfile.path}], :verbose => false |
| 58 | + packages = File.readlines(tmpfile.path).map(&:chomp).map{|row| Hash[fields.zip(row.split("\t"))]} |
| 59 | + File.open(t.name, "w") do |fh| |
| 60 | + fh << JSON.pretty_generate(packages) |
| 61 | + end |
| 62 | +end |
| 63 | + |
| 64 | +desc 'update README.md' |
| 65 | +file 'README.md' => ['README.md.erb', 'debian-packages.json'] do |t| |
| 66 | + packages = JSON.parse(File.read('debian-packages.json')) |
| 67 | + File.open(t.name, "w") do |fh| |
| 68 | + fh << ERB.new(File.read('README.md.erb'), trim_mode: '-').result(binding) |
| 69 | + end |
| 70 | +end |
| 71 | + |
0 commit comments