Sha256: 3287be41d30a35b6aefb8699cd60b327ac55289f7a080ee53c3c017732dc97f5

Contents?: true

Size: 1.2 KB

Versions: 13

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

module Orchestration
  module DockerCompose
    class DatabaseService
      # We dictate which port all database services will run on in their
      # container to simplify port mapping.
      PORT = 3354

      def initialize(config)
        @config = config
      end

      def definition
        return nil if @config.settings.nil?

        adapter = @config.settings.fetch('adapter')
        return nil if adapter == 'sqlite3'

        port = @config.settings.fetch('port')
        {
          'image' => image_from_adapter(adapter),
          'environment' => environment_from_adapter(adapter),
          'ports' => ["#{port}:#{PORT}"]
        }
      end

      private

      def image_from_adapter(adapter)
        {
          'postgresql' => 'library/postgres',
          'mysql2' => 'library/mysql'
        }.fetch(adapter)
      end

      def environment_from_adapter(adapter)
        {
          'postgresql' => {
            'PGPORT' => PORT.to_s,
            'POSTGRES_PASSWORD' => 'password'
          },
          'mysql2' => {
            'MYSQL_ROOT_PASSWORD' => 'password',
            'MYSQL_TCP_PORT' => PORT.to_s
          }
        }.fetch(adapter)
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
orchestration-0.3.3 lib/orchestration/docker_compose/database_service.rb
orchestration-0.3.2 lib/orchestration/docker_compose/database_service.rb
orchestration-0.3.1 lib/orchestration/docker_compose/database_service.rb
orchestration-0.3.0 lib/orchestration/docker_compose/database_service.rb
orchestration-0.2.8 lib/orchestration/docker_compose/database_service.rb
orchestration-0.2.7 lib/orchestration/docker_compose/database_service.rb
orchestration-0.2.6 lib/orchestration/docker_compose/database_service.rb
orchestration-0.2.5 lib/orchestration/docker_compose/database_service.rb
orchestration-0.2.4 lib/orchestration/docker_compose/database_service.rb
orchestration-0.2.3 lib/orchestration/docker_compose/database_service.rb
orchestration-0.2.2 lib/orchestration/docker_compose/database_service.rb
orchestration-0.2.1 lib/orchestration/docker_compose/database_service.rb
orchestration-0.2.0 lib/orchestration/docker_compose/database_service.rb