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