mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
Reorg script moving in folders (#4791)
* organize script in folder part 1 * improve test e2e * fix smart build script * fix relative path
This commit is contained in:
@@ -6,10 +6,10 @@ cd $DIR/../../../
|
||||
|
||||
#if [ "$TRAVIS_PULL_REQUEST" != "false" ];
|
||||
#then
|
||||
node ./scripts/move-dist-folder.js --base-href $TRAVIS_BUILD_NUMBER && (./scripts/pr-publish.sh -n $TRAVIS_BUILD_NUMBER -r $REPO_DOCKER -u $USERNAME_DOCKER -p $PASSWORD_DOCKER || exit 1);
|
||||
node ./scripts/travis/deploy/move-dist-folder.js --base-href $TRAVIS_BUILD_NUMBER && (./scripts/travis/deploy/pr-publish.sh -n $TRAVIS_BUILD_NUMBER -r $REPO_DOCKER -u $USERNAME_DOCKER -p $PASSWORD_DOCKER || exit 1);
|
||||
#fi;
|
||||
|
||||
#if [ "$TRAVIS_PULL_REQUEST" != "false" ];
|
||||
#then
|
||||
(node --no-deprecation ./scripts/pr-deploy.js -n $TRAVIS_BUILD_NUMBER -u $RANCHER_TOKEN -p $RANCHER_SECRET -s $REPO_RANCHER --image "docker:$REPO_DOCKER/adf/demo-shell:$TRAVIS_BUILD_NUMBER" --env $ENVIRONMENT_NAME -r $ENVIRONMENT_URL || exit 1);
|
||||
(node --no-deprecation ./scripts/travis/deploy/pr-deploy.js -n $TRAVIS_BUILD_NUMBER -u $RANCHER_TOKEN -p $RANCHER_SECRET -s $REPO_RANCHER --image "docker:$REPO_DOCKER/adf/demo-shell:$TRAVIS_BUILD_NUMBER" --env $ENVIRONMENT_NAME -r $ENVIRONMENT_URL || exit 1);
|
||||
#fi;
|
||||
|
65
scripts/travis/deploy/move-dist-folder.js
Executable file
65
scripts/travis/deploy/move-dist-folder.js
Executable file
@@ -0,0 +1,65 @@
|
||||
var program = require('commander');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var ncp = require('ncp').ncp;
|
||||
var rimraf = require('rimraf');
|
||||
|
||||
ncp.limit = 16;
|
||||
|
||||
replaceHrefInIndex = (href) => {
|
||||
fs.readFile(`demo-shell/dist/${href}/index.html`, 'utf8', function (err, data) {
|
||||
if (err) {
|
||||
return console.log(err);
|
||||
}
|
||||
|
||||
let result = data.replace(`base href="/"`, `base href=\"/${href}/\"`);
|
||||
|
||||
fs.writeFile(`demo-shell/dist/${href}/index.html`, result, 'utf8', function (err) {
|
||||
if (err) return console.log(err);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
async function main() {
|
||||
|
||||
program
|
||||
.version('0.1.0')
|
||||
.option('--base-href [type]', '')
|
||||
.parse(process.argv);
|
||||
|
||||
|
||||
let outputTemp = path.resolve(__dirname, '../demo-shell/', program.baseHref);
|
||||
console.log('output ' + outputTemp);
|
||||
|
||||
let distFolder = path.resolve(__dirname, '../demo-shell/dist');
|
||||
|
||||
fs.rename(distFolder, outputTemp, (err) => {
|
||||
if (err) throw err;
|
||||
console.log('renamed complete');
|
||||
|
||||
let distFolderNew = path.resolve(__dirname, '../demo-shell/dist', program.baseHref);
|
||||
|
||||
if (!fs.existsSync(distFolderNew)){
|
||||
fs.mkdirSync(distFolder);
|
||||
fs.mkdirSync(distFolderNew);
|
||||
}
|
||||
|
||||
ncp(outputTemp, distFolderNew, (err) => {
|
||||
if (err) {
|
||||
return console.error(err);
|
||||
}
|
||||
|
||||
replaceHrefInIndex(program.baseHref);
|
||||
|
||||
rimraf(outputTemp, ()=> { console.log('output temp removed'); });
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
main();
|
||||
|
||||
|
260
scripts/travis/deploy/pr-deploy.js
Normal file
260
scripts/travis/deploy/pr-deploy.js
Normal file
@@ -0,0 +1,260 @@
|
||||
var program = require('commander');
|
||||
var request = require('request');
|
||||
|
||||
function asyncRequest(option) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
request(option, function (error, res, body) {
|
||||
if (!error && (res.statusCode == 200 || res.statusCode == 201)) {
|
||||
resolve(body);
|
||||
} else {
|
||||
console.log("Error " + JSON.stringify(body));
|
||||
reject(error + JSON.stringify(body));
|
||||
throw "Error";
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function main() {
|
||||
|
||||
program
|
||||
.version('0.1.0')
|
||||
.option('-n, --name [type]', 'Name to give at the service in rancher')
|
||||
.option('-r, --remote [type]', 'Remote environment host adf.lab.com ')
|
||||
.option('-e, --env [type]', 'Name to give at the service in rancher')
|
||||
.option('-i, --image [type]', 'Docker image to load')
|
||||
.option('-s, --server [type]', 'Server RANCHER_SERVER URL')
|
||||
.option('-p, --password [type]', 'password RANCHER')
|
||||
.option('-u, --username [type]', 'username RANCHER')
|
||||
.parse(process.argv);
|
||||
|
||||
auth = 'Basic ' + new Buffer(program.username + ':' + program.password).toString('base64');
|
||||
|
||||
var project = await asyncRequest({
|
||||
url: program.server + `/v1/project?name=${program.env}`,
|
||||
method: 'GET',
|
||||
json: true,
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
"accept": "application/json",
|
||||
"Authorization": auth
|
||||
},
|
||||
body: ""
|
||||
}).catch((error) => {
|
||||
console.log('Project name error'+ error);
|
||||
});
|
||||
|
||||
var stacks = await asyncRequest({
|
||||
url: `${program.server}/v2-beta/projects/${project.data[0].id}/stacks?limit=-1&sort=name`,
|
||||
method: 'GET',
|
||||
json: true,
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
"accept": "application/json",
|
||||
"Authorization": auth
|
||||
},
|
||||
body: ""
|
||||
}).catch((error) => {
|
||||
console.log('Stacks error'+ error);
|
||||
});
|
||||
|
||||
|
||||
var stackId = stacks.data[0].id;
|
||||
var environmentId = project.data[0].id;
|
||||
|
||||
console.log("StackId " + stackId);
|
||||
console.log("ID environment " + environmentId);
|
||||
console.log("image to Load " + program.image);
|
||||
|
||||
var postData = {
|
||||
"scale": 1,
|
||||
"assignServiceIpAddress": false,
|
||||
"startOnCreate": true,
|
||||
"type": "service",
|
||||
"stackId": stackId,
|
||||
"launchConfig": {
|
||||
"instanceTriggeredStop": "stop",
|
||||
"kind": "container",
|
||||
"networkMode": "managed",
|
||||
"privileged": false,
|
||||
"publishAllPorts": false,
|
||||
"readOnly": false,
|
||||
"runInit": false,
|
||||
"startOnCreate": true,
|
||||
"stdinOpen": true,
|
||||
"tty": true,
|
||||
"vcpu": 1,
|
||||
"drainTimeoutMs": 0,
|
||||
"type": "launchConfig",
|
||||
"labels": {"io.rancher.container.pull_image": "always"},
|
||||
"restartPolicy": {"name": "always"},
|
||||
"secrets": [],
|
||||
"dataVolumes": [],
|
||||
"dataVolumesFrom": [],
|
||||
"dns": [],
|
||||
"dnsSearch": [],
|
||||
"capAdd": [],
|
||||
"capDrop": [],
|
||||
"devices": [],
|
||||
"logConfig": {"driver": "", "config": {}},
|
||||
"dataVolumesFromLaunchConfigs": [],
|
||||
"imageUuid": program.image,
|
||||
"ports": [],
|
||||
"blkioWeight": null,
|
||||
"cgroupParent": null,
|
||||
"count": null,
|
||||
"cpuCount": null,
|
||||
"cpuPercent": null,
|
||||
"cpuPeriod": null,
|
||||
"cpuQuota": null,
|
||||
"cpuRealtimePeriod": null,
|
||||
"cpuRealtimeRuntime": null,
|
||||
"cpuSet": null,
|
||||
"cpuSetMems": null,
|
||||
"cpuShares": null,
|
||||
"createIndex": null,
|
||||
"created": null,
|
||||
"deploymentUnitUuid": null,
|
||||
"description": null,
|
||||
"diskQuota": null,
|
||||
"domainName": null,
|
||||
"externalId": null,
|
||||
"firstRunning": null,
|
||||
"healthInterval": null,
|
||||
"healthRetries": null,
|
||||
"healthState": null,
|
||||
"healthTimeout": null,
|
||||
"hostname": null,
|
||||
"ioMaximumBandwidth": null,
|
||||
"ioMaximumIOps": null,
|
||||
"ip": null,
|
||||
"ip6": null,
|
||||
"ipcMode": null,
|
||||
"isolation": null,
|
||||
"kernelMemory": null,
|
||||
"memory": null,
|
||||
"memoryMb": null,
|
||||
"memoryReservation": null,
|
||||
"memorySwap": null,
|
||||
"memorySwappiness": null,
|
||||
"milliCpuReservation": null,
|
||||
"oomScoreAdj": null,
|
||||
"pidMode": null,
|
||||
"pidsLimit": null,
|
||||
"removed": null,
|
||||
"requestedIpAddress": null,
|
||||
"shmSize": null,
|
||||
"startCount": null,
|
||||
"stopSignal": null,
|
||||
"stopTimeout": null,
|
||||
"user": null,
|
||||
"userdata": null,
|
||||
"usernsMode": null,
|
||||
"uts": null,
|
||||
"uuid": null,
|
||||
"volumeDriver": null,
|
||||
"workingDir": null,
|
||||
"networkLaunchConfig": null
|
||||
},
|
||||
"secondaryLaunchConfigs": [],
|
||||
"name": program.name,
|
||||
"createIndex": null,
|
||||
"created": null,
|
||||
"description": null,
|
||||
"externalId": null,
|
||||
"healthState": null,
|
||||
"kind": null,
|
||||
"removed": null,
|
||||
"selectorContainer": null,
|
||||
"selectorLink": null,
|
||||
"uuid": null,
|
||||
"vip": null,
|
||||
"fqdn": null
|
||||
};
|
||||
|
||||
var createService = await asyncRequest({
|
||||
url: `${program.server}/v2-beta/projects/${environmentId}/service`,
|
||||
method: 'POST',
|
||||
json: true,
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
"accept": "application/json",
|
||||
"Authorization": auth
|
||||
},
|
||||
body: postData,
|
||||
}).catch((error) => {
|
||||
console.log('Error createService'+ error);
|
||||
});
|
||||
|
||||
if (!createService) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("New environment ID " + createService.id);
|
||||
|
||||
var loadBalancer = await asyncRequest({
|
||||
url: `${program.server}/v1/projects/${environmentId}/loadbalancerservices`,
|
||||
method: 'GET',
|
||||
json: true,
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
"accept": "application/json",
|
||||
"Authorization": auth
|
||||
},
|
||||
body: postData,
|
||||
}).catch((error) => {
|
||||
console.log('Error loadBalancer'+ error);
|
||||
});
|
||||
|
||||
if (!loadBalancer) {
|
||||
return;
|
||||
}
|
||||
|
||||
var loadBalancerId = loadBalancer.data[0].id;
|
||||
console.log("Load balancer ID " + loadBalancerId);
|
||||
|
||||
var loadBalancerGet = await asyncRequest({
|
||||
url: `${program.server}/v2-beta/projects/${environmentId}/loadbalancerservices/${loadBalancerId}`,
|
||||
method: 'GET',
|
||||
json: true,
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
"accept": "application/json",
|
||||
"Authorization": auth
|
||||
}
|
||||
}).catch((error) => {
|
||||
console.log('Error get load balancer'+ error);
|
||||
});
|
||||
|
||||
//console.log("Load balancer ID " + JSON.stringify(loadBalancerGet.lbConfig.portRules));
|
||||
|
||||
var newRule = {
|
||||
"type": "portRule",
|
||||
"hostname": program.remote,
|
||||
"path": `/${program.name}`,
|
||||
"priority": 1,
|
||||
"protocol": "http",
|
||||
"serviceId": createService.id,
|
||||
"sourcePort": 80,
|
||||
"targetPort": 8080
|
||||
};
|
||||
|
||||
loadBalancerGet.lbConfig.portRules.push(newRule);
|
||||
|
||||
await asyncRequest({
|
||||
url: `${program.server}/v2-beta/projects/${environmentId}/loadbalancerservices/${loadBalancerId}`,
|
||||
method: 'PUT',
|
||||
json: true,
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
"accept": "application/json",
|
||||
"Authorization": auth
|
||||
},
|
||||
body: loadBalancerGet
|
||||
}).catch((error) => {
|
||||
console.log('Error Update load balancer'+ error);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
main();
|
51
scripts/travis/deploy/pr-publish.sh
Executable file
51
scripts/travis/deploy/pr-publish.sh
Executable file
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env bash
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
|
||||
show_help() {
|
||||
echo "Usage: pr-publish.sh"
|
||||
echo ""
|
||||
echo "-n or --name pr name"
|
||||
echo "-r or --repo docker repository url"
|
||||
}
|
||||
|
||||
name_pr(){
|
||||
NAME_PR=$1
|
||||
}
|
||||
|
||||
name_docker_repo(){
|
||||
DOCKER_REPO=$1
|
||||
}
|
||||
|
||||
username_docker_repo(){
|
||||
USERNAME_DOCKER=$1
|
||||
}
|
||||
|
||||
password_docker_repo(){
|
||||
PASSWORD_DOCKER=$1
|
||||
}
|
||||
|
||||
while [[ $1 == -* ]]; do
|
||||
case "$1" in
|
||||
-h|--help|-\?) show_help; exit 0;;
|
||||
-n|--name) name_pr $2; shift 2;;
|
||||
-r|--repo) name_docker_repo $2; shift 2;;
|
||||
-u|--username) username_docker_repo $2; shift 2;;
|
||||
-p|--password) password_docker_repo $2; shift 2;;
|
||||
-*) echo "invalid option: $1" 1>&2; show_help; exit 0;;
|
||||
esac
|
||||
done
|
||||
|
||||
cd $DIR/..
|
||||
|
||||
echo "====== PUBLISH DOCKER IMAGE TAG pr $NAME_PR ====="
|
||||
|
||||
docker build -t $DOCKER_REPO/adf/demo-shell:$NAME_PR --build-arg BUILD_NUMBER=$NAME_PR .
|
||||
|
||||
echo "====== LOGIN ====="
|
||||
docker login http://$DOCKER_REPO -p $PASSWORD_DOCKER -u $USERNAME_DOCKER
|
||||
docker push "$DOCKER_REPO/adf/demo-shell:$NAME_PR"
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user