polyn-cli 0.1.2 → 0.1.3

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: 4157c24284768c4e60893c3f3d7aca891e8916752ca85c6c48577ad59b9719bc
4
+ data.tar.gz: 114bb082e7f42f3db6d0efde45d4f058bb33bab652c42fc316668b6456d0e500
5
5
  SHA512:
6
- metadata.gz: cf5e0ff4dae1a5769da3f041f32a579a159c7fe00281d8a8f563e0c0642d55a3632010f47d7351b6e72592cfd781e6eea1d88091a3a51dd12c8e9045809ca040
7
- data.tar.gz: 9a91d45f22c7c2ec3d3dce6e32776607d9da6d17d6c93a811c5219e4ae11cf0b47aa60bd0615fb705d857fe1fcd60df3e20243a92c4cfeb98e8170dfa892c0d6
6
+ metadata.gz: c349dfca556555beaccbe06d2829378e4fb027a76651d444b3f0b0b8560237ca4f2ab8a8678be12de69eee47ade4837ca8cae405e632fbc2c5e2a5e55cbbae0d
7
+ data.tar.gz: 1d09e688a62159910697b791de37cebbd0d21f5e7078b84201854b777e0b3d22bcf93b9f034fd4d81f9125ddd32a17d683c0e0d9284a360e0ddb2e23afdd4e99
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.3)
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
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.3"
6
6
  end
7
7
  end
@@ -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'
@@ -81,4 +81,6 @@ Polyn expects you to keep a `./remote_state_config/backend.tf` file that configu
81
81
 
82
82
  ## Deployment
83
83
 
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.
84
+ 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.
85
+
86
+ 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.3
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-08-23 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