Sha256: 83394c09d362022701b7f37916efc19d09291d76db73a494024d9a27b507a3a7

Contents?: true

Size: 1.49 KB

Versions: 3

Compression:

Stored size: 1.49 KB

Contents

require "sct_core"

require_relative "docker"

module Shell
  class Php < Docker

    attr_accessor :make

    # Configure the Yarn command
    def self.config
      self.set_image("eu.gcr.io/dev-pasc-vcdm/proactive-base:latest", true)
      self.set_pwd_as_volume("/var/www")
      self.set_current_user_and_group
      self.set_entrypoint("php")
      self.set_environment_variables(get_service_ip_and_port)
    end

    def self.get_service_ip_and_port
      service_names = %w[mysql-service redis-service]
      environment_variables = {}

      minikube_status

      service_names.each { |service_name|
        url = `#{SctCore::Helper.minikube} service #{service_name} --url`

        ip_and_port = url.match /(?<ip>[0-9]+(?:\.[0-9]+){3}):(?<port>[0-9]+)/

        case service_name
        when "mysql-service"
          environment_variables.store("DB_HOST", ip_and_port[:ip])
          environment_variables.store("DB_PORT", ip_and_port[:port])
        when "redis-service"
          environment_variables.store("REDIS_HOST", ip_and_port[:ip])
          environment_variables.store("REDIS_PORT", ip_and_port[:port])
        end
      }

      return environment_variables
    end

    def self.minikube_status
      output = `#{SctCore::Helper.minikube} status`

      if output.scan(/Running/).length != 3 && output.scan(/Configured/).length != 1
        UI.important("Please check your minikube status. If all services are stopped you should start the minikube first.")
        exit
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sct-0.1.25 shell/lib/shell/docker/php.rb
sct-0.1.24 shell/lib/shell/docker/php.rb
sct-0.1.23 shell/lib/shell/docker/php.rb