alphayax / rancher-api
Rancher的基本API
2.0.4
2018-05-31 09:33 UTC
Requires
- alphayax/get_opt: ^3.0.0
- guzzlehttp/guzzle: ~6.0
README
基于RancherAPI的一个非常基本的工具
安装
此包在composer中可用。要使用它,只需按照以下要求:
composer require alphayax/rancher-api
如何使用
注意,您需要在Rancher中生成一个API密钥才能使用此工具。(在API -> Keys菜单下)
使用新Docker镜像更新Rancher服务
适用于持续部署
$client = new \alphayax\rancher_api\Client($rancherUrl, $rancherKey, $rancherSecret);
$client->upgradeFromProjectIdAndServiceId($projectId, $serviceId);
命令行界面
您可以使用以下CLI脚本: vendor/bin/rancher_update.php
持续部署
基本的Gitlab CI示例
$RANCHER_SECRET
、$RANCHER_KEY
和$RANCHER_URL
的值可在Rancher的API -> Key菜单下找到
在Gitlab仓库设置中,在CI/CD配置下,添加以下秘密变量
$RANCHER_URL
(例如:http://www.example.com:8080/v2-beta
)$RANCHER_SECRET
(例如:sdf45gsdfg12sd3f1gs5dfg1sd23fg1s5df1
)$RANCHER_KEY
(例如:123456789ABCDEF12345
)$RANCHER_ENVIRONMENT
(例如:1a2
)
在您的
.gitlab-ci.yaml
文件中,声明deploy
阶段并将以下内容放入其中
.deploy: &deploy
stage: deploy
image: composer
variables:
GIT_STRATEGY: none
RANCHER_SERVICE: 1s220
tags:
- composer
only:
- master
script:
- composer require alphayax/rancher-api
- vendor/bin/rancher_update.php --rancher-url $RANCHER_URL --rancher-secret $RANCHER_SECRET --rancher-key $RANCHER_KEY --rancher-project-id $RANCHER_ENVIRONMENT --rancher-service-id $RANCHER_SERVICE