Skip to content

Commit

Permalink
use temp dir for generating templates
Browse files Browse the repository at this point in the history
  • Loading branch information
tycooon committed Dec 18, 2024
1 parent b7d4713 commit 8fadaad
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions lib/helmsnap/generate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,38 @@ def initialize(config, snapshots_path: nil)
def call
Helmsnap::SetupDependencies.call(config)

FileUtils.rmtree(snapshots_path)
Dir.mktmpdir do |tmpdir|
tmp_path = Pathname.new(tmpdir)
generate!(tmp_path)
end
end

private

attr_accessor :config, :snapshots_path

def generate!(tmp_path)
config.envs.each do |env|
run_cmd(
"helmfile",
"--environment",
env.name,
"template",
"--output-dir-template",
snapshots_path.join(env.name).join("{{ .Release.Name }}"),
tmp_path.join(env.name, "{{ .Release.Name }}"),
"--skip-deps",
)
end

snapshots_path.glob(["**/*yaml", "**/*.yml"]).each do |path|
tmp_path.glob(["**/*yaml", "**/*.yml"]).each do |path|
content = path.read
content.gsub!(/\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d\.\d+/, "2022-01-01 00:00:00.000")
content.gsub!(/\d\d\d\d-\d\d-\d\d-\d\d-\d\d-\d\d/, "2022-01-01-00-00-00")
content.gsub!(/\d\d\d\d-\d\d-\d\d-\d\d-\d\d/, "2022-01-01-00-00")
path.write(content)
end
end

private

attr_accessor :config, :snapshots_path
FileUtils.rmtree(snapshots_path)
FileUtils.move(tmp_path, snapshots_path)
end
end

0 comments on commit 8fadaad

Please sign in to comment.