Sha256: 11dcffaa6bbd9f543d63bb1bea23835a68d982db8117d53eff879b8a3c1253dd

Contents?: true

Size: 1.42 KB

Versions: 16

Compression:

Stored size: 1.42 KB

Contents

require 'thor/shell'
require 'docker-sync/preconditions/strategy'

module Docker_Sync
  module SyncStrategy
    class Native
      include Thor::Shell

      @options
      @sync_name

      def initialize(sync_name, options)
        @sync_name = sync_name
        @options = options

        begin
          DockerSync::Preconditions::Strategy.instance.docker_available
        rescue Exception => e
          say_status 'error', "#{@sync_name} has been configured to sync with native docker volume, but docker is not found", :red
          say_status 'error', e.message, :red
          exit 1
        end
      end

      def run
        create_volume
      end

      def sync
        # noop
      end

      def get_volume_name
        @sync_name
      end

      def start_container
        # noop
      end

      def clean
        delete_volume
      end

      def stop
        # noop
      end

      private

      def create_volume
        run_cmd "docker volume create --opt type=none --opt device=\"#{@options['src']}\" --opt o=bind "\
          "--name #{get_volume_name}"

        say_status 'success', "Docker volume for #{get_volume_name} created", :white
      end

      def delete_volume
        run_cmd "docker volume ls -q | grep #{get_volume_name} && docker volume rm #{get_volume_name}"
      end

      def run_cmd(cmd)
        say_status 'command', cmd, :white if @options['verbose']

        `#{cmd}`
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
docker-sync-0.4.6 lib/docker-sync/sync_strategy/native.rb
docker-sync-0.4.5 lib/docker-sync/sync_strategy/native.rb
docker-sync-0.4.5.beta1 lib/docker-sync/sync_strategy/native.rb
docker-sync-0.4.4 lib/docker-sync/sync_strategy/native.rb
docker-sync-0.4.4.beta2 lib/docker-sync/sync_strategy/native.rb
docker-sync-0.4.4.beta1 lib/docker-sync/sync_strategy/native.rb
docker-sync-0.4.3 lib/docker-sync/sync_strategy/native.rb
docker-sync-0.4.3.pre.beta1 lib/docker-sync/sync_strategy/native.rb
docker-sync-0.4.2 lib/docker-sync/sync_strategy/native.rb
docker-sync-0.4.1 lib/docker-sync/sync_strategy/native.rb
docker-sync-0.4.1.pre.beta2 lib/docker-sync/sync_strategy/native.rb
docker-sync-0.4.1.pre.beta1 lib/docker-sync/sync_strategy/native.rb
docker-sync-0.4.0 lib/docker-sync/sync_strategy/native.rb
docker-sync-0.4.0.pre.beta2 lib/docker-sync/sync_strategy/native.rb
docker-sync-0.4.0.pre.beta1 lib/docker-sync/sync_strategy/native.rb
docker-sync-0.3.6 lib/docker-sync/sync_strategy/native.rb