Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TECH] Rend les déploiements déclaratif plutot qu'impératif #278

Merged
merged 6 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions common/deployer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const ScalingoClient = require('./services/scalingo-client');

function fromBranch(repoName, appNames, branch) {
return async () => {
const client = await ScalingoClient.getInstance('production');
return Promise.all(
appNames.map((appName) => {
return client.deployFromArchive(appName, branch, repoName, { withEnvSuffix: false });
}),
);
};
}

module.exports = { fromBranch };
19 changes: 19 additions & 0 deletions common/register-slash-commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function registerSlashCommands(deployConfiguration, manifest) {
deployConfiguration.forEach((configuration) => {
manifest.registerSlashCommand({
...configuration.slashCommand,
path: `/slack/commands${configuration.slashCommand.command}`,
should_escape: false,
handler: () => {
configuration.deployFunction();
return {
text: configuration.slackReturnText,
};
},
});
});
}

module.exports = {
registerSlashCommands,
};
9 changes: 0 additions & 9 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,12 @@ module.exports = (function () {
PIX_DATAWAREHOUSE_REPO_NAME: 'pix-db-replication',
PIX_DATAWAREHOUSE_APPS_NAME: ['pix-datawarehouse', 'pix-datawarehouse-ex', 'pix-datawarehouse-data'],

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

PIX_APPS: ['app', 'certif', 'admin', 'orga', 'api', '1d'],
PIX_APPS_ENVIRONMENTS: ['integration', 'recette', 'production'],
PIX_TUTOS_REPO_NAME: 'pix-tutos',
PIX_TUTOS_APP_NAME: 'pix-tutos',
PIX_APIM_REPO_NAME: 'pix-nginx-apim',
PIX_APIM_APPS_NAME: 'pix-nginx-apim-production',
PIX_GEOAPI_REPO_NAME: 'geoapi',
PIX_GEOAPI_APP_NAME: 'pix-geoapi-production',
PIX_AIRFLOW_APP_NAME: 'pix-airflow-production',
PIX_DBT_APPS_NAME: ['pix-dbt-production', 'pix-dbt-external-production'],
PIX_360_REPO_NAME: 'pix-360',
PIX_360_APP_NAME: 'pix-360-production',
};

if (process.env.NODE_ENV === 'test') {
Expand Down
34 changes: 0 additions & 34 deletions run/controllers/slack.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,6 @@ function _getDeployStartedMessage(release, appName) {
}

module.exports = {
deployPixAPIM(request) {
const payload = request.pre.payload;
commands.deployPixAPIM(payload);

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

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

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

deployAirflow(request) {
const payload = request.pre.payload;
commands.deployAirflow(payload);
Expand Down Expand Up @@ -135,22 +117,6 @@ module.exports = {
};
},

deployMetabase() {
commands.deployMetabase();

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

deployPix360() {
commands.deployPix360();

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

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

Expand Down
44 changes: 44 additions & 0 deletions run/deploy-configuration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const { fromBranch } = require('../common/deployer');

module.exports = [
{
slashCommand: {
command: '/deploy-metabase',
description: 'Déploie metabase',
usage_hint: '/deploy-metabase',
},
slackReturnText: 'Commande de déploiement de Metabase en production bien reçue.',
deployFunction: fromBranch(
'metabase-deploy',
['pix-metabase-production', 'pix-data-metabase-production'],
'master',
),
},
{
slashCommand: {
command: '/deploy-pix-apim',
description: 'Pour déployer les applications Pix APIM depuis la branche main',
usage_hint: '/deploy-pix-apim',
},
slackReturnText: 'Commande de déploiement de Pix APIM en production bien reçue.',
deployFunction: fromBranch('pix-nginx-apim', ['pix-nginx-apim-production'], 'main'),
},
{
slashCommand: {
command: '/deploy-geoapi',
description: 'Déploie GeoAPI en production depuis la branche main',
usage_hint: '/deploy-geoapi',
},
slackReturnText: 'Commande de déploiement de GeoAPI en production bien reçue.',
deployFunction: fromBranch('geoapi', ['pix-geoapi-production'], 'main'),
},
{
slashCommand: {
command: '/deploy-pix-360',
description: 'Pour déployer pix 360 depuis la branche main',
usage_hint: '/deploy-pix-360',
},
slackReturnText: 'Commande de déploiement de Pix 360 en production bien reçue.',
deployFunction: fromBranch('pix-360', ['pix-360-production'], 'main'),
},
];
35 changes: 0 additions & 35 deletions run/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,6 @@ 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.registerSlashCommand({
command: '/deploy-pix-tutos',
path: '/slack/commands/create-and-deploy-pix-tutos-release',
Expand All @@ -94,14 +85,6 @@ manifest.registerSlashCommand({
handler: slackbotController.createAndDeployPixTutosRelease,
});

manifest.registerSlashCommand({
command: '/deploy-pix-apim',
path: '/slack/commands/deploy-pix-apim',
description: 'Pour déployer les applications Pix APIM depuis la branche main',
should_escape: false,
handler: slackbotController.deployPixAPIM,
});

manifest.registerSlashCommand({
command: '/deploy-airflow',
path: '/slack/commands/deploy-airflow',
Expand All @@ -111,24 +94,6 @@ manifest.registerSlashCommand({
handler: slackbotController.deployAirflow,
});

manifest.registerSlashCommand({
command: '/deploy-geoapi',
path: '/slack/commands/deploy-geoapi',
description: 'Déploie GeoAPI en production depuis la branche main',
usage_hint: '/deploy-geoapi',
should_escape: false,
handler: slackbotController.deployGeoAPI,
});

manifest.registerSlashCommand({
command: '/deploy-pix-360',
path: '/slack/commands/deploy-pix-360',
description: 'Pour déployer pix 360 depuis la branche main',
usage_hint: '/deploy-pix-360',
should_escape: false,
handler: slackbotController.deployPix360,
});

manifest.registerSlashCommand({
command: '/app-status',
path: '/slack/commands/app-status',
Expand Down
33 changes: 0 additions & 33 deletions run/services/slack/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,10 @@ 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,
PIX_TUTOS_REPO_NAME,
PIX_TUTOS_APP_NAME,
PIX_APIM_REPO_NAME,
PIX_APIM_APPS_NAME,
PIX_GEOAPI_REPO_NAME,
PIX_GEOAPI_APP_NAME,
PIX_AIRFLOW_APP_NAME,
PIX_DBT_APPS_NAME,
PIX_360_REPO_NAME,
PIX_360_APP_NAME,
} = require('../../../config');
const releasesService = require('../../../common/services/releases');
const ScalingoClient = require('../../../common/services/scalingo-client');
Expand Down Expand Up @@ -160,15 +152,6 @@ function _isAppFromPixRepo({ appName }) {
return appNamePrefix === 'pix' && PIX_APPS.includes(shortAppName) && PIX_APPS_ENVIRONMENTS.includes(environment);
}

async function _deployFromBranch(repoName, appNames, branch) {
const client = await ScalingoClient.getInstance('production');
return Promise.all(
appNames.map((appName) => {
return client.deployFromArchive(appName, branch, repoName, { withEnvSuffix: false });
}),
);
}

async function deployTagUsingSCM(appNames, tag) {
const client = await ScalingoClient.getInstance('production');
return Promise.all(
Expand All @@ -188,18 +171,6 @@ module.exports = {
await deployTagUsingSCM(PIX_DBT_APPS_NAME, version);
},

async deployPixAPIM() {
await _deployFromBranch(PIX_APIM_REPO_NAME, [PIX_APIM_APPS_NAME], 'main');
},

async deployGeoAPI() {
await _deployFromBranch(PIX_GEOAPI_REPO_NAME, [PIX_GEOAPI_APP_NAME], 'main');
},

async deployPix360() {
await _deployFromBranch(PIX_360_REPO_NAME, [PIX_360_APP_NAME], 'main');
},

async createAndDeployPixLCMS(payload) {
await _publishAndDeployReleaseWithAppsByEnvironment(
PIX_LCMS_REPO_NAME,
Expand Down Expand Up @@ -247,10 +218,6 @@ module.exports = {
await _publishAndDeployRelease(PIX_DB_STATS_REPO_NAME, PIX_DB_STATS_APPS_NAME, payload.text, payload.response_url);
},

async deployMetabase() {
await _deployFromBranch(PIX_METABASE_REPO_NAME, PIX_METABASE_APPS_NAME, 'master');
},

async createAndDeployPixTutosRelease(payload) {
await _publishAndDeployRelease(PIX_TUTOS_REPO_NAME, [PIX_TUTOS_APP_NAME], payload.text, payload.response_url);
},
Expand Down
4 changes: 4 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ require('dotenv').config();
const path = require('path');
const Hapi = require('@hapi/hapi');
const config = require('./config');
const runDeployConfiguration = require('./run/deploy-configuration');
const { registerSlashCommands } = require('./common/register-slash-commands');
const runManifest = require('./run/manifest');
const buildManifest = require('./build/manifest');
const { slackConfig } = require('./common/config');
Expand All @@ -29,6 +31,8 @@ setupErrorHandling(server);
.forEach((file) => server.route(require(path.join(routesDir, file))));
});

registerSlashCommands(runDeployConfiguration, runManifest);

manifests.forEach((manifest) => {
const routes = manifest.getHapiRoutes().map((route) => {
return {
Expand Down
56 changes: 28 additions & 28 deletions test/acceptance/run/manifest_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,48 +91,20 @@ describe('Acceptance | Run | Manifest', function () {
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: '/deploy-metabase',
},
{
command: '/deploy-pix-tutos',
description: 'Crée une release de Pix Tutos',
should_escape: false,
url: `http://${hostname}/slack/commands/create-and-deploy-pix-tutos-release`,
usage_hint: '[patch, minor, major]',
},
{
command: '/deploy-pix-apim',
description: 'Pour déployer les applications Pix APIM depuis la branche main',
should_escape: false,
url: `http://${hostname}/slack/commands/deploy-pix-apim`,
usage_hint: undefined,
},
{
command: '/deploy-airflow',
description: 'Déploie la version précisée de Airflow en production',
should_escape: false,
url: `http://${hostname}/slack/commands/deploy-airflow`,
usage_hint: '/deploy-airflow $version',
},
{
command: '/deploy-geoapi',
description: 'Déploie GeoAPI en production depuis la branche main',
should_escape: false,
url: `http://${hostname}/slack/commands/deploy-geoapi`,
usage_hint: '/deploy-geoapi',
},
{
command: '/deploy-pix-360',
description: 'Pour déployer pix 360 depuis la branche main',
should_escape: false,
url: `http://${hostname}/slack/commands/deploy-pix-360`,
usage_hint: '/deploy-pix-360',
},
{
command: '/app-status',
url: `http://${hostname}/slack/commands/app-status`,
Expand All @@ -147,6 +119,34 @@ describe('Acceptance | Run | Manifest', function () {
url: `http://${hostname}/slack/commands/deploy-dbt`,
usage_hint: '/deploy-dbt $version',
},
{
command: '/deploy-metabase',
description: 'Déploie metabase',
should_escape: false,
url: `http://${hostname}/slack/commands/deploy-metabase`,
usage_hint: '/deploy-metabase',
},
{
command: '/deploy-pix-apim',
description: 'Pour déployer les applications Pix APIM depuis la branche main',
should_escape: false,
url: `http://${hostname}/slack/commands/deploy-pix-apim`,
usage_hint: '/deploy-pix-apim',
},
{
command: '/deploy-geoapi',
description: 'Déploie GeoAPI en production depuis la branche main',
should_escape: false,
url: `http://${hostname}/slack/commands/deploy-geoapi`,
usage_hint: '/deploy-geoapi',
},
{
command: '/deploy-pix-360',
description: 'Pour déployer pix 360 depuis la branche main',
should_escape: false,
url: `http://${hostname}/slack/commands/deploy-pix-360`,
usage_hint: '/deploy-pix-360',
},
],
},
oauth_config: {
Expand Down
Loading
Loading