Class: Dev::Common::Platform

Inherits:
Object
  • Object
show all
Defined in:
lib/firespring_dev_commands/platform.rb

Overview

Class which returns information about the current platform

Constant Summary collapse

ALLOWED_ARCHITECTURES =

Constant containing all supported architectures

%w(arm64 amd64).freeze

Instance Method Summary collapse

Instance Method Details

#architectureObject

Determine the platform architecture If one was specified in the DOCKER_ARCHITECTURE variable, use it Otherwise, use the RUBY_PLATFORM built-in to auto-detect and architecture



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/firespring_dev_commands/platform.rb', line 23

def architecture
  docker_architecture = ENV['DOCKER_ARCHITECTURE'].to_s.strip.downcase
  if docker_architecture.empty?
    determine_compute_architecture
  else
    raise "Missing 'linux/' prefix in DOCKER_ARCHITECTURE: #{docker_architecture}" unless docker_architecture.start_with?('linux/')

    architecture_name = docker_architecture.split('/')[1]
    unless ALLOWED_ARCHITECTURES.include?(architecture_name)
      raise "Invalid DOCKER_ARCHITECTURE: #{architecture_name}. Allowed architectures are #{ALLOWED_ARCHITECTURES.join(', ')}"
    end

    docker_architecture
  end
end

#determine_compute_architectureObject

Normalize the ruby platform to return a docker platform architecture format



9
10
11
12
13
14
15
16
17
18
# File 'lib/firespring_dev_commands/platform.rb', line 9

def determine_compute_architecture
  case RUBY_PLATFORM
  when /x86_64|amd64/
    'linux/amd64' # 64-bit Intel/AMD architecture
  when /arm|aarch64/
    'linux/arm64' # ARM architecture
  else
    raise 'Unknown or unsupported architecture'
  end
end