Skip to content
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

Allow artifact_file to handle snapshot and latest version correctly #125

Closed
wants to merge 31 commits into from
Closed

Allow artifact_file to handle snapshot and latest version correctly #125

wants to merge 31 commits into from

Conversation

BarthV
Copy link
Contributor

@BarthV BarthV commented Mar 15, 2014

issue #115

This patch allows artifact_file corectly downloading *-SNAPSHOT and LATEST version :

  • It detects artifact version based on existing artifact class method (Thanks to @gregsymons)
  • In case of "rolling version", it retrives artifact filename from Nexus metadata and merge it with provided destination folder.
  • Cast a log info because provided filename is now ignored when asking for a snapshot version

Anyway, we are now able to download the artifact properly but we still do not know its name. I think it's still very interesting to correct the issue #112

@BarthV
Copy link
Contributor Author

BarthV commented Mar 15, 2014

I did many test (snapshots, static version, latest, etc...), many times. I also tried to make artifact_file resources upgrade/downgrade perfectly (new file is downloaded). Idempotency is still OK.

But it would be nice to all of you to test it again :). Thx

@BarthV
Copy link
Contributor Author

BarthV commented Mar 15, 2014

I got a problem with latest tag (snap is ok), and still have indent issues. Fixing this right now

@BarthV
Copy link
Contributor Author

BarthV commented Mar 15, 2014

Ready to be tested !
Don't forget to merge fix #124 before all ;-)

@BarthV
Copy link
Contributor Author

BarthV commented Mar 16, 2014

OK ... my artifact's version resolution is wrong :
I just read https://github.com/RiotGames/nexus_cli and I realized version is not at a static position but always the last one.
So [...].split(':')[3] is not always correct -> [...].split(':')[-1] should fix this

@bdemers
Copy link

bdemers commented Mar 16, 2014

We have worked around this issue in the past by creating hard links in the after proc. myartifact-1.2.3-timestamp.jar -> myartifact-1.2.3-SNAPSHOT.jar (also a work around for #112 )

@BarthV
Copy link
Contributor Author

BarthV commented Mar 16, 2014

I'm not sure about it, but hardlink in the after proc suppose that we can guess filename or resolve it from nexus metadata.
Currently if you're using *-snapshot or latest version tag we cannot guess it and make further actions on this file.

That why a providing a built-in procedure to resolve filename or making a symlink would be nice.

Tell me if I'm wrong :/

@bdemers
Copy link

bdemers commented Mar 17, 2014

Absolutely, a proper solution would be much better. Just doc'ing the work around for anyone googling until this gets a fix.
You can guess the filename by doing something like:

Dir.glob("#{::File.dirname(self.new_resource.name)}/*#{::File.extname(self.new_resource.name)}").last

Granted this is work around is more of a hack then anything...

@BarthV
Copy link
Contributor Author

BarthV commented Mar 20, 2014

rebased

@BarthV
Copy link
Contributor Author

BarthV commented Mar 21, 2014

OK this time I think all cases are covered.
LWRP update should be 100% transparent with previous version and previous syntax (I'm only adding some switching cases)

So ... I have worked and tested a lot to finally bring a very simple modification into load_current_resource to handle snap/latest file from nexus.
I also added a new symlink lwrp attribute which links downloaded file to the specified symlink path.
Idempotency should be ok too.

Symlinking is totally optionnal and you still can download a "latest" artifact without bothering about the filename.

This is a silly example :

artifact_file "/tmp/my-artifact.jar" do
  location "com.test:my-artifact:jar:LATEST"
  owner "me"
  group "mes"
end

We get something like :

  • /tmp/my-artifact-1.3.175.jar
  • /var/chef/cache/artifact_file/com_test_my-artifact_jar_LATEST-c58fcfa00dc150d5b09e7dd9e113b2a5

if we put a symlink in the resource :

artifact_file "/tmp/my-artifact.jar" do
  location "com.test:my-artifact:jar:LATEST"
  owner "me"
  group "mes"
  symlink "/tmp/my-artifact.jar"
end

We get something like :

  • /tmp/my-artifact-1.3.175.jar
  • /var/chef/cache/artifact_file/com_test_my-artifact_jar_LATEST-c58fcfa00dc150d5b09e7dd9e113b2a5
  • /tmp/my-artifact.jar -> /tmp/my-artifact-1.3.175.jar

Symlink obviously works with non-rolling (ie. static) versions too.

I tried to keep the changes very easy to read and to understand. I think it's ok, but feel free to comment, review or modify this PR.

Thanks !

@@ -37,6 +37,16 @@ def load_current_resource

@nexus_configuration = new_resource.nexus_configuration
@nexus_connection = Chef::Artifact::Nexus.new(node, nexus_configuration)

if Chef::Artifact.snapshot?(new_resource.location.split(':')[-1]) || Chef::Artifact.latest?(new_resource.location.split(':')[-1])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should come up with a way to refactor this so that we don't have to do this splitting logic. I think adding a new snapshot? and latest? to Chef::Artifact::Nexus would do the trick - see https://github.com/RiotGames/artifact-cookbook/blob/master/libraries/chef_artifact_nexus.rb#L30-L31 for reference.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I'll work on this and think about adding new snapshot/latest method directly at Nexus object level.

@KAllan357
Copy link
Contributor

To piggyback on the discussion in #112, would it make sense that the following example:

artifact_file "/tmp/my-artifact.jar" do
  location "com.test:my-artifact:jar:LATEST"
  owner "me"
  group "mes"
end

Should give you:

  • /tmp/my-artifact.jar

I think perhaps that Nexus downloads should again go under your Chef::Config[:file_cache_path] and be copied to your new_resource.path with the appropriate name.

Edit: I'm not sure I fully understand the use case behind the usage of symlink. I think based on the above, the expectation would be that the file's name gets changed and placed in the appropriate directory. Requiring a symlink to get that functionality might be unexpected.

@KAllan357
Copy link
Contributor

Overall this has come along nicely. We certainly appreciate all the effort. Would it be possible to squash this whole pull request into a couple of reasonable-sized commits?

@BarthV
Copy link
Contributor Author

BarthV commented Mar 21, 2014

ok, i'll clean this up a bit

@BarthV
Copy link
Contributor Author

BarthV commented Mar 25, 2014

Closing this PR.
Currently Working on a cleaner version including asked features.

@BarthV BarthV closed this Mar 25, 2014
@BarthV BarthV deleted the file-handle-snapshot branch March 25, 2014 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants