forked from sekassel-research/actions-rancher-update
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
48 lines (43 loc) · 1.41 KB
/
main.js
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
const core = require('@actions/core');
const axios = require('axios');
process.on('unhandledRejection', handleError);
main().catch(handleError);
async function main() {
const rancherUrl = core.getInput('rancher_url', {required: true});
const rancherToken = core.getInput('rancher_token', {required: true});
const clusterId = core.getInput('cluster_id', {required: true});
const projectId = core.getInput('project_id', {required: true});
const namespace = core.getInput('namespace', {required: true});
const deployment = core.getInput('deployment', {required: true});
const dockerImage = core.getInput('docker_image', {required: true});
await axios.patch(
`${rancherUrl}/k8s/clusters/${clusterId}/apis/apps/v1/namespaces/${namespace}/deployments/${deployment}`,
[
{
op: 'replace',
path: '/spec/template/spec/containers/0/image',
value: dockerImage,
},
],
{
headers: {
'Content-Type': 'application/json-patch+json',
'Authorization': 'Bearer ' + rancherToken,
},
},
);
await axios.post(
`${rancherUrl}/v3/projects/${clusterId}:${projectId}/workloads/deployment:${namespace}:${deployment}?action=redeploy`,
{},
{
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + rancherToken,
},
},
);
}
function handleError(err) {
console.log(err);
core.setFailed(err.message);
}