Skip to content

Commit 8fadaad

Browse files
committed
use temp dir for generating templates
1 parent b7d4713 commit 8fadaad

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

lib/helmsnap/generate.rb

+15-7
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,38 @@ def initialize(config, snapshots_path: nil)
1010
def call
1111
Helmsnap::SetupDependencies.call(config)
1212

13-
FileUtils.rmtree(snapshots_path)
13+
Dir.mktmpdir do |tmpdir|
14+
tmp_path = Pathname.new(tmpdir)
15+
generate!(tmp_path)
16+
end
17+
end
18+
19+
private
20+
21+
attr_accessor :config, :snapshots_path
1422

23+
def generate!(tmp_path)
1524
config.envs.each do |env|
1625
run_cmd(
1726
"helmfile",
1827
"--environment",
1928
env.name,
2029
"template",
2130
"--output-dir-template",
22-
snapshots_path.join(env.name).join("{{ .Release.Name }}"),
31+
tmp_path.join(env.name, "{{ .Release.Name }}"),
2332
"--skip-deps",
2433
)
2534
end
2635

27-
snapshots_path.glob(["**/*yaml", "**/*.yml"]).each do |path|
36+
tmp_path.glob(["**/*yaml", "**/*.yml"]).each do |path|
2837
content = path.read
2938
content.gsub!(/\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d\.\d+/, "2022-01-01 00:00:00.000")
3039
content.gsub!(/\d\d\d\d-\d\d-\d\d-\d\d-\d\d-\d\d/, "2022-01-01-00-00-00")
3140
content.gsub!(/\d\d\d\d-\d\d-\d\d-\d\d-\d\d/, "2022-01-01-00-00")
3241
path.write(content)
3342
end
34-
end
35-
36-
private
3743

38-
attr_accessor :config, :snapshots_path
44+
FileUtils.rmtree(snapshots_path)
45+
FileUtils.move(tmp_path, snapshots_path)
46+
end
3947
end

0 commit comments

Comments
 (0)