nexus_seed 0.2.8 → 0.2.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +72 -0
- data/lib/nexus_seed/base.rb +1 -1
- data/lib/nexus_seed/builder.rb +12 -9
- data/lib/nexus_seed/version.rb +2 -2
- data/lib/nexus_seed.rb +5 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61cc46080bca8e537d0290de925e2c4a24ec08251f4613af77233712bfc87368
|
4
|
+
data.tar.gz: 7a192d784f4baf6b2e5eee0b553c2c12f12b08f97c81c1f58ef897e01273e648
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: faefc536924c2c8341c0722b06b9b5ccdddb11458db2985381a73dcb9596eae90ce787fc31a34aa7145bf0c24a6dd72169c6d07d6a76f65ad922162d6a2b419a
|
7
|
+
data.tar.gz: 919c1c15889cb931610e60d677b122df71476b3650f2baa6a65385d9921086b36ace17b0d4b6dd260f2811b1be4b3de9a2506f6231e2d81d377195f96cb7f978
|
data/README.md
CHANGED
@@ -1,3 +1,75 @@
|
|
1
1
|
# nexus_seed
|
2
2
|
|
3
3
|
Common rails application seeding logic.
|
4
|
+
|
5
|
+
# Running
|
6
|
+
|
7
|
+
## Running tasks on deploy
|
8
|
+
|
9
|
+
Task files must be placed in `/lib/tasks/seed_#{name}.rake`
|
10
|
+
|
11
|
+
Set task name in helm values e.g. for a `common` seed task:
|
12
|
+
|
13
|
+
```
|
14
|
+
helm:
|
15
|
+
values:
|
16
|
+
rails:
|
17
|
+
seedTasks:
|
18
|
+
- common
|
19
|
+
```
|
20
|
+
|
21
|
+
Configure the post deploy hook in `devspace.yaml` and set `COMPONENT` appropriately:
|
22
|
+
|
23
|
+
```
|
24
|
+
hooks:
|
25
|
+
- name: post-deploy-seed-task-hook
|
26
|
+
events: [ "after:deploy" ]
|
27
|
+
command: |-
|
28
|
+
docker run --rm --pull always registry.nexusmods.com/nexus-mods/devops/tools/seed_task_start:stable cat seed_task_start.sh |
|
29
|
+
NAMESPACE=${devspace.namespace} COMPONENT=api bash
|
30
|
+
```
|
31
|
+
|
32
|
+
## Running tasks manually
|
33
|
+
|
34
|
+
Run `common` seed task with default options:
|
35
|
+
|
36
|
+
`bundle exec rake seed_common:run`
|
37
|
+
|
38
|
+
Options are `[:retry_limit, :sleep_interval]`
|
39
|
+
|
40
|
+
E.g. to retry 100 times every 3 seconds:
|
41
|
+
|
42
|
+
`bundle exec rake seed_common:run[100,3]`
|
43
|
+
|
44
|
+
# Local gem development
|
45
|
+
|
46
|
+
Steps to run this gem from local sources in one the nexus 'staged build' rails components:
|
47
|
+
|
48
|
+
## Copy gem sources to component
|
49
|
+
|
50
|
+
```
|
51
|
+
cd ~/nexus-api
|
52
|
+
cp -r ../nexus_seed .
|
53
|
+
```
|
54
|
+
|
55
|
+
## Adjust component Dockerfile to include gem sources
|
56
|
+
|
57
|
+
Within stage 1, append a COPY after the Gemfile copy:
|
58
|
+
|
59
|
+
```
|
60
|
+
COPY --chown=nexus:nexus Gemfile* ./
|
61
|
+
COPY --chown=nexus:nexus nexus_seed/ ./nexus_seed/
|
62
|
+
```
|
63
|
+
|
64
|
+
Within stage 2, append a COPY after the bundle copy:
|
65
|
+
|
66
|
+
```
|
67
|
+
COPY --from=stage1 /usr/local/bundle /usr/local/bundle
|
68
|
+
COPY --from=stage1 /app/nexus_seed/ /app/nexus_seed/
|
69
|
+
```
|
70
|
+
|
71
|
+
## Adjust Gemfile to use local path
|
72
|
+
|
73
|
+
```
|
74
|
+
gem 'nexus_seed', :path => "/app/nexus_seed"
|
75
|
+
```
|
data/lib/nexus_seed/base.rb
CHANGED
data/lib/nexus_seed/builder.rb
CHANGED
@@ -5,14 +5,17 @@ module NexusSeed
|
|
5
5
|
@counts = {}
|
6
6
|
@start = Time.now
|
7
7
|
@seeds = []
|
8
|
-
|
8
|
+
|
9
|
+
def self.logger
|
10
|
+
@logger ||= SemanticLogger::Logger.new('NexusSeed::Builder')
|
11
|
+
end
|
9
12
|
|
10
13
|
def self.build_called
|
11
14
|
@build_called
|
12
15
|
end
|
13
16
|
|
14
17
|
def self.build(class_name, params = {}, options = {})
|
15
|
-
if ENV['
|
18
|
+
if ENV['NEXUS_SEED_REPORT']
|
16
19
|
pre_seed_counts unless @build_called
|
17
20
|
end
|
18
21
|
|
@@ -21,25 +24,25 @@ module NexusSeed
|
|
21
24
|
end
|
22
25
|
|
23
26
|
def self.seed_report
|
24
|
-
if ENV['
|
27
|
+
if ENV['NEXUS_SEED_REPORT']
|
25
28
|
total = 0
|
26
29
|
|
27
|
-
|
30
|
+
logger.info('SEED REPORT:')
|
28
31
|
NexusSeed::Builders.constants.select do |c|
|
29
32
|
NexusSeed::Builders.const_get(c).is_a?(Class)
|
30
33
|
k = NexusSeed::Builders.const_get(c).new.send(:klass)
|
31
34
|
if @counts[k.name.demodulize] != k.count
|
32
35
|
total += (k.count - @counts[k.name.demodulize])
|
33
|
-
|
36
|
+
logger.info("Generated #{k.count - @counts[k.name.demodulize]} new #{k.name.demodulize}s")
|
34
37
|
end
|
35
38
|
end
|
36
39
|
|
37
|
-
|
40
|
+
logger.info("Generated total of #{total} new seeds.")
|
38
41
|
else
|
39
|
-
|
42
|
+
logger.info('Seeding completed.')
|
40
43
|
end
|
41
44
|
|
42
|
-
|
45
|
+
logger.info("Time: #{(Time.now - @start).round(2)}s")
|
43
46
|
end
|
44
47
|
|
45
48
|
def self.add_seed(seed)
|
@@ -53,7 +56,7 @@ module NexusSeed
|
|
53
56
|
count += 1
|
54
57
|
seed.destroy
|
55
58
|
end
|
56
|
-
|
59
|
+
logger.info("Destroyed #{count} seeds (including dependants). All seeds deleted.")
|
57
60
|
end
|
58
61
|
end
|
59
62
|
|
data/lib/nexus_seed/version.rb
CHANGED
data/lib/nexus_seed.rb
CHANGED
@@ -7,10 +7,9 @@ require 'nexus_seed/base'
|
|
7
7
|
|
8
8
|
module NexusSeed
|
9
9
|
# defaults
|
10
|
-
@@retry_limit =
|
10
|
+
@@retry_limit = 12
|
11
11
|
@@sleep_interval = 5
|
12
12
|
@@retries = 0
|
13
|
-
@@logger = SemanticLogger::Logger.new('NexusSeed')
|
14
13
|
|
15
14
|
# override this method with your specific requirement
|
16
15
|
def requires
|
@@ -18,6 +17,7 @@ module NexusSeed
|
|
18
17
|
end
|
19
18
|
|
20
19
|
def run
|
20
|
+
logger.info('Run with options:', limit: retry_limit, interval: sleep_interval)
|
21
21
|
logger.measure_info('Total seed run.') do
|
22
22
|
_run_internal
|
23
23
|
end
|
@@ -26,6 +26,8 @@ module NexusSeed
|
|
26
26
|
# recursively called until requirement is met or the limit is reached
|
27
27
|
def _run_internal
|
28
28
|
if Rails.env.test? || Rails.env.development?
|
29
|
+
|
30
|
+
logger.info("Starting run attempt #{retries + 1}")
|
29
31
|
if requires
|
30
32
|
NexusSeed::Base.transaction do
|
31
33
|
seed
|
@@ -84,7 +86,7 @@ module NexusSeed
|
|
84
86
|
end
|
85
87
|
|
86
88
|
def logger
|
87
|
-
|
89
|
+
@logger ||= SemanticLogger::Logger.new('NexusSeed')
|
88
90
|
end
|
89
91
|
|
90
92
|
def task_options(opts = {})
|