How to restage an app directly using V3 APIs (with examples) - cloudfoundry/cloud_controller_ng GitHub Wiki
- Fetch the current droplet of the app to retrieve it's "current" package.
- Endpoint:
GET /v3/apps/:guid/droplets/current
- Docs: Get Current Droplet
- Example:
$ cf curl /v3/apps/$(cf app my-app --guid)/droplets/current | jq .links.package.href
"https://api.neon-bite.capi.land/v3/packages/63f8c286-0df6-4837-86c8-544b594ab429"
-
Grab the package guid from the link. In the example above this would be:
63f8c286-0df6-4837-86c8-544b594ab429
-
Create a build (restage the package without affecting the app). This is functionally the same as
cf v3-stage
.
- Endpoint:
POST /v3/builds
- Docs: Create a build
- Example:
$ cf curl -X POST /v3/builds -d '{ "package": { "guid": "63f8c286-0df6-4837-86c8-544b594ab429" } }'
{
"guid": "61b9dbea-a4da-479c-8873-31247cb1c1e6",
"created_at": "2019-04-30T18:07:06Z",
"updated_at": "2019-04-30T18:07:06Z",
"state": "STAGING",
"error": null,
"lifecycle": {
"type": "buildpack",
"data": {
"buildpacks": [],
"stack": "cflinuxfs3"
}
},
"package": {
"guid": "63f8c286-0df6-4837-86c8-544b594ab429"
},
"droplet": null,
"metadata": {
"labels": {},
"annotations": {}
},
"links": {
"self": {
"href": "https://api.neon-bite.capi.land/v3/builds/61b9dbea-a4da-479c-8873-31247cb1c1e6"
},
"app": {
"href": "https://api.neon-bite.capi.land/v3/apps/6efc923a-82fe-4ff2-82c2-d8ae65927c12"
}
},
"created_by": {
"guid": "dc72353e-3d76-4f7b-8de7-f582a5e6ab20",
"name": "admin",
"email": "admin"
}
}
- Poll the status of the build until it succeeds (or fails)
- Endpoint:
GET /v3/builds/:guid
- Docs: Get a build
- Example:
$ cf curl /v3/builds/61b9dbea-a4da-479c-8873-31247cb1c1e6
{
"guid": "61b9dbea-a4da-479c-8873-31247cb1c1e6",
"created_at": "2019-04-30T18:07:06Z",
"updated_at": "2019-04-30T18:07:12Z",
"state": "STAGED",
"error": null,
"lifecycle": {
"type": "buildpack",
"data": {
"buildpacks": [
"staticfile_buildpack"
],
"stack": "cflinuxfs3"
}
},
"package": {
"guid": "63f8c286-0df6-4837-86c8-544b594ab429"
},
"droplet": {
"guid": "b6b19703-22f7-41a8-b31a-c351237530a0",
"href": "https://api.neon-bite.capi.land/v3/droplets/b6b19703-22f7-41a8-b31a-c351237530a0"
},
"metadata": {
"labels": {},
"annotations": {}
},
"links": {
"self": {
"href": "https://api.neon-bite.capi.land/v3/builds/61b9dbea-a4da-479c-8873-31247cb1c1e6"
},
"app": {
"href": "https://api.neon-bite.capi.land/v3/apps/6efc923a-82fe-4ff2-82c2-d8ae65927c12"
}
},
"created_by": {
"guid": "dc72353e-3d76-4f7b-8de7-f582a5e6ab20",
"name": "admin",
"email": "admin"
}
}
- Note the
state
field. If the state isSTAGED
Grab the droplet guid from the response.
$ cf curl /v3/builds/61b9dbea-a4da-479c-8873-31247cb1c1e6 | jq .droplet.guid
"b6b19703-22f7-41a8-b31a-c351237530a0"
- Update the app to use the new droplet guid (same as
cf v3-set-droplet
).
- Endpoint:
PATCH /v3/apps/:guid/relationships/current_droplet
- Docs: Set current droplet
- Example:
$ cf curl -X PATCH /v3/apps/$(cf app my-app --guid)/relationships/current_droplet -d '{ "data": { "guid": "b6b19703-22f7-41a8-b31a-c351237530a0" } }'
{
"data": {
"guid": "b6b19703-22f7-41a8-b31a-c351237530a0"
},
"links": {
"self": {
"href": "https://api.neon-bite.capi.land/v3/apps/6efc923a-82fe-4ff2-82c2-d8ae65927c12/relationships/current_droplet"
},
"related": {
"href": "https://api.neon-bite.capi.land/v3/apps/6efc923a-82fe-4ff2-82c2-d8ae65927c12/droplets/current"
}
}
}
- Now restart the app to run it with this new droplet using
cf restart
orcf v3-zdt-restart
(on newer Cloud Foundry foundations that support the beta rolling app deployments feature).