Sha256: 20c389edc375a986283d8f2b19b5218cda9ccfc470dd0e40733d5f2a3e294e2e

Contents?: true

Size: 1.88 KB

Versions: 7

Compression:

Stored size: 1.88 KB

Contents

# typed: strict

module Kuby
  module Docker
    class Alpine < Distro
      SHELL_EXE = T.let('/bin/sh'.freeze, String)

      DEFAULT_PACKAGES = T.let([
        [:ca_certificates, nil],
        [:nodejs, '12.14.1'],
        [:yarn, '1.21.1'],
        [:c_toolchain, nil],
        [:tzdata, nil],
        [:git, nil]
      ].freeze, T::Array[[Symbol, T.nilable(String)]])

      sig { returns(Layer) }
      attr_reader :phase

      sig { override.params(packages: T::Array[Distro::PackageImpl], into: Dockerfile).void }
      def install(packages, into:)
        dockerfile = into
        install_managed(packages, dockerfile)
        install_unmanaged(packages, dockerfile)
      end

      sig { override.returns(T::Array[[Symbol, T.nilable(String)]]) }
      def default_packages
        DEFAULT_PACKAGES
      end

      sig { override.returns(String) }
      def shell_exe
        SHELL_EXE
      end

      private

      sig { params(packages: T::Array[Distro::PackageImpl], dockerfile: Dockerfile).void }
      def install_managed(packages, dockerfile)
        pkgs = T.cast(packages.select(&:managed?), T::Array[Distro::ManagedPackageImpl])

        unless pkgs.empty?
          package_names = pkgs.map { |pkg| pkg.package_name_for(:alpine) }
          dockerfile.run(
            "apk add --no-cache #{package_names.join(' ')}"
          )
        end
      end

      sig { params(packages: T::Array[Distro::PackageImpl], dockerfile: Dockerfile).void }
      def install_unmanaged(packages, dockerfile)
        packages
          .reject(&:managed?)
          .each do |package|
            if package.respond_to?(:install_on_alpine)
              package.send(:install_on_alpine, dockerfile)
            else
              raise UnsupportedDistroError, "Couldn't install #{package.name} "\
                "because alpine is an unsupported distro"
            end
          end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
kuby-core-0.17.0 lib/kuby/docker/alpine.rb
kuby-core-0.16.1 lib/kuby/docker/alpine.rb
kuby-core-0.16.0 lib/kuby/docker/alpine.rb
kuby-core-0.15.0 lib/kuby/docker/alpine.rb
kuby-core-0.14.0 lib/kuby/docker/alpine.rb
kuby-core-0.13.0 lib/kuby/docker/alpine.rb
kuby-core-0.12.0 lib/kuby/docker/alpine.rb