Sha256: 259980cec14e51054d245f9e3d0bad03f317497391a09d1cdfdfe751ee3b51bf

Contents?: true

Size: 1.58 KB

Versions: 22

Compression:

Stored size: 1.58 KB

Contents

# Copyright 2021 Google LLC
#
# Use of this source code is governed by an MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT.

require_relative "config/environment"
require "docker"

desc "Lists all available samples."
task :list do
  samples = Dir.entries(".").select do |entry|
    File.directory?(File.join(".", entry)) \
     && !%w[. ..].include?(entry) \
     && File.exist?(File.join(".", entry, "application.rb"))
  end
  puts "Available samples: "
  samples.sort.each { |dir| puts "  #{dir}" }
  puts ""
  puts "Run a sample with the command `bundle exec rake run\\[<sample-name>\\]`"
end

desc "Runs a simple ActiveRecord tutorial on a Spanner emulator."
task :run, [:sample] do |_t, args|
  sample = args[:sample]
  unless sample
    puts "Missing argument :sample. Running quickstart sample"
    puts ""
    sample = "quickstart"
  end

  puts "Downloading Spanner emulator image..."
  Docker::Image.create "fromImage" => "gcr.io/cloud-spanner-emulator/emulator:latest"
  puts "Creating Spanner emulator container..."
  container = Docker::Container.create(
    "Image" => "gcr.io/cloud-spanner-emulator/emulator:latest",
    "ExposedPorts" => { "9010/tcp" => {} },
    "HostConfig" => {
      "PortBindings" => {
        "9010/tcp" => [{ "HostPort" => "9010" }]
      }
    }
  )

  begin
    puts "Starting Spanner emulator..."
    container.start!
    Dir.chdir sample do
      sh "ruby ../bin/create_emulator_instance.rb"
      sh "rake db:migrate"
      sh "rake db:seed"
      sh "ruby application.rb"
    end
  ensure
    container.stop!
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
activerecord-spanner-adapter-1.8.0 examples/snippets/Rakefile
activerecord-spanner-adapter-1.6.3 examples/snippets/Rakefile
activerecord-spanner-adapter-1.6.2 examples/snippets/Rakefile
activerecord-spanner-adapter-1.6.1 examples/snippets/Rakefile
activerecord-spanner-adapter-1.6.0 examples/snippets/Rakefile
activerecord-spanner-adapter-1.5.1 examples/snippets/Rakefile
activerecord-spanner-adapter-1.5.0 examples/snippets/Rakefile
activerecord-spanner-adapter-1.4.4 examples/snippets/Rakefile
activerecord-spanner-adapter-1.4.3 examples/snippets/Rakefile
activerecord-spanner-adapter-1.4.2 examples/snippets/Rakefile
activerecord-spanner-adapter-1.4.1 examples/snippets/Rakefile
activerecord-spanner-adapter-1.4.0 examples/snippets/Rakefile
activerecord-spanner-adapter-1.3.1 examples/snippets/Rakefile
activerecord-spanner-adapter-1.2.2 examples/snippets/Rakefile
activerecord-spanner-adapter-1.2.1 examples/snippets/Rakefile
activerecord-spanner-adapter-1.2.0 examples/snippets/Rakefile
activerecord-spanner-adapter-1.1.0 examples/snippets/Rakefile
activerecord-spanner-adapter-1.0.1 examples/snippets/Rakefile
activerecord-spanner-adapter-1.0.0 examples/snippets/Rakefile
activerecord-spanner-adapter-0.7.0 examples/snippets/Rakefile