Skip to content

Commit

Permalink
Merge pull request #15 from fahamutech/migrate_to_traefik_v2_and_bfas…
Browse files Browse the repository at this point in the history
…t_database_core_v4

migrate traefik configurations to v2 and bfast database core to v4
  • Loading branch information
joshuamshana authored Jan 1, 2022
2 parents 5c64bd6 + 8053c73 commit 8d27146
Show file tree
Hide file tree
Showing 4 changed files with 580 additions and 595 deletions.
53 changes: 23 additions & 30 deletions functions/factories/swarm-orchestration.factory.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ export class SwarmOrchestrationFactory extends OrchestrationAdapter {
* @return {Promise<string>}
*/
async functionsInstanceAddDomain(projectId, domain, force) {
try {
const response = await this.shell.exec(
`/usr/local/bin/docker service update ${force ? '--force ' : ' '} --label-add="traefik.frontend.rule"="Host:${projectId}-faas.bfast.fahamutech.com, ${domain}" ${projectId}_faas`
);
return response.toString();
} catch (e) {
throw {message: "Fails to add custom domain", reason: e.toString()};
}
// try {
// const response = await this.shell.exec(
// `/usr/local/bin/docker service update ${force ? '--force ' : ' '} --label-add="traefik.frontend.rule"="Host:${projectId}-faas.bfast.fahamutech.com, ${domain}" ${projectId}_faas`
// );
// return response.toString();
// } catch (e) {
throw {message: "not supported"};
// }
}

/**
Expand All @@ -108,13 +108,14 @@ export class SwarmOrchestrationFactory extends OrchestrationAdapter {
* @return {Promise<string>}
*/
async functionsInstanceRemoveDomain(projectId, force) {
try {
const response = await this.shell.exec(
`/usr/local/bin/docker service update ${force ? '--force' : ''} --label-add="traefik.frontend.rule=Host:${projectId}-faas.bfast.fahamutech.com" ${projectId}_faas`);
return response.toString();
} catch (e) {
throw {message: "Fails to remove all custom domain", reason: e.toString()};
}
// try {
// const response = await this.shell.exec(
// `/usr/local/bin/docker service update ${force ? '--force' : ''} --label-add="traefik.frontend.rule=Host:${projectId}-faas.bfast.fahamutech.com" ${projectId}_faas`);
// return response.toString();
// } catch (e) {
// throw {message: "Fails to remove all custom domain", reason: e.toString()};
// }
throw {message: "not supported"};
}

/**
Expand Down Expand Up @@ -233,16 +234,14 @@ export class SwarmOrchestrationFactory extends OrchestrationAdapter {
"--replicas 0",
"--restart-condition any",
"--restart-delay 5s",
// "--secret rsapub",
// "--secret rsapriv",
"--label \"traefik.docker.network=bfastweb\"",
"--label \"traefik.enable=true\"",
"--label \"traefik.port=3000\"",
"--label \"traefik.protocol=http\"",
"--label \"traefik.frontend.rule=Host:${projectId}-faas.${cluster}.${hostDomain}\"",
"--label \"traefik.backend.loadbalancer.stickiness=true\"",
"--label \"traefik.http.services.${projectId}-faas.loadbalancer.server.port=3000\"",
"--label \"traefik.http.routers.${projectId}-faas.rule=Host(`${projectId}-faas.${cluster}.${hostDomain}`)\"",
"--label \"traefik.http.services.${projectId}-faas.loadbalancer.sticky.cookie=true\"",
`--env \"WEB_3_TOKEN=${process.env.WEB_3_TOKEN}\"`,
"--env \"APPLICATION_ID=${appId}\"",
"--env \"MASTER_KEY=${masterKey}\"",
"--env \"PROJECT_ID=${projectId}\"",
`--env \"DATABASE_URI=mongodb://${project.parse.appId.toString().replace(new RegExp('[-]', 'ig'), '').trim()}:${project.parse.masterKey.toString().replace(new RegExp('[-]', 'ig'), '').trim()}@139.162.206.182:27017/${project.projectId}?authSource=admin\"`,
"--env \"PORT=3000\"",
Expand All @@ -251,7 +250,6 @@ export class SwarmOrchestrationFactory extends OrchestrationAdapter {
"joshuamshana/bfastfunction:latest",
];
if (dryRun === true) {
// console.log(commands.join('\n'));
console.log('-------dry run faas-----------');
return;
}
Expand Down Expand Up @@ -282,10 +280,9 @@ export class SwarmOrchestrationFactory extends OrchestrationAdapter {
"--restart-delay 5s",
"--label \"traefik.docker.network=bfastweb\"",
"--label \"traefik.enable=true\"",
"--label \"traefik.port=3000\"",
"--label \"traefik.protocol=http\"",
"--label \"traefik.frontend.rule=Host:${projectId}-daas.${cluster}.${hostDomain}\"",
"--label \"traefik.backend.loadbalancer.stickiness=true\"",
"--label \"traefik.http.services.${projectId}-daas.loadbalancer.server.port=3000\"",
"--label \"traefik.http.routers.${projectId}-daas.rule=Host(`${projectId}-daas.${cluster}.${hostDomain}`)\"",
"--label \"traefik.http.services.${projectId}-daas.loadbalancer.sticky.cookie=true\"",
"--env \"APPLICATION_ID=${appId}\"",
`--env \"WEB_3_TOKEN=${process.env.WEB_3_TOKEN}\"`,
"--env \"PROJECT_ID=${projectId}\"",
Expand All @@ -303,7 +300,6 @@ export class SwarmOrchestrationFactory extends OrchestrationAdapter {
"joshuamshana/bfastfunction:latest",
]
if (dryRun === true) {
// console.log(commands.join('\n'));
console.log('-----------dry run daas----------');
return;
}
Expand Down Expand Up @@ -338,7 +334,6 @@ export class SwarmOrchestrationFactory extends OrchestrationAdapter {
});
}


async instanceInfo(instanceId) {
const answer = await this.shell.exec(`/usr/local/bin/docker service inspect ${instanceId}`, {
env: {
Expand All @@ -348,7 +343,6 @@ export class SwarmOrchestrationFactory extends OrchestrationAdapter {
return JSON.parse(answer.toString().trim());
}


/**
*
* @param dryRun {boolean}
Expand All @@ -368,7 +362,6 @@ export class SwarmOrchestrationFactory extends OrchestrationAdapter {

}


async removeInstance(instanceId) {
return this.shell.exec(`/usr/local/bin/docker service rm ${instanceId}`, {
env: {
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bfast-cloud",
"description": "bfast cloud orchestration for project management",
"version": "2.2.5",
"version": "2.3.0",
"private": false,
"main": "functions/bfast-cloud.mjs",
"scripts": {
Expand All @@ -23,12 +23,12 @@
],
"dependencies": {
"bcryptjs": "~2.4.3",
"bfast": "~6.0.0-alpha.17",
"bfast-database-core": "~3.0.0-alpha.13",
"bfast": "~6.0.0-alpha.18",
"bfast-database-core": "~4.0.0-alpha.1",
"jsonwebtoken": "~8.5.1",
"keypairs": "~1.2.14",
"moment": "~2.29.1",
"mongodb": "~4.2.1",
"mongodb": "~4.2.2",
"sharp": "~0.29.3",
"uuid": "~8.3.2"
},
Expand All @@ -37,7 +37,7 @@
"@types/jsonwebtoken": "~8.5.6",
"@types/mongodb": "~4.0.7",
"@types/socket.io": "~3.0.2",
"bfast-function": "~2.0.0-alpha.7",
"bfast-function": "~2.0.0-alpha.9",
"chai": "~4.3.4",
"mocha": "~9.1.3"
}
Expand Down
17 changes: 9 additions & 8 deletions specs/src/users.router.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -313,14 +313,15 @@ describe('Users route', function () {
});
should().exist(user);
should().exist(detail);
should().exist(detail.createdAt);
should().exist(detail.updatedAt);
should().exist(detail.id);
expect(detail.displayName).equal('ethan');
expect(detail.phoneNumber).equal('0656');
expect(detail.email).equal('[email protected]');
expect(detail.username).equal('[email protected]');
expect(detail.role).equal('USER');
should().exist(detail.message);
expect(detail).eql({message: "done update", modified: 1})
// should().exist(detail.updatedAt);
// should().exist(detail.id);
// expect(detail.displayName).equal('ethan');
// expect(detail.phoneNumber).equal('0656');
// expect(detail.email).equal('[email protected]');
// expect(detail.username).equal('[email protected]');
// expect(detail.role).equal('USER');
});
// it('should not update un-changeable field for valid token', async function () {
// try {
Expand Down
Loading

0 comments on commit 8d27146

Please sign in to comment.