Class: Polyn::Cli::Commands

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/polyn/cli.rb

Overview

Thor commands for the CLI. Subclassed so other classes can be in the CLI namespace

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/polyn/cli.rb', line 45

def self.exit_on_failure?
  true
end

Instance Method Details

#initObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/polyn/cli.rb', line 51

def init
  say "Initializing Polyn schema repository"
  directory "tf", File.join(options.dir, "tf")
  directory "schemas", File.join(options.dir, "schemas")
  template "docker-compose.yml", File.join(options.dir, "docker-compose.yml")
  template "Dockerfile", File.join(options.dir, "Dockerfile")
  template ".dockerignore", File.join(options.dir, ".dockerignore")
  template ".gitignore", File.join(options.dir, ".gitignore")
  template "README.md", File.join(options.dir, "README.md")
  template "Gemfile", File.join(options.dir, "Gemfile")
  run tf_init
  say "Initializing git"
  inside options.dir do
    run "git init"
  end
  say "Repository initialized"
end

#tf_initObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/polyn/cli.rb', line 71

def tf_init
  terraform_root = File.join(options.dir, "tf")
  say "Initializing Terraform"
  inside terraform_root do
    # In a development environment we want developers to work with their own local
    # .tfstate rather than one configured in a remote `backend` intended for
    # production use.
    # https://www.terraform.io/language/settings/backends/configuration
    #
    # Terraform assumes only one backend will be configured and there's no path
    # to switch between local and remote. There's also no way to dynamically load
    # modules. https://github.com/hashicorp/terraform/issues/1439
    # Instead we'll copy a backend config to the terraform root if we're in a production
    # environment
    if polyn_env == "production"
      add_remote_backend(terraform_root) { run "terraform init" }
    else
      run "terraform init"
    end
  end
end

#upObject



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/polyn/cli.rb', line 94

def up
  terraform_root = File.join(Dir.getwd, "tf")
  # We only want to run nats in the docker container if
  # the developer isn't already running nats themselves locally
  if polyn_env == "development" && !nats_running?
    say "Starting NATS"
    run "docker compose up --detach"
  end

  say "Updating JetStream configuration"
  inside "tf" do
    if polyn_env == "production"
      add_remote_backend(terraform_root) { run tf_apply }
    else
      run tf_apply
    end
  end

  say "Updating Polyn schema registry"
  Polyn::Cli::SchemaLoader.new(self).load_schemas
end