Is my Godeps.json correctly generated? - heroku

I am trying to deploy a simple go lang server on heroku.I have managed to get it running. But I am wondering if my utilisation of godep is proper.
Here is the Godeps.json I have produced.
{
"ImportPath": ".",
"GoVersion": "go1.5",
"Packages": [
"./..."
],
"Deps": [
{
"ImportPath": "github.com/kevinlg/trendee-api",
"Rev": "6acde53081a273d4caedf113688e1ab83854c877"
}
]
}
I am wondering why "ImportPath":"." and not github.com/kevinlg/trendee-api instead of having it as a dependency ?
When I check the Heroku example or the Godeps.json for godep I can see
"ImportPath": "github.com/heroku/go-getting-started",
or
"ImportPath": "github.com/tools/godep
I have been able to get the server running and deployed on heroku.
Here is my project folder structure
trendee-api /(GOPATH)
bin/
Godeps/
pkg/
src/
github.com/
kevinlg/
trendee-api/
I have used the following commands.
godep save -r ./...
go install github.com/kevinlg/trendee-api
Thanks in advance for the help

When you use godep save -r ./... you are saving multiple packages, which is why your Godeps.json looks like that.
For a single binary, you could also use godep save -r in the $GOPATH/src/github.com/kevinlg/trendee-api directory, given the following structure:
trendee-api /(GOPATH)
bin/
Godeps/
pkg/
src/
github.com/
kevinlg/
trendee-api/
main.go

I'm new to go and I had problem with Godeps too.
why you are using "go install ".
try using this link,
this is the heroku's website teaching about Godeps
and actually you can use godep help save
in command line to learn more about "godep save"

Related

lerna ERR! EDESTDIR --dest does not match with the package directories: packages

When trying to import a repo into my lerna monorepo it keeps failing with:
lerna ERR! EDESTDIR --dest does not match with the package directories: packages
I'm using the default lerna.json config.
{
"packages": [
"packages/*",
],
"version": "0.0.0"
}
The import command I'm using is:
npx lerna import --flatten /Users/home/Desktop/Lerna_Tests/docs-repo --dest=docs
I also tried:
npx lerna import --flatten /Users/home/Desktop/Lerna_Tests/docs-repo --dest=packages/docs
However, both fail with the same error.
I want the repo to go to the packages/docs directory.
Summary
I added a directory glob entry to my lerna.json packages array and added quotes to my import command to fix it.
Explanation:
I realized that when setting up the lerna.json I was using the default lerna.json config but needed to add an entry to the packages array like this:
{
"packages": [
"packages/*",
"packages/docs/*" <<<<<<<<< I added this line.
],
"version": "0.0.0"
}
NOTE: the /* is important after the directory.
Once I added this, the following command imported my repository without a problem:
npx lerna import --flatten /Users/home/Desktop/Lerna_Tests/docs-repo --dest="packages/docs"
Note: I tried without the quotes around the destination directory and it didn't work for some reason. The docs for Lerna give an example without using quotes so I assume that it must be okay in some circumstances just not in mine.
This SO question and answer helped my fix my error. However, it was a different solution and a different problem so I thought I'd post my question answer for those whose issue relates closer to the above situation.

Go importing vendor dependencies issue when building a Go 1.7 project using govendor, dh-make-golang

I've been looking into building a go project into a debian package.
I've looked into dh-make-golang and I have a nice and shiny debian folder set up in my repository. When I try to use gbp buildpackage --git-pbuilder though it errors out due to all of my dependencies not being found. It seems that dh-make-golang ignores the vendor folder when it copies everything from my project's git repository, and I use govendor so all of my dependencies are in there.
How can I resolve this dependency issue and build the project as a .deb package properly? For reference, the error I am getting is:
src/github.com/project/project/project.go:15:2: cannot find package "google.golang.org/grpc/grpclog" in any of:
/usr/lib/go-1.7/src/google.golang.org/grpc/grpclog (from $GOROOT)
/tmp/project/obj-x86_64-linux-gnu/src/google.golang.org/grpc/grpclog (from $GOPATH)
Issue was a bug in dh-make-golang regarding importing vendor dependencies. It was just fixed today.
https://github.com/Debian/dh-make-golang/issues/46
Take a look at goxc - it can do this for you!
You simply need to add a .goxc.json to the root of your directory, that looks like this
{
"AppName": "my_app",
"ArtifactsDest": "downloads",
"Tasks": [
"interpolate-source"
"deb",
],
"BuildConstraints": "linux,amd64 windows,amd64 darwin,amd64 linux,arm",
"ResourcesInclude": "INSTALL*,README*,LICENSE*,config/*,static/*,templates/*",
"PackageVersion": "0.9.3",
"TaskSettings": {
"deb": {
"metadata": {
"description": "my app",
"maintainer": "me",
"maintainer-email": "me#example.com"
},
"metadata-deb": {
"Homepage": "https://example.com"
},
"other-mapped-files": {
"/": "debian/",
"/usr/share/something/static": "static/",
"/usr/share/something/templates": "templates/"
}
}
},
"ConfigVersion": "0.9"
}
Then run goxc and it'll do all the work for you.

Set specific commit of a dependency with govendor

I'm using govendor for managing dependencies in a project. I have the following dependency in my vendor/vendor.json.
{
...
"package": [
{...},
{
"checksumSHA1": "8XAGmXqf+b4LW91wsWxa4kH1NN0=",
"path": "gopkg.in/h2non/bimg.v1",
"revision": "9bb3ae10c5ce30e72f7ac0834368536fc095d6a7",
"revisionTime": "2017-01-13T19:35:42Z"
}
],
...
}
Now I want to use master version of bimg package, which is newer than version 1.0.7 fetched by govendor. What is a proper way to achieve this, beside manually downloading master version from github and saving it to the vendor folder?
ps: all dependencies are committed.
I got help from #jbrandhorst in go slack:
you'll want to remove the old one as well, govendor remove gopkg.in/h2non/bimg.v1
[3:16] source repo appears to be github.com/h2non/bimg, so
govendor fetch github.com/h2non/bimg will install it to your vendor
folder
[3:16] if you just want to add it to your vendor.json, you use
govendor add I think

How to set custom folder path for sub folders in vendor when installing a package?

I want to install a package into my local project.For that I'm creating a composer.json file in my project folder is given below, it gives the total vendor folder of that package into my custom folder in my project. Its working fine.....
{
"config": {
"vendor-dir": "/var/www/html/Test2/Testing/Down"
},
}
It gives the package into 'Down' folder.
But, now I want the sub folders or files in that packages to be installed in my custom folders like js/css folders in my project.
For example i want jquery.js file into my local folder path
/var/www/html/Test2/Testing/assests/js
From the package "frameworks/jquery".
For that, what changes are needed in my composer.json file?
Composer is used to bring in packages to support the PHP code of a project, here is how they describe it on the Composer website:
Composer is a tool for dependency management in PHP. It allows you to
declare the libraries your project depends on and it will manage
(install/update) them for you.
In other words, if you need to do logging in your PHP code and decide to use the publicly available monolog package, you use composer to bring that package into your project, then in your PHP code, you can call monolog functions.
Using config to rename the vendor directory is trying to use Composer in a way that doesn't fit the intent of the tool. The vendor directory is used to hold the packages brought in (such as the monolog code). The vendor-dir value is simply renaming that directory.
Since you have GitHub listed as a tag, you could possibly use cloning to get your files to your website directory.
I've modified my composer.json file, it looks like the below:
{
"config": {
"vendor-dir": "/var/www/html/Test2/Testing/Down"
},
"require": {
},
"scripts": {
"post-package-install": [
"php -r \"exec('cp -r /var/www/html/Test2/Testing/Down/frameworks/jquery/* /var/www/html/Test2/Testing/assets/js');\""
]
}
}
It will gives all selected files in a package to my local folder.
Briefly the files in the folder 'frameworks/jquery' are copied into my local 'assets/js' folder.

How to ignore directories with Composer?

I'd like to release a PHP library and submit it on Packagist to have it installable via Composer.
My library has the following structure:
lib/
tests/
composer.json
README.md
Basically, whenever I include this library in a project's composer.json, I'd like everything to be copied with the exception of the tests directory, which is cumbersome and is only needed when developing the library itself. It's just a waste of space otherwise (especially when packaging the project for production).
Is it possible to exclude this directory from the library's composer.json?
This is not possible in Composer. However, there are some ways to do it:
When you run the update or install command with --prefer-dist, Composer tries to download the archive on github. You can remove the test directory from the archives by putting this in a .gitattributes file in the root directory of your project:
Tests/ export-ignore
Composer will only use the tags on github. Just temporary remove the tests directory when creating a tag will also do the trick.
It's possible to control the archive creation by adding exclude patterns in the composer.json file within the archive key. See https://getcomposer.org/doc/04-schema.md#archive for details.
The example given (cited from above URL):
{
"archive": {
"exclude": ["/foo/bar", "baz", "/*.test", "!/foo/bar/baz"]
}
}
The example will include /dir/foo/bar/file, /foo/bar/baz, /file.php, /foo/my.test but it will exclude /foo/bar/any, /foo/baz, and /my.test.
That way you have about the same control that .gitattributes would give you, without having to use Git or affecting any processes that require different settings in said file.
This has been possible since Nov 11, 2015 with https://getcomposer.org/doc/04-schema.md#exclude-files-from-classmaps
Source: https://github.com/composer/composer/issues/4456#issuecomment-155825777
EDIT: Misinterpretation. The above only lets the autoloader ignore the specified paths, it does not actually prevent them from being copied to the filesystem upon install.
This can be automated with post-update-cmd the composer.json file within the scripts key:
"scripts": {
"post-update-cmd": [
"rm -rf vendor/aura/intl/tests vendor/cakephp/cakephp/tests"
],
},
Or use pattern to remove directories:
"scripts": {
"post-update-cmd": [
"find vendor/ -type d -regextype posix-extended -iregex '.*/(doc|docs|example|examples|test|tests|tmp)' -print -exec rm -r {} +"
],
},

Resources