Skip to content

Commit

Permalink
Add deploy metabase command
Browse files Browse the repository at this point in the history
  • Loading branch information
francois2metz committed Jun 13, 2022
1 parent 25d835d commit c76b431
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 2 deletions.
6 changes: 5 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,16 @@ module.exports = (function() {
PIX_LCMS_APP_NAME: 'pix-lcms',
PIX_UI_REPO_NAME: 'pix-ui',
PIX_EMBER_TESTING_LIBRARY_REPO_NAME: 'ember-testing-library',
PIX_SITE_REPO_NAME: 'pix-site',
PIX_DB_STATS_REPO_NAME: 'pix-db-stats',
PIX_DB_STATS_APPS_NAME: ['pix-db-stats', 'pix-db-stats-datawarehouse', 'pix-db-stats-datawarehouse-ext'],
PIX_SITE_REPO_NAME: 'pix-site',
PIX_SITE_APPS: ['pix-site', 'pix-pro'],
PIX_DATAWAREHOUSE_REPO_NAME: 'pix-db-replication',
PIX_DATAWAREHOUSE_APPS_NAME: ['pix-datawarehouse', 'pix-datawarehouse-ex'],

PIX_METABASE_REPO_NAME: 'metabase-deploy',
PIX_METABASE_APPS_NAME: ['pix-metabase-production', 'pix-data-metabase-dev'],

PIX_APPS: ['app', 'certif', 'admin', 'orga', 'api'],
PIX_APPS_ENVIRONMENTS: ['integration', 'recette', 'production'],
};
Expand Down
9 changes: 9 additions & 0 deletions run/controllers/slack.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ module.exports = {
};
},

deployMetabase(request) {
const payload = request.pre.payload;
commands.deployMetabase();

return {
text: 'Commande de déploiement de Metabase en production bien reçue.';
};
},

interactiveEndpoint(request) {
const payload = request.pre.payload;

Expand Down
10 changes: 9 additions & 1 deletion run/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ manifest.registerSlashCommand({
handler: slackbotController.createAndDeployEmberTestingLibraryRelease,
});


manifest.registerSlashCommand({
command: '/deploy-db-stats',
path: '/slack/commands/create-and-deploy-db-stats',
Expand All @@ -85,6 +84,15 @@ manifest.registerSlashCommand({
handler: slackbotController.createAndDeployDbStats,
});

manifest.registerSlashCommand({
command: '/deploy-metabase',
path: '/slack/commands/deploy-metabase',
description: 'Déploie metabase',
usage_hint: '/deploy-metabase',
should_escape: false,
handler: slackbotController.deployMetabase,
});

manifest.registerShortcut({
name: 'Déployer une version/MEP',
type: 'global',
Expand Down
10 changes: 10 additions & 0 deletions run/services/slack/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const {
PIX_EMBER_TESTING_LIBRARY_REPO_NAME,
PIX_DB_STATS_REPO_NAME,
PIX_DB_STATS_APPS_NAME,
PIX_METABASE_REPO_NAME,
PIX_METABASE_APPS_NAME,
} = require('../../../config');
const releasesService = require('../../../common/services/releases');
const ScalingoClient = require('../../../common/services/scalingo-client');
Expand Down Expand Up @@ -176,5 +178,13 @@ module.exports = {

async createAndDeployDbStats(payload) {
await publishAndDeployRelease(PIX_DB_STATS_REPO_NAME, PIX_DB_STATS_APPS_NAME, payload.text, payload.response_url);
},

async deployMetabase() {
const repoName = PIX_METABASE_REPO_NAME;
const client = await ScalingoClient.getInstance('production');
await PIX_METABASE_APPS_NAME.map((appName) => {
return client.deployFromArchive(appName, 'master', repoName, { withEnvSuffix: false });
});
}
};
7 changes: 7 additions & 0 deletions test/acceptance/run/manifest_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ describe('Acceptance | Run | Manifest', function() {
should_escape: false,
url: `http://${hostname}/slack/commands/create-and-deploy-db-stats`,
usage_hint: '[patch, minor, major]'
},
{
command: '/deploy-metabase',
description: 'Déploie metabase',
should_escape: false,
url: `http://${hostname}/slack/commands/deploy-metabase`,
usage_hint: ''
}
]
},
Expand Down
20 changes: 20 additions & 0 deletions test/unit/run/services/slack/commands_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const {
createAndDeployPixBotRelease,
getAndDeployLastVersion,
createAndDeployDbStats,
deployMetabase,
} = require('../../../../../run/services/slack/commands');
const releasesServices = require('../../../../../common/services/releases');
const githubServices = require('../../../../../common/services/github');
Expand Down Expand Up @@ -273,6 +274,7 @@ describe('Services | Slack | Commands', () => {
// when
await createAndDeployDbStats(payload);
});

it('should publish a new release', () => {
// then
sinon.assert.calledWith(releasesServices.publishPixRepo, 'pix-db-stats', 'minor');
Expand All @@ -288,4 +290,22 @@ describe('Services | Slack | Commands', () => {
sinon.assert.calledWith(releasesServices.deployPixRepo);
});
});

describe('#deployMetabase', () => {
let client;

beforeEach(async () => {
// given
client = { deployFromArchive: sinon.spy() };
sinon.stub(ScalingoClient, 'getInstance').resolves(client);
// when
await deployMetabase();
});

it('should deploy the release', () => {
// then
sinon.assert.calledWith(client.deployFromArchive, 'pix-metabase-production', 'master', 'metabase-deploy', { withEnvSuffix: false });
sinon.assert.calledWith(client.deployFromArchive, 'pix-data-metabase-dev', 'master', 'metabase-deploy', { withEnvSuffix: false });
});
});
});

0 comments on commit c76b431

Please sign in to comment.