I have been trying to run my cookbooks from many hours and gone through multiple questions regarding the same but still couldn't manage to make it work.
sudo chef-solo -c solo.rb -j node.json -o main::default;
I'm running the above command inside my cookbooks folder which contains other cookbooks like apt, git, etc.
And, inside cookbooks/main/recipe/default.rb I'm including include_recipe "apt".
Every time, I run the command I get the following error:
Cookbook apt not found. If you're loading apt from another cookbook,
make sure you configure the dependency in your metadata
So I added depends "apt" inside my cookbooks/main/metadata.rb. But now I'm getting this error:
Cookbook depends on itself in cookbook apt, please remove this
unnecessary self-dependency
Without more information it's difficult to extrapolate where the problem may lie. Here's an example of how you should theoretically be laying out your cookbooks/files, though:
All cookbooks you're writing go in <dir>/cookbooks/.
All vendored cookbooks (e.g. apt) go in <dir>/vendor/.
So your structure, at a very stripped down level, might look something like this:
.
├── cookbooks
│ └── main
│ ├── metadata.rb
│ └── recipes
├── solo.rb
└── vendor
└── apt
├── metadata.rb
└── recipes
Now lets take a look at some individual files:
The default recipe of your main cookbook:
# cookbooks/main/recipes/default.rb
include_recipe 'apt'
And your main cookbook's metadata file:
# cookbooks/main/metadata.rb
name 'main'
...
depends 'apt'
Note that the apt cookbook resides in vendor/. Anything here should be from third parties and you should not modify.
From here, you just need to ensure your solo.rb properly references both cookbook directories for the cookbook_path attribute:
# solo.rb
...
cookbook_path ['cookbooks/', 'vendor/']
...
A second answer because this was diagnosed on Slack, themain cookbook had name "apt" in its metadata which made the error message confusing.
So as a somewhat unrelated answer: there is a very low chance you actually need that apt::default recipe. We've moved most of the stuff that cookbook in to Chef core. If you just want to run an apt-get update, use the apt_update resource.
Related
TL;DR: Where do .so files end up when you install plugins with go install -buildmode=plugin?
I have a project that uses plugins. The layout is something like this:
myproject/
├── main.go
└── modules
├── bar
│ └── main.go
└── foo
└── main.go
When I run go install the binary gets installed OK.
But I would also like to run go install for each of my modules and have them available to the main binary everywhere on the system.
If I run go install -buildmode=plugin from inside a module folder (say, modules/foo) the command runs to completion but I can't find the resulting file anywhere.
Installing a normal package ends up in:
GOPATH/pkg/<goos>_<goarch>_dynlink/path/to/parent/folder/packagename.a
Installing main packages end up in:
GOPATH/bin/foldername
(where foldername is the parent folder of the main package you install, it'll get an .exe extension on windows).
When you "go install" a plugin (using -buildmode=plugin), that ends up in
GOPATH/pkg/<goos>_<goarch>_dynlink/path/to/parent/folder/foldername.a
I'm working on a Ruby gem and I'm getting an odd error. I have previously released this gem without too much trouble. I added some methods / refactored some code and wanted to release a subsequent version (from 1.1 to 1.2).
For reference, the name of the gem is Intervallum, (the word 'interval' in Latin).
I'm getting a 'require' error that's been stumping me.
The folder tree is:
.
├── Gemfile
├── LICENSE
├── README.md
├── intervallum-[version].gem
├── intervallum.gemspec
└── lib
├── intervallum
│ ├── module.scroll.rb
│ └── module.spell.rb
└── intervallum.rb
In lib/intervallum.rb I tried Dir.glob, Dir['./lib/intervallum/*'] and require '../intervallum/lib/intervallum/module.spell.rb' and what happens for each one is:
Locally, after gem build intervallum.gemspec and gem install intervallum-[version].gem, I boot up irb and require intervallum and it works fine.
push to RubyGems
remove the local copy
install from RG
load up in irb I get load errors or it cannot find class of a helper class
I'm not sure why this keeps occurring, or if there's something that I'm missing as to why this keeps occurring but any advice would be much appreciated.
The problem is that you are not including those files in the gem when it gets packaged. Your gemspec specifies that only the lib/intervallum.rb file will be included in the gem:
s.files = ["./lib/intervallum.rb"]
Change that line to include all files in lib. It's also a good idea to include the gemspec.
s.files = Dir['lib/**/*', 'intervallum.gemspec']
I have this folder structure for my fib package:
$ tree
.
└── src
└── fib
├── fib
│ └── main.go
├── fib.go
└── fib_test.go
(main.go is in package main, fib(_test).go is in package fib)
GOPATH is set to $PWD/src, GOBIN is set to $PWD/bin. When I run go install fib/fib, I get a file called fib in the directory bin (this is what I expect):
$ tree bin/
bin/
└── fib
But when I set GOOS or GOARCH, the directory in the form GOOS_GOARCH is created:
$ GOARCH=386 GOOS=windows go install fib/fib
$ tree bin/
bin/
└── windows_386
└── fib.exe
This is not what I want. I'd like to have the file fib.exe in the bin directory, not in the sub directory bin/windows_386.
(How) is this possible?
That doesn't seem possible, as illustrated in issue 6201.
GOARCH sets the kind of binary to build.
You might be cross-compiling: GOARCH might be arm.
You definitely don't want to run the arm tool on an x86 system.
The host system type is GOHOSTARCH.
To install the api tool (or any tools) you need to use
GOARCH=$(go env GOHOSTARCH) go install .../api
and then plain 'go tool' will find them.
In any case (GOARCH or GOHOSTARCH), the go command will install in a fixed location that you cannot change.
The phrase "I (don't) want" is incompatible with the go tool; the go tool works how it works. You can a) copy the file to where you want it to be after installing it with the go tool or b) compile it yourself, e.g. by invoking 6g manually (here you can specify the output). If you are unhappy with how the go tool works, just switch to a build tool of your liking, e.g. plain old Makefiles. Note that the go tool helps you there too, e.g. by invoking the compiler via go tool 6g
Is there an easy way to fire up a web browser for a folder?
eg.
I am in a folder that contains a website (index.html and other files) and I want to browse the site through a browser. Is there a gem that I just launch to make this folder browsable?
In this way I don't have to install nginx just for a specific folder. And when you install nginx you have to bother with configuration files and so on.
Kinda how Rails does it with:
rails server
Yes, there is... Throw the following in a file called webserver:
#!/usr/bin/env ruby
require 'webrick'
include WEBrick
server = HTTPServer.new(:Port => 3000, :DocumentRoot => Dir::pwd)
trap("INT"){ server.shutdown }
server.start
Then, perform the following (This assumes Mac OSX):
$ sudo chmod 755 webserver
$ sudo chown root:wheel webserver
$ sudo cp webserver /usr/local/bin/webserver (or somewhere in your path)
Now, just run webserver from the directory you want to use as the document root. A webserver will now be running on localhost:3000.
Hope this helps!
UPDATE
I just remembered after reading a post on Phusion Passenger 3.0 progress that there will be a passenger lite option...
Easiest way I've found is this little Python one-liner:
2.x:
python -m SimpleHTTPServer
3.x:
python -m http.server 8080
Unless you want to execute Ruby dynamically, of course. But that wasn't explicit in your question. Only static HTML.
The webbrick example works great, thanks to Brian. However, I just wanted to follow up on his update.
Assuming you have a working ruby and rubygems installed:
gem install passenger
put all files in a subdirectory called public
example project dir:
.
├── any
│ ├── old crap
│ └── that will not be on the website
└── public
├── favicon.ico
├── images
│ ├── ajax-loader-large.gif
│ ├── bg.jpg
│ ├── bg_home.jpg
│ ├── bg_nav.gif
├── index.html
├── javascripts
│ ├── jquery.liveSearch.js
├── robots.txt
└── stylesheets
├── all.css
Then run passenger start
The first time it will install a bunch of things (including nginx, but you won't have to worry about configuring it), but it should work faster after that.
And, if you have PHP >= 5.4.0, you can:
php -S localhost:8000
That's pretty easy!
Reference: http://php.net/manual/en/features.commandline.webserver.php
I'm after an overview/clarification of the ideal project structure for a ruby (non-rails/merb/etc) project. I'm guessing it follows
app/
bin/ #Files for command-line execution
lib/
appname.rb
appname/ #Classes and so on
Rakefile #Running tests
README
test,spec,features/ #Whichever means of testing you go for
appname.gemspec #If it's a gem
Have I got something wrong? What parts have I missed out?
I think that is pretty much spot on. By default, Rubygems will add the lib directory to the loadpath, but you can push any directory you want onto that using the $: variable. i.e.
$:.push File.expand_path(File.dirname(__FILE__) + '/../surfcompstuff')
That means when you have say, surfer.rb in that dir, you can require "surfer" anywhere and the file will be found.
Also, as a convention, classes and singletons get a file and modules get a directory. For instance, if you had the LolCatz module and the LolCatz::Moar class that would look like:
lib/
appname.rb
lolcatz/
moar.rb
That is why there is an lib/appname folder because most libraries are in the appname namespace.
Additionally, if you try running the command newgem --simple [projectname] that'll quickly generate a scaffold for you with just the bare essentials for a Ruby project (and by extension a Ruby Gem). There are other tools which do this, I know, but newgem is pretty common. I usually get rid of the TODO file and all the script stuff.
See the following example from http://guides.rubygems.org/what-is-a-gem/
% tree freewill
freewill/
├── bin/
│ └── freewill
├── lib/
│ └── freewill.rb
├── test/
│ └── test_freewill.rb
├── README
├── Rakefile
└── freewill.gemspec
I attempt to mimic the Rails project structure because my team, which usually deals with Rails, will understand the structure better than another configuration. Convention over Configuration - bleeding over from Rails.
If you use bundler, running this command bundle gem app_name will give you the same directory structure.
If you want to use rspec instead of unit tests you can then run this command rspec --init
(Just make sure you cd app_name first)