2 * Copyright © 2016-2017 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 const fs = require('fs');
20 var pathToRoot = process.env.TESTS_BASE;
21 if (!pathToRoot.endsWith("/")) {
24 var envConfig = require(pathToRoot + 'config.json');
25 var protocol = (process.env.PROTOCOL !== undefined) ? process.env.PROTOCOL : 'https';
28 envConfig = require(pathToRoot + 'environments/dockerConfig.json');
33 var inputArgs = process.argv.slice(2);
34 let changeConfig = false;
35 if (process.env.K8S_CONF_PATH !== undefined) {
36 console.log('updating with kubernetes services');
37 let k8sConfig = require(pathToRoot + process.env.K8S_CONF_PATH);
38 mapK8sPod2Docker(k8sConfig, inputArgs[0], inputArgs[1]);
41 console.log('not updating at all');
44 let data = JSON.stringify(envConfig, null, 2);
45 console.log('writing config file: ' + pathToRoot+'environments/dockerConfig.json');
47 fs.writeFileSync(pathToRoot+'environments/dockerConfig.json', data);
51 function mapK8sPod2Docker(k8sConfig, id, k8sid) {
52 let item = k8sConfig.items.find(item => {
53 if (item.spec !== undefined && item.spec.ports !== undefined) {
54 let spec = item.spec.ports.find(port => {
55 if (port.name === k8sid) {
59 return (spec !== undefined);
65 item.spec.ports.forEach(port => {
66 if (port.name === k8sid) {
67 envConfig[id].port = port.nodePort;
68 let rancherData = JSON.parse(item.metadata.annotations["field.cattle.io/publicEndpoints"]);
69 let address = rancherData.find(address => {
70 return address.port === port.nodePort;
72 envConfig[id].port = address.port;
73 envConfig[id].server = address.addresses[0];
74 envConfig[id].protocol = protocol;
75 envConfig[id].user = process.env.SDC_USER_ID;