polyn-cli 0.1.2 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4ae34f6e95adeb45fa4c421f9eb70960bf599e570a2934365efff5218948d954
4
- data.tar.gz: f72f8e51082c3d68956bd28a78667d6e484e89c7e90aa87dc212ad6c1d7a59e5
3
+ metadata.gz: d0492c19f8164fbaa7e050276f22e3c56c9879f63307840e3551a5d955e190ce
4
+ data.tar.gz: bc6f7f2a6899e28261453509402eaa5955e45e8c163ec9dd79a069c366ffcd8b
5
5
  SHA512:
6
- metadata.gz: cf5e0ff4dae1a5769da3f041f32a579a159c7fe00281d8a8f563e0c0642d55a3632010f47d7351b6e72592cfd781e6eea1d88091a3a51dd12c8e9045809ca040
7
- data.tar.gz: 9a91d45f22c7c2ec3d3dce6e32776607d9da6d17d6c93a811c5219e4ae11cf0b47aa60bd0615fb705d857fe1fcd60df3e20243a92c4cfeb98e8170dfa892c0d6
6
+ metadata.gz: dd5a1d0fc16b7d499d95e8fcc1a6c96a7006da394205ccb5ec969e91c7d3c7c37bed608d6b86b4555c39ca16e1ce70ed91120c0ddac30a5014435abfc301a2e0
7
+ data.tar.gz: d33d503d6dee25d3220532b2731beac35eb90ccc28859475f2cadef9ec03dc19f8b283ef6ba2bbcbbd5a5f31ca81f48564da747e92c17a0e153665fa9381701a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- polyn-cli (0.1.2)
4
+ polyn-cli (0.1.5)
5
5
  dotenv (~> 2.7.6)
6
6
  json_schemer (~> 0.2)
7
7
  nats-pure (~> 2.0.0)
@@ -0,0 +1,8 @@
1
+ #!/bin/bash
2
+
3
+ # We want to keep these commands out of the Docker image
4
+ # build and instead defer them till the container is run.
5
+ # terraform init may require credentials for a remote backend
6
+ # and we don't want that in the image for security reasons.
7
+ bundle exec polyn tf_init
8
+ bundle exec polyn up
@@ -19,26 +19,38 @@ module Polyn
19
19
  def initialize(thor, **opts)
20
20
  @thor = thor
21
21
  @client = NATS.connect(Polyn::Cli.configuration.nats_servers).jetstream
22
- @bucket = client.key_value(opts.fetch(:store_name, STORE_NAME))
22
+ @store_name = opts.fetch(:store_name, STORE_NAME)
23
+ @bucket = client.key_value(@store_name)
23
24
  @cloud_event_schema = Polyn::Cli::CloudEvent.to_h.freeze
24
25
  @events_dir = opts.fetch(:events_dir, File.join(Dir.pwd, "events"))
25
26
  @events = {}
27
+ @existing_events = {}
26
28
  end
27
29
 
28
30
  def load_events
29
31
  thor.say "Loading events into the Polyn event registry from '#{events_dir}'"
30
32
  read_events
33
+ load_existing_events
31
34
 
32
35
  events.each do |name, event|
33
36
  bucket.put(name, JSON.generate(event))
34
37
  end
35
38
 
39
+ delete_missing_events
40
+
36
41
  true
37
42
  end
38
43
 
39
44
  private
40
45
 
41
- attr_reader :thor, :events, :client, :bucket, :cloud_event_schema, :events_dir
46
+ attr_reader :thor,
47
+ :events,
48
+ :client,
49
+ :bucket,
50
+ :cloud_event_schema,
51
+ :events_dir,
52
+ :store_name,
53
+ :existing_events
42
54
 
43
55
  def read_events
44
56
  event_files = Dir.glob(File.join(events_dir, "/**/*.json"))
@@ -95,6 +107,32 @@ module Polyn
95
107
  }),
96
108
  })
97
109
  end
110
+
111
+ def load_existing_events
112
+ sub = client.subscribe("#{key_prefix}.>")
113
+
114
+ loop do
115
+ msg = sub.next_msg
116
+ existing_events[msg.subject.gsub("#{key_prefix}.", "")] = msg.data unless msg.data.empty?
117
+ # A timeout is the only mechanism given to indicate there are no
118
+ # more messages
119
+ rescue NATS::IO::Timeout
120
+ break
121
+ end
122
+ sub.unsubscribe
123
+ end
124
+
125
+ def key_prefix
126
+ "$KV.#{store_name}"
127
+ end
128
+
129
+ def delete_missing_events
130
+ missing_events = existing_events.keys - events.keys
131
+ missing_events.each do |event|
132
+ thor.say "Deleting event #{event}"
133
+ bucket.delete(event)
134
+ end
135
+ end
98
136
  end
99
137
  end
100
138
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Polyn
4
4
  class Cli
5
- VERSION = "0.1.2"
5
+ VERSION = "0.1.5"
6
6
  end
7
7
  end
data/lib/polyn/cli.rb CHANGED
@@ -130,7 +130,7 @@ module Polyn
130
130
 
131
131
  def tf_apply
132
132
  if polyn_env == "development"
133
- %(terraform apply -var "jetstream_servers=#{nats_servers}")
133
+ %(terraform apply -auto-approve -input=false -var "jetstream_servers=#{nats_servers}")
134
134
  else
135
135
  "terraform apply -auto-approve -input=false "\
136
136
  "-var \"jetstream_servers=#{nats_servers}\" "\
@@ -11,10 +11,6 @@ ADD tf ./tf
11
11
 
12
12
  FROM app as dev
13
13
  ENV POLYN_ENV='development'
14
- RUN bundle exec polyn tf_init
15
- CMD bundle exec polyn up
16
14
 
17
15
  FROM app as prod
18
- ENV POLYN_ENV='production'
19
- RUN bundle exec polyn tf_init
20
- CMD bundle exec polyn up
16
+ ENV POLYN_ENV='production'
@@ -3,20 +3,19 @@
3
3
  This repository contains all of the events and terraform resources for the Polyn services
4
4
  environment.
5
5
 
6
- ## Development Setup
7
-
8
6
  1. Install [Ruby](https://github.com/asdf-vm/asdf-ruby)
9
- 2. Install Terraform. For M1 Macs, [download the AMD64 version](https://www.terraform.io/downloads)
7
+ 2. Install bundler `gem install bundler`
8
+ 3. Install dependencies `bundle install`
9
+ 4. Install Terraform. For M1 Macs, [download the AMD64 version](https://www.terraform.io/downloads)
10
10
  rather than using Homebrew to install Terraform.
11
- 3. Ensure Docker & Docker Compose is installed
12
- 4. [Install the Polyn CLI](https://github.com/SpiffInc/polyn-cli)
13
- 5. Call `polyn tf_init` if this is the first time using terraform in the codebase.
14
- 6. Call `polyn up`. By default this will run in `development` mode, which will start the NATS
11
+ 5. Ensure Docker & Docker Compose is installed
12
+ 6. Call `bundle exec polyn tf_init` if this is the first time using terraform in the codebase.
13
+ 7. Call `bundle exec polyn up`. By default this will run in `development` mode, which will start the NATS
15
14
  server, configure it via Terraform, and update the Polyn Event Registry.
16
15
 
17
16
  ### Running NATS locally
18
17
 
19
- `polyn up` will use run a Docker container for you if one is not already running. Alternatively, you can run `nats-server` yourself locally if you prefer.
18
+ `bundle exec polyn up` will use run a Docker container for you if one is not already running. Alternatively, you can run `nats-server` yourself locally if you prefer.
20
19
 
21
20
  ## Naming Conventions
22
21
 
@@ -24,15 +23,15 @@ See the Protocol Documentation for [Naming Conventions](https://github.com/Spiff
24
23
 
25
24
  ## Streams
26
25
 
27
- Each stream should have its own configuration file under `./tf` . Run `polyn gen:stream <stream_name>` to generate a new configuration file for a stream
26
+ Each stream should have its own configuration file under `./tf`. Run `bundle exec polyn gen:stream <stream_name>` to generate a new configuration file for a stream
28
27
 
29
28
  ## Consumers
30
29
 
31
- Run `polyn gen:consumer <stream_name> <destination_name> <event_type>` to generate new configuration for a consumer of a stream. It will be included in the same file as the stream configuration.
30
+ Run `bundle exec polyn gen:consumer <stream_name> <destination_name> <event_type>` to generate new configuration for a consumer of a stream. It will be included in the same file as the stream configuration.
32
31
 
33
32
  ## Event Schemas
34
33
 
35
- Run `polyn gen:schema <event_type>` to generate a new JSON Schema for an event
34
+ Run `bundle exec polyn gen:schema <event_type>` to generate a new JSON Schema for an event
36
35
 
37
36
  All the schemas for your events should live in the `./events` directory.
38
37
  The name of your schema file should be the same as your event, but with `.json` at the end.
@@ -45,7 +44,7 @@ This means you only need to include the JSON Schema for the `data` portion of th
45
44
 
46
45
  If you'd like to organize your events by team ownership or some other convention, you can use subdirectories to do so. The full event type should still be part of the file name. You should also ensure there are not duplicate event types in different directories as only one schema can be defined per event type.
47
46
 
48
- You can generate a schema in a subdirectory like this: `polyn gen:schema some/nested/dir/widgets.created.v1`
47
+ You can generate a schema in a subdirectory like this: `bundle exec polyn gen:schema some/nested/dir/widgets.created.v1`
49
48
 
50
49
  ## Schema Versioning
51
50
 
@@ -81,4 +80,6 @@ Polyn expects you to keep a `./remote_state_config/backend.tf` file that configu
81
80
 
82
81
  ## Deployment
83
82
 
84
- The default `Dockerfile` generated by [Install the Polyn CLI](https://github.com/SpiffInc/polyn-cli) can help you create an image that will configure terraform and your infrastucture with the latest changes when you execute `docker run`. You'll need to pass in `env` variables for `NATS_SERVERS` and `NATS_CREDENTIALS`. Also any `env` variables needed to connect to your remote state storage.
83
+ The default `Dockerfile` generated by [Install the Polyn CLI](https://github.com/SpiffInc/polyn-cli) can help you create an image with the latest changes and nessary environment to run polyn commands.
84
+
85
+ The `bin/apply_changes.sh` script can be used to execute the polyn commands you need to update your production NATS server. You'll need to pass in `env` variables for `NATS_SERVERS` and `NATS_CREDENTIALS`. Also any `env` variables needed to connect to your remote state storage.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polyn-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jarod
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2022-08-22 00:00:00.000000000 Z
12
+ date: 2022-09-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: dotenv
@@ -89,6 +89,7 @@ files:
89
89
  - LICENSE.txt
90
90
  - README.md
91
91
  - Rakefile
92
+ - bin/apply_changes.sh
92
93
  - bin/console
93
94
  - bin/setup
94
95
  - exe/polyn