-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdependencies.html.md.erb
76 lines (53 loc) · 2.69 KB
/
dependencies.html.md.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
---
title: Declare App Dependencies
owner: Tobias Fuhrimann
---
<strong><%= modified_date %></strong>
<%= vars.product_short %> 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](https://github.com/golang/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](https://github.com/swisscom/cf-sample-app-go-dep/).
When an app is deployed, <%= vars.product_short %> 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](https://github.com/swisscom/cf-sample-app-go-dep/blob/master/.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:
```yaml
package: github.com/swisscom/cf-sample-app-go
import: []
```
When an app is deployed, <%= vars.product_short %> 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:
<pre class="terminal">
$ glide install
[INFO] Lock file (glide.lock) does not exist. Performing update.
[INFO] Downloading dependencies. Please wait...
[INFO] No references set.
...
</pre>
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:
```txt
vendor
```
<div style="text-align:center;margin:3em;">
<a href="./run-locally.html" class="btn btn-primary">I've installed the App dependencies locally</a>
</div>