Class: Dev::Common::Platform

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

Constant Summary collapse

ALLOWED_ARCHITECTURES =
%w(arm64 amd64).freeze

Instance Method Summary collapse

Instance Method Details

#architectureObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/firespring_dev_commands/platform.rb', line 17

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



6
7
8
9
10
11
12
13
14
15
# File 'lib/firespring_dev_commands/platform.rb', line 6

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