New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #17417 - adds exporting task #36
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly 👍 just a few nitpicks. I'll set it up now and try it out :)
def self.load_defaults | ||
return unless super | ||
|
||
%w(template_sync_filter template_sync_branch).each { |s| Setting::BLANK_ATTRS << s } | ||
%w(template_sync_filter template_sync_branch ).each { |s| Setting::BLANK_ATTRS << s } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: is this extra whitespace intentional?
self.set('template_sync_repo', N_('Default Git repo to sync from'), 'https://github.com/theforeman/community-templates.git', N_('Repo')), | ||
self.set('template_sync_negate', N_('Negate the search'), false, N_('Negate')), | ||
self.set('template_sync_branch', N_('Default branch in Git repo'), nil, N_('Branch')) | ||
self.set('template_sync_negate', N_('Negate the prefix search for purging, filter for importing or exporting'), false, N_('Negate')), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: This can probably be worded better - perhaps "Negate the prefix (for purging) / filter (for importing/exporting)" ?
@@ -24,6 +27,23 @@ namespace :templates do | |||
puts results.join("\n") | |||
end | |||
|
|||
task :import => :sync |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: Shouldn't this the other way around? :sync is deprecated, so the code should now be at :import
end | ||
end | ||
|
||
def get_template_name(template) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name
is a bit overloaded, using get_template_filename
would be clearer
metadata_export_mode: ENV['metadata_export_mode'], | ||
}).export! | ||
|
||
puts 'Export finished' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the internal code logs using logger
- but just this single line for rake. Can we get output parity here (at least using @verbose
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignore me, seems to work just fine now that I try it ;)
@ares: Should this work with local git dirs? I tried this:
and it fails with
|
It should, you need to have at least one commit there though. Also note that the branch must not be checked out before pushing (e.g. checkout to different branch than you push to). |
No, it still bombs. I'm doing this:
Same error, I think:
|
The prefixing is a bit weird too. I used
See how it's kept the import prefix (but with lowercase and whitespace->underscore) but also added the prefix again. This is also not handled in the The filename is mostly cosmetic, but (assuming you automate the import step with a known prefix) the Both import and export should probably check if the string already starts with the prefix and drop it if so. |
@GregSutcliffe the error you're receiving is caused by the fact you haven't created a development branch in your repo. We default to it since we assume the repo is community-templates. You can also override the branch in settings but it must exist in target repo. We should probably add some layer for better error detection and reporting, but that's out of scope for this PR I'm afraid as this is the same for importing. Regarding the prefix, I think we just need to stop importing double prefixes. During the export, prefix is already part of the name and you're right, it does not make sense to add it to the filename since normally it should already be there. I fixed all your comments, please take another look. I'd also like to add pure FS export support in this PR so please do not merge yet. I hope to find some time today to finish it. |
Now with FS support, so cancelling the "do not merge" status :-) |
task :sync => :environment do | ||
task :import => :environment do | ||
if Rake.application.top_level_tasks.include?('templates:sync') | ||
ActiveSupport::Deprecation.warn('templates:sync task has been renamed to templates:import and will be removed in future version') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in a future version ?
@ares we're closer but not done yet :)
So you've only added Does it make sense to drop the There's also two other small things I'll comment on inline. EDIT: there is still some weirdness on export/import with prefixes - after a few rounds I see this in my export dir:
Note how the original |
matching = name.match(/#{@filter}/i) | ||
matching = !matching if @negate | ||
next if !matching | ||
end | ||
|
||
raise MissingKindError unless metadata['kind'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The export task isn't writing kind
for ptables or snippets, so the subsequent import fails. We should probably remove this check now that we're moving to model
- but we might want to add model
to the export task so that we always hit line 79 below
git_repo = Git.clone(@repo, @dir) | ||
logger.debug "cloned #{@repo} to #{@dir}" | ||
branch = @branch ? @branch : get_default_branch(git_repo) | ||
git_repo.checkout(branch) if branch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any chance to create the branch if we specify a non-existant one? Currently it fails unless you give a valid branch, and it felt a bit weird to have to clone my repo separately just to add a target for exporting. This is not a blocker and can be done in another PR, just curious
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
easy enough to do it in this PR
I kept changes in separate commit for easier reviewing. I think it should address all recent comments. Please take another look. |
theforeman/foreman#4098 has been merged so exported templates will have model in the yaml if it runs with 1.15 UPDATE: the PR was merged and aligned to 1.14.1 in redmine so this might work Foreman 1.14.1+ |
There's still a chance to get this merged in 2016 :-) |
Sorry for the delay @ares Testing pretty well here, the only minor issue/question left is what to do with prefixed imports. Currently you get something like this:
Note how the Prefix goes in the name but not the metadata. Now, when this is exported it'll be fixed (assuming metadata==refresh) but it leaves it slightly inconsistent in the meantime. I don't think it's a big issue, so let's [test] one more time, and then merge, and we can deal with edge cases as we go. |
I didn't find a better way. I agree, lets hear from users how they would prefer to solve it. If this is commonly used thing we might have prefix as first class citizen attribute in templates. |
@ares looks like you've got a minor test failure. +1 when it's green ;) |
* rely on model attribute on import * drop prefix on export * create branch if it does not exist * fix deprecation message
thou shalt not fail |
Squashed and merged, ty @ares for the hard work and patience :) |
Requires theforeman/foreman#4031 but other than that, ready for review. I didn't cover it in readme since I'd like to write a proper manual for the plugin and start linking there. If you want to test, run
rake templates:export
. Just be careful, currently it clones remote repo, does changes, creates commit and pushes to the origin. After discussion with @xprazak2 we decided to leave it like this until there's a filesystem support (#35). Later we'd like to introduce repos as first class citizen object that users could configure separately.