Apigee does not provide zero downtime deployments for resources hosted at the environment level. Nevertheless, we could handle this by versioning the resource files and updating the relevant API proxies accordingly. The following approach could be used for updating JavaScript resource files stored at the environment level without taking a downtime for updating them.
1. First, a JavaScript file could be uploaded to an environment by appending a version number to the filename as follows:
curl -i -u $username:$password -F "file=@hello-v1.js" -H 'Content-Type: multipart/form-data' "https://api.enterprise.apigee.com/v1/organizations/${org_name}/environments/${env_name}/resourcefiles?name=hello-v1.js&type=jsc"
HTTP/1.1 201 Created Access-Control-Allow-Headers: origin, x-requested-with, accept Access-Control-Allow-Methods: GET, PUT, POST, DELETE Access-Control-Allow-Origin: * Access-Control-Max-Age: 3628800 Content-Type: application/json Date: Thu, 14 Feb 2019 00:20:25 GMT Server: Apigee LB Content-Length: 46 Connection: keep-alive { "name" : "hello-v1.js", "type" : "jsc" }
2. Afterwards, it can be referred in an API proxy as follows:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Javascript async="false" continueOnError="false" enabled="true" timeLimit="200" name="Hello-JavaScript"> <DisplayName>Hello-JavaScript</DisplayName> <Properties/> <ResourceURL>jsc://hello-v1.js</ResourceURL> </Javascript> <PreFlow name="PreFlow"> <Request> <Step> <Name>Hello-JavaScript</Name> </Step> </Request> <Response/> </PreFlow>
3. Then, when the above JavaScript file needs to be updated, a new file can be created with the updated content with a new version number. It can be uploaded to the environment with a new resource name as follows:
curl -i -u $username:$password -F "file=@hello-v2.js" -H 'Content-Type: multipart/form-data' "https://api.enterprise.apigee.com/v1/organizations/${org_name}/environments/${env_name}/resourcefiles?name=hello-v2.js&type=jsc"
HTTP/1.1 201 Created Access-Control-Allow-Headers: origin, x-requested-with, accept Access-Control-Allow-Methods: GET, PUT, POST, DELETE Access-Control-Allow-Origin: * Access-Control-Max-Age: 3628800 Content-Type: application/json Date: Thu, 14 Feb 2019 00:25:23 GMT Server: Apigee LB Content-Length: 46 Connection: keep-alive { "name" : "hello-v2.js", "type" : "jsc" }
4. Afterwards, we may need to update the JavaScript policy in the API proxy with the new version number. If there are multiple API proxies using this resource, we may need to update all of them:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Javascript async="false" continueOnError="false" enabled="true" timeLimit="200" name="Hello-JavaScript"> <DisplayName>Hello-JavaScript</DisplayName> <Properties/> <ResourceURL>jsc://hello-v2.js</ResourceURL> </Javascript>
This process would allow us to propogate changes to JavaScript resources hosted at the environment level without taking a downtime.