I am trying to use the Rancher API to do automated deployments. Every time a new docker image is available, I want to upgrade the Service to use the new image version. Looking at the upgrade API, I can see in the inputs are:
HTTP/1.1 POST /v1/projects/1a8/services/1s6/?action=upgrade
Host: rancher.blah.com.au
Accept: application/json
Content-Type: application/json
Content-Length: 51
{
"inServiceStrategy": null,
"toServiceStrategy": null,
}
Please advise what are these input fields? All I want to do is update the following field and kick off the upgrade:
imageUuid: "docker:blah/blah:v0.1"
Thanks
1 Like
alena
January 15, 2016, 5:51pm
2
@yunspace for your use case, you would have to use âinServiceStrategyâ for the upgrade, and:
fetch service.launchConfig field of your service-to-upgrade
update image field in the launchConfig fetched on the previous step, and pass it as enclosed field to inServiceStrategy parameter for the upgrade:
"inServiceStrategy": {
"launchConfig": {
"tty":true,
"vcpu":1,
"imageUuid":"docker:ubuntu:14.04.3"
//...and other parameters of your existing service's launch config
}
}
3 Likes
Thanks, that answered my question. I will try it out
Hi, need a small help
how did u fetch the service.launchConfig of your corresponding service ?
@Sadish_Kumar - I simplified my life and I wrote a python script that does that - if that helps: https://github.com/etlweather/gaucho
3 Likes
@Sadish_Kumar similar to @etlweather , I also have a script https://github.com/LittleBayDigital/little-builder/blob/master/bin/lib/_rancher.sh
Basically what it does is:
Gets the service using the API ${RANCHER_API_URL}/projects/${environment}/services/${service}/
Updates the updatedServiceStrategy
Send a Update request
Actually I think @etlweather âs script is a lot nicer than my one. Use his!
For automated deployment, in my case, upon tags in GitLab, I created a container which runs on Rancher using webhook to create the web API and upon HTTP requests, it runs commands using gaucho to upgrade the containers.
Then in GltLab CI, upon build with a tag, I simply use curl
to call the HTTP endpoint to cause the service to be upgraded.
1 Like
hello
Is there a way, updating via rancher API, to keep previous configurations and only updating the docker image?
thanks in advance
Hi Vincent,
Can you share how can we do that ( update an worklaod or servic to use different contianer image and keep other config as it is ) or direct us to some links where the porcess is menioned.
myclau
August 10, 2018, 5:21am
13
I try a easy approach.
using rancher cli grep the service id
~/rancher ps | grep service | grep -w ${RANCHER_SERVICE_NAME}
curl get api json with the serviceid from (1)
from the json in (2) use jq get .launchConfig (if you have sidekick, please also get .secondaryLaunchConfigs i.e is array)
create the request data json obj and pass in the data from (3)
appendsecondaryLaunchConfigs=[ "${secondaryLaunchConfigs}" = null ] && echo "" || echo ",\"secondaryLaunchConfigs\": ${secondaryLaunchConfigs-n
ull}"`
echo â{
"inServiceStrategy": {
"type": "inServiceUpgradeStrategy",
"batchSize": 1,
"intervalMillis": 2000,
"startFirst": false,
"launchConfig": ${launchConfig-null}
${appendsecondaryLaunchConfigs}
}
` }â | jq . > update-request-data.json
the change the imageuuid in update-request-data.json
if not sidekick:
updatedServiceStrategy=cat update-request-data.json | jq ".inServiceStrategy.launchConfig.imageUuid=\"docker:${image}\""
is sidekick (you need to specify which sidekick if you have mutiple, if only one sidekickindex is 0):
updatedServiceStrategy=cat update-request-data.json | jq ".inServiceStrategy.secondaryLaunchConfigs[${sidekickindex}].imageUuid=\"docker:${image}\""
send request to api with ?action=upgrade
curl --silent --write-out âUpgrade service - HTTP: %{http_code}\nâ -u â${RANCHER_ACCESS_KEY}:${RANCHER_SECRET_KEY}â
-X POST
-H âAccept: application/jsonâ
-H âContent-Type: application/jsonâ
-d â${updatedServiceStrategy}â
â${RANCHER_API_URL}/projects/${environment}/services/${serviceid}/?action=upgradeâ -o upgrade.log
curl -u â64247E71B0B579E7A393:8NTg8FHftrcUfiU5kXUN37ARjgHvmgVfnNezfhHpâ -X POST -H âAccept: application/jsonâ -H âContent-Type: application/jsonâ -d â{âinServiceStrategyâ:{âlaunchConfigâ:{âttyâ:true, âvcpuâ:1, âimageUuidâ:âdocker:tomcat:9.0-jre8â}}â âhttp://10.10.1.8:8080/v2-beta/projects/1a7/services/1s88/?action=upgrade â
{âidâ:âf0d4f155-58c8-4377-8f1a-13a959e4c284â,âtypeâ:âerrorâ,âlinksâ:{},âactionsâ:{},âstatusâ:400,âcodeâ:âInvalidBodyContentâ,âmessageâ:âInvalidBodyContentâ,âdetailâ:null,âbaseTypeâ:âerrorâ}