-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathgetting-started.html.md.erb
549 lines (368 loc) · 18.3 KB
/
getting-started.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
---
title: Getting started with the cf CLI
owner: CLI
---
The Cloud Foundry Command Line Interface (cf CLI) is the official command line client for Cloud Foundry. You can use the cf CLI to manage apps, service instances, orgs, spaces, and users in your environment.
## <a id='prerequisite'></a> Prerequisite
To follow the procedures in this topic, you must download and install the latest version of the cf CLI v7 or v8. For more information, see [Installing the Cloud Foundry command line interface](install-go-cli.html).
## <a id='login'></a> Log in with the CLI
The `cf login` command uses the syntax described below to specify a target API endpoint, login credentials, an org, and a space.
The cf CLI prompts for credentials as needed. If you are a member of multiple orgs or spaces, `cf login` prompts you to specify the org or space to which you
want to log in. Otherwise, it targets your org and space automatically.
To log in to the cf CLI:
1. In a terminal window, run:
```
cf login -a API-URL -u USERNAME -p PASSWORD -o ORG -s SPACE
```
Where:
<ul>
<li><code>API-URL</code> is your API endpoint, <%= vars.api_endpoint %>.</li>
<li><code>USERNAME</code> is your username.</li>
<li><code>PASSWORD</code> is your password. <%= vars.company_name %> discourages using the <code>-p</code> option, because it records your password in your shell history.</li>
<li><code>ORG</code> is the org where you want to deploy your apps.</li>
<li><code>SPACE</code> is the space in the org where you want to deploy your apps.</li>
</ul>
When you successfully log in, you see output similar to the following example:
<pre class="terminal">
API endpoint: https://api.example.com
Password>
Authenticating...
OK
Targeted org example-org
Targeted space development
API endpoint: https://api.example.com
User: username<span>@</span>example.com
Org: example-org
Space: development
</pre>
Alternatively, you can write a script to log in and set your target using the non-interactive `cf api`, `cf auth`, and `cf target` commands. See [UAAC](https://github.com/cloudfoundry/cf-uaac/blob/master/README.md) for setting up `client_id` and `client_secret`.
## <a id='login'></a> Log in with the API
You can write a script to log in to the cf CLI. This allows you to avoid manually logging in to the cf CLI each time you use it.
To write a script to log in:
1. In a terminal window, target your API by running:
```
cf api API-URL
```
Where `API-URL` is your API endpoint, <%= vars.api_endpoint %>.
<br>
<br>
For more information about the `cf api` command, use `cf api --help`.
1. Authenticate by running:
```
cf auth USERNAME PASSWORD
```
Where:
<ul>
<li><code>USERNAME</code> is your username.</li>
<li><code>PASSWORD</code> is your password. <%= vars.company_name %> discourages using the <code>-p</code> option, because it records your password in your shell history.</li>
</ul>
For more information about the `cf auth` command, use `cf auth --help`.
1. Target your org or space by running:
```
cf target -o ORG -s SPACE
```
Where:
<ul>
<li><code>ORG</code> is the org you want to target.</li>
<li><code>SPACE</code> is the space you want to target.</li>
</ul>
For more information about the `cf target` command, use `cf target --help`.
After you log in, the cf CLI saves a `config.json` file that contains your API endpoint, org, space values, and access token. If you change these settings,
the `config.json` file is updated accordingly.
By default, `config.json` is located in the `~/.cf` directory. You can relocate the `config.json` file using the `CF_HOME` environment variable.
## <a id='i18n'></a> Localize the cf CLI
The cf CLI translates terminal output into the language that you select. The default language is `en-US`.
The cf CLI supports these languages:
* Chinese (simplified): `zh-Hans`
* Chinese (traditional): `zh-Hant`
* English: `en-US`
* French: `fr-FR`
* German: `de-DE`
* Italian: `it-IT`
* Japanese: `ja-JP`
* Korean: `ko-KR`
* Portuguese (Brazil): `pt-BR`
* Spanish: `es-ES`
For more information about the `cf config --locale` command, use `cf config --help`.
Localizing the cf CLI affects only messages that the cf CLI generates.
To set the language of the cf CLI:
1. In a terminal window, log in to the cf CLI:
```
cf login
```
1. Run:
```
cf config --locale LANGUAGE
```
Where `LANGUAGE` is code of the language you want to set. Valid values are `zh-Hans`, `zh-Hant`, `en-US`, `fr-FR`, `de-DE`, `it-IT`, `ja-JP`, `ko-KR`,
`pt-BR`, and `es-ES`.
1. Confirm the language change by running:
```
cf help
```
The above command returns output similar to the example below:
<pre class="terminal">
NOME:
cf - Uma ferramenta de linha de comando para interagir com Cloud Foundry
USO:
cf [opções globais] comando [argumentos...] [opções de comando]
VERSÃO:
6.14.1
...
</pre>
## <a id='user-roles'></a> Manage users and roles
The cf CLI includes commands that list users and assign roles in orgs and spaces.
### <a id='listing-users'></a> List users
To list all users in an org or a space:
1. In a terminal window, log in to the cf CLI:
```
cf login
```
1. Run one of these commands:
* To list org users, run:
```
cf org-users ORG
```
Where `ORG` is the name of the org for which you want to see the list of users.
<br>
<br>
The above command returns output similar to the example below:
<pre class="terminal">
Getting users in org example-org as username<span>@</span>example.com...
ORG MANAGER
username<span>@</span>example.com
BILLING MANAGER
huey<span>@</span>example.com
dewey<span>@</span>example.com
ORG AUDITOR
louie<span>@</span>example.com
</pre>
* To list space users, run:
```
cf space-users ORG SPACE
```
Where:
<ul>
<li><code>ORG</code> is the name of the org that contains the space for which you want to see the list of users.</li>
<li><code>SPACE</code> is the name of the space for which you want to see the list of users.</li>
</ul>
The above command returns output similar to the example below:
<pre class="terminal">
Getting users in org example-org / space example-space as username<span>@</span>example.com...
SPACE MANAGER
username<span>@</span>example.com
SPACE DEVELOPER
huey<span>@</span>example.com
dewey<span>@</span>example.com
SPACE AUDITOR
louie<span>@</span>example.com
</pre>
For more information about the `cf org-users` command, use `cf org-users --help`. For
more information about the `cf space-users` command, use `cf space-users --help`.
### <a id='managing-roles'></a> Manage roles
You use the commands listed below to manage roles in the cf CLI. These commands require admin permissions and take `username`, `org` or `space`, and `role` as
arguments:
* `cf set-org-role`<br>For more information, use `cf set-org-role --help`.
* `cf unset-org-role`<br>For more information, use `cf unset-org-role --help`.
* `cf set-space-role`<br>For more information, use `cf set-space-role --help`.
* `cf unset-space-role`<br>For more information, use `cf unset-space-role --help`.
The available roles are:
* `OrgManager`
* `BillingManager`
* `OrgAuditor`
* `SpaceManager`
* `SpaceDeveloper`
* `SpaceAuditor`
For more information about user roles, see [Orgs, Spaces, Roles, and Permissions](../concepts/roles.html).
The following example shows the terminal output for `cf set-org-role [email protected] example-org OrgManager`, which assigns the Org Manager role to
`[email protected]` within the `example-org` org:
<pre class="terminal">
Assigning role OrgManager to user huey<span>@</span>example.com in org example-org as username<span>@</span>example.com...
OK
</pre>
<p class="note important">
If you are not an admin, you see this message when you try to run these commands: <code>error code: 10003, message: You
are not authorized to perform the requested action</code></p>
### <a id='multi-origin'></a> Manage roles for users with identical usernames in multiple origins
If a username corresponds to multiple accounts from different user stores, such as both the internal UAA store and an external SAML or LDAP store, running
either `cf set-org-role` or `cf unset-org-role` returns an error similar to the following example:
<pre class="terminal">The user exists in multiple origins. Specify an origin for the requested user from: ‘uaa’, ‘other’</pre>
To resolve this ambiguity, you can construct a `curl` command that uses the API to perform the desired role management function. For an example, see the
[Cloud Foundry API documentation](https://v3-apidocs.cloudfoundry.org/version/3.169.0/index.html#create-a-role).
## <a id='push'></a> Push an app
These sections describe how to use the `cf push` command to push a new app or sync changes to an existing app.
For more information about the `cf push` command, use `cf push --help`.
### <a id='push-procedure'></a> Push a new app or push changes to an app
To push an app:
1. In a terminal window, log in to the cf CLI by running:
```
cf login
```
1. Go to the directory of the app.
1. Push a new app or push changes to an app by running:
```
cf push APP-NAME
```
Where `APP-NAME` is the name of the app.
### <a id='push-path'></a> Push an app using a manifest
You can provide a path to a manifest file when you push an app. The manifest file includes information such as the name of the app, disk limit, and number
of instances. You can use a manifest file rather than adding flags to the `cf push` command.
`cf push` locates the `manifest.yml` file in the current working directory by default. Alternatively, you can provide a path to the manifest with the `-f`
flag.
For more information about the `-f` flag, see the `cf push --help` output.
<p class="note">
When you provide an app name at the command line, the <code>cf push</code> command uses that app
name instead of any app name provided in the manifest. If the manifest configures multiple apps, you can push a
single app by providing thenname at the command line; the cf CLI does not push the others. Use these behaviors for testing.</p>
### <a id='push-buildpack'></a> Push an app with a buildpack
You can specify a buildpack when you push an app with the `-b` flag. If you use the `-b` flag to specify a buildpack, the app remains permanently linked to
that buildpack. To use the app with a different buildpack, you must delete the app and then push it again.
For more information about available buildpacks, see the [Cloud Foundry documentation](https://docs.cloudfoundry.org/buildpacks/).
The following example shows the terminal output for `cf push awesome-app -b ruby_buildpack`, which pushes an app called `awesome-app` to the URL
`http://awesome-app.example.com` and specifies the Ruby buildpack with the `-b` flag:
<pre class="terminal">
Pushing app awesome-app to org example-org / space development as [email protected]...
...
Waiting for app awesome-app to start...
name: awesome-app
requested state: started
routes: awesome-app.example.com
last uploaded: Wed 17 Jul 22:57:04 UTC 2024
stack: cflinuxfs3
buildpacks:
name version detect output buildpack name
ruby_buildpack 1.8.58 ruby ruby
type: web
sidecars:
instances: 1/1
memory usage: 1024M
start command: bundle exec rackup config.ru -p $PORT -o 0.0.0.0
state since cpu memory disk logging cpu entitlement details
#0 running 2024-07-17T22:57:22Z 0.3% 49.5M of 1G 130.2M of 1G 0B/s of 16K/s 2.4%
</pre>
<p class="note important">
To avoid security exposure, verify that you migrate your apps and custom
buildpacks to use the <code>cflinuxfs4</code> stack based on Ubuntu 22.04 LTS (Jammy Jellyfish). The <code>cflinuxfs3</code> stack is
based on Ubuntu 18.04 (Bionic Beaver), which reaches end of standard support in April 2023.</p>
### <a id='new-route'></a> Map a route to an app
You can provide a hostname for your app when you push the app. If you do not provide a hostname, the `cf push` command routes your app to a URL of the form
`APP-NAME.DOMAIN`, where `APP-NAME` is the name of your app and `DOMAIN` is the default domain configured in the Cloud Foundry environment. The route definition is
included in the `manifest.yml` file.
For information about mapping a route to your app, see [Routes and domains](../devguide/deploy-apps/routes-domains.html).
To map a route to the app:
1. In a terminal window, log in to the cf CLI by running:
```
cf login
```
1. Push and map a route by running:
```
cf push -f manifest.yml --var host=APP-HOSTNAME
```
Where:
<ul>
<li><code>APP-NAME</code> is the name of the app.</li>
<li><code>APP-DOMAIN</code> is the domain of the app.</li>
<li><code>APP-HOSTNAME</code> is the hostname of the app.</li>
</ul>
## <a id='user-provided'></a> Manage user-provided service instances
These sections describe how to create or update a service instance.
### <a id='user-cups'></a> Create a service instance
To create a new service instance, use the `cf create-user-provided-service` or `cf cups` commands. For more information about the
`cf create-user-provided-service` and `cf cups` commands, use `cf create-user-provided-service --help`.
To create or update a user-provided service instance, you must supply basic parameters. For example, a database service might require a username, password,
host, port, and database name.
You can provide these parameters in the following ways:
* Interactively. For more information, see [Supply Parameters Interactively](#interactive) below.
* Non-interactively. For more information, see [Supply Parameters Non-Interactively](#non-interactive) below.
* With third-party log management software as described in RFC 6587. For more information, see [Supply Parameters Through a Third Party](#third-party) below
and [RFC 6587](http://tools.ietf.org/html/rfc6587).
When used with third-party logging, data is sent formatted according to RFC 5424. For more information, see
<a href="http://tools.ietf.org/html/rfc5424">RFC 5424</a>.
#### <a id='interactive'></a> Supply parameters interactively
To create a new service while supplying parameters interactively:
1. In a terminal window, log in to the cf CLI by running:
```
cf login
```
1. List parameters in a comma-separated list after the `-p` flag. Run:
```
cf cups SERVICE -p "PARAMETER, SECOND-PARAMETER, THIRD-PARAMETER"
```
Where:
<ul>
<li><code>SERVICE</code> is the name of the service you want to create.</li>
<li><code>PARAMETER</code>, <code>SECOND-PARAMETER</code>, and <code>THIRD-PARAMETER</code> are parameters such as username, password, host, port, and database name.</li>
</ul>
#### <a id='non-interactive'></a> Supply parameters non-interactively
To create a new service while supplying parameters non-interactively:
1. In a terminal window, log in to the cf CLI by running:
```
cf login
```
1. Pass parameters and their values in as a JSON hash, bound by single quotes, after the `-p` tag. Run:
```
cf cups SERVICE -p '{"host":"HOSTNAME", "port":"PORT"}'
```
Where:
<ul>
<li><code>SERVICE</code> is the name of the service you want to create.</li>
<li><code>HOSTNAME</code> and <code>PORT</code> are service parameters.</li>
</ul>
#### <a id='third-party'></a> Supply parameters through a third party
For specific log service instructions, see [Streaming app logs to third-party services](../devguide/services/log-management-thirdparty-svc.html).
To create a service instance that sends data to a third party:
1. Log in to the cf CLI:
```
cf login
```
1. Create a service instance that sends data to a third party by running:
```
cf cups SERVICE -l THIRD-PARTY-DESTINATION-URL
```
Where:
<ul>
<li><code>SERVICE</code> is the name of the service you want to create.</li>
<li><code>THIRD-PARTY-DESTINATION-URL</code> is the external URL of the third-party service.</li>
</ul>
### <a id='bind-unbind'></a> Bind and unbind service instances
After you create a user-provided service instance, you can:
* Bind the service to an app with `cf bind-service`. For more information, use `cf bind-service --help`.
* Unbind the service with `cf unbind-service`. For more information, use `cf unbind-service --help`.
* Rename the service with `cf rename-service`. For more information, use `cf rename-service --help`.
* Delete the service with `cf delete-service`. For more information, use `cf delete-service --help`.
### <a id='user-uups'></a> Update a service instance
To update one or more of the parameters for an existing user-provided service instance, use `cf update-user-provided-service` or `cf uups`.
For more information about the `cf update-user-provided-service` and `cf uups` commands, use `cf create-user-provided-service --help`.
The <code>cf uups</code> command does not update any parameter values that you do not supply.
## <a id='return-codes'></a> Retrieve cf CLI return codes
The cf CLI uses exit codes, which help with scripting and confirming that a command has run successfully.
To view a cf CLI exit code:
1. In a terminal window, log in to the cf CLI by running:
```
cf login
```
1. To check that the login was successful, run one of these commands, depending on your OS:
* For macOS, run:
```
echo $?
```
* For Windows, run:
```
echo %ERRORLEVEL%
```
If the command succeeds, the exit code is `0`.
## <a id='help'></a> View CLI help output
The `cf help` command lists the cf CLI commands and a brief description of each..
To list detailed help for any cf CLI command, add the `--help` or `-h` flag to the command.
The example below shows detailed help output for the `cf delete` command:
<pre class="terminal">
NAME:
delete - Delete an app
USAGE:
cf delete APP_NAME [-f -r]
ALIAS:
d
OPTIONS:
-f Force deletion without confirmation
-r Delete any mapped routes (only deletes routes mapped to a single app)
</pre>