Declare App Dependencies
Page last updated:
Page last updated:
Cloud Foundry recognizes an app as Go (among other possible reasons)
by the existence of a glide.yaml
or Gopkg.toml
file in the root directory.
Dep
Once you have dep installed, go to the root
of your project/application and run dep init
it will create the files
Gopkg.toml
, Gopkg.lock
and the vendor
directory:
$ dep init
$ ls
$ Gopkg.toml Gopkg.lock vendor/
If your project has dependencies they will be in the newly created
directory vendor
otherwise the directory will be empty. Check the
example.
When an app is deployed, Cloud Foundry reads this file and installs
the appropriate dependencies using the dep ensure
command.
You could now push your application cf push
if you would like to prevent
pushing the vendor
directory or other files like the README.md
, add them to
the .cfignore
file, see below.
Glide
For your own apps, you can create one by running glide init
.
The demo app you deployed already has a glide.yaml
, and it looks something like this:
package: github.com/swisscom/cf-sample-app-go
import: []
When an app is deployed, Cloud Foundry reads this file and installs the appropriate dependencies using the glide install
command.
Run this command in your local directory to install the dependencies, preparing your system for running the app locally:
$ glide install [INFO] Lock file (glide.lock) does not exist. Performing update. [INFO] Downloading dependencies. Please wait... [INFO] No references set. ...
As you can see, there are no dependencies to install for our sample app so we can just run it. The command did, however, create a glide.lock
file. It is good practice to push this to the cloud as well since it specifies which versions of dependencies to install exactly.
.cfignore
Upon running cf push
, we will also push our whole dependencies folder
vendor
. Since Cloud Foundry runs dep ensure
or glide install
anyways, this
is redundant and should be omitted to save bandwidth and even more importantly:
time. You can create a .cfignore
file which works just like a .gitignore
file and which tells Cloud Foundry what files should be excluded when pushing.
Let’s create a .cfignore
file and exclude the vendor
folder:
vendor
View the source for this page in GitHub