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

start making docker-compose test templates dynamic #18935

Merged
merged 9 commits into from
Jun 17, 2022
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
9 changes: 6 additions & 3 deletions generators/docker-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const shelljs = require('shelljs');
const chalk = require('chalk');
const _ = require('lodash');

const { defaultConfig } = require('./generator-defaults');
const dockerUtils = require('./docker-utils');
const { getBase64Secret } = require('./utils');
const { MAVEN } = require('../jdl/jhipster/build-tool-types');
Expand Down Expand Up @@ -103,17 +102,21 @@ function loadConfigs() {
this.gatewayNb = 0;
this.monolithicNb = 0;
this.microserviceNb = 0;
const serverPort = 8080;

// Loading configs
this.debug(`Apps folders: ${this.appsFolders}`);
this.appsFolders.forEach(appFolder => {
this.appsFolders.forEach((appFolder, index) => {
const path = this.destinationPath(`${this.directoryPath + appFolder}`);
if (this.fs.exists(`${path}/.yo-rc.json`)) {
const config = this.getJhipsterConfig(`${path}/.yo-rc.json`).getAll();
_.defaults(config, defaultConfig);
config.composePort = serverPort + index;
_.defaults(config, this.getDefaultConfigForApplicationType(config.applicationType));
this.loadAppConfig(config, config);
this.loadServerConfig(config, config);
this.loadDerivedPlatformConfig(config);
this.loadDerivedAppConfig(config);
this.loadDerivedServerConfig(config);

if (config.applicationType === MONOLITH) {
this.monolithicNb++;
Expand Down
2 changes: 1 addition & 1 deletion generators/docker-compose/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function writeFiles() {
// Generate a list of target apps to monitor for the prometheus config
const appsToMonitor = [];
for (let i = 0; i < this.appConfigs.length; i++) {
appsToMonitor.push(` - ${this.appConfigs[i].baseName}:${this.appConfigs[i].serverPort}`);
appsToMonitor.push(` - ${this.appConfigs[i].baseName}:${this.appConfigs[i].composePort}`);
}

// Format the application target list as a YAML array
Expand Down
19 changes: 6 additions & 13 deletions generators/docker-compose/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,12 @@ const writeFiles = require('./files').writeFiles;
const { GATEWAY, MONOLITH } = require('../../jdl/jhipster/application-types');
const { PROMETHEUS } = require('../../jdl/jhipster/monitoring-types');
const { EUREKA } = require('../../jdl/jhipster/service-discovery-types');
const { CASSANDRA, COUCHBASE, MONGODB, ORACLE } = require('../../jdl/jhipster/database-types');
const { CASSANDRA, COUCHBASE, MONGODB, ORACLE, NO: NO_DATABASE } = require('../../jdl/jhipster/database-types');
const { ELASTICSEARCH } = require('../../jdl/jhipster/search-engine-types');
const { KAFKA } = require('../../jdl/jhipster/message-broker-types');
const { MEMCACHED, REDIS } = require('../../jdl/jhipster/cache-types');
const databaseTypes = require('../../jdl/jhipster/database-types');
const { GENERATOR_DOCKER_COMPOSE } = require('../generator-list');

const NO_DATABASE = databaseTypes.NO;

/* eslint-disable consistent-return */
module.exports = class extends BaseDockerGenerator {
async _postConstruct() {
Expand Down Expand Up @@ -131,13 +128,12 @@ module.exports = class extends BaseDockerGenerator {
loadConfig() {
this.usesOauth2 = this.appConfigs.some(appConfig => appConfig.authenticationTypeOauth2);
this.useKafka = this.appConfigs.some(appConfig => appConfig.messageBroker === KAFKA);
this.entryPort = 8080;
},

setAppsYaml() {
this.appsYaml = [];
this.keycloakRedirectUris = '';
let portIndex = 8080;
this.serverPort = portIndex;
this.appConfigs.forEach(appConfig => {
const lowercaseBaseName = appConfig.baseName.toLowerCase();
const parentConfiguration = {};
Expand All @@ -146,15 +142,14 @@ module.exports = class extends BaseDockerGenerator {
const yaml = jsyaml.load(this.fs.read(`${path}/src/main/docker/app.yml`));
const yamlConfig = yaml.services[`${lowercaseBaseName}-app`];
if (appConfig.applicationType === GATEWAY || appConfig.applicationType === MONOLITH) {
this.keycloakRedirectUris += `"http://localhost:${portIndex}/*", "https://localhost:${portIndex}/*", `;
this.keycloakRedirectUris += `"http://localhost:${appConfig.composePort}/*", "https://localhost:${appConfig.composePort}/*", `;
if (appConfig.devServerPort !== undefined) {
this.keycloakRedirectUris += `"http://localhost:${appConfig.devServerPort}/*", `;
}
// Split ports by ":" and take last 2 elements to skip the hostname/IP if present
const ports = yamlConfig.ports[0].split(':').slice(-2);
ports[0] = portIndex;
ports[0] = appConfig.composePort;
yamlConfig.ports[0] = ports.join(':');
portIndex++;
}

if (appConfig.applicationType === MONOLITH && this.monitoring === PROMETHEUS) {
Expand All @@ -174,7 +169,7 @@ module.exports = class extends BaseDockerGenerator {
parentConfiguration[`${lowercaseBaseName}`] = yamlConfig;

// Add database configuration
const database = appConfig.prodDatabaseType;
const database = appConfig.databaseTypeSql ? appConfig.prodDatabaseType : appConfig.databaseType;
if (database !== NO_DATABASE && database !== ORACLE) {
const relativePath = normalize(pathjs.relative(this.destinationRoot(), `${path}/src/main/docker`));
const databaseYaml = jsyaml.load(this.fs.read(`${path}/src/main/docker/${database}.yml`));
Expand Down Expand Up @@ -304,11 +299,9 @@ module.exports = class extends BaseDockerGenerator {
this.log(`You can launch all your infrastructure by running : ${chalk.cyan('docker-compose up -d')}`);
if (this.gatewayNb + this.monolithicNb > 1) {
this.log('\nYour applications will be accessible on these URLs:');
let portIndex = 8080;
this.appConfigs.forEach(appConfig => {
if (appConfig.applicationType === GATEWAY || appConfig.applicationType === MONOLITH) {
this.log(`\t- ${appConfig.baseName}: http://localhost:${portIndex}`);
portIndex++;
this.log(`\t- ${appConfig.baseName}: http://localhost:${appConfig.composePort}`);
}
});
this.log('\n');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Launch all your infrastructure by running: `docker-compose up -d`.
### Applications and dependencies:
<%_ for(let i = 0; i < appConfigs.length; i++) { _%>
- <%= appConfigs[i].baseName %> (<%= appConfigs[i].applicationType %> application)
- <%= appConfigs[i].baseName %>'s <%= appConfigs[i].prodDatabaseType %> database
- <%= appConfigs[i].baseName %>'s <%= appConfigs[i].databaseTypeSql ? appConfigs[i].prodDatabaseType : appConfigs[i].databaseType %> database
<%_ if (appConfigs[i].searchEngine && !appConfigs[i].searchEngineCouchbase) { _%>
- <%= appConfigs[i].baseName %>'s <%= appConfigs[i].searchEngine %> search engine
<%_ } _%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1024,8 +1024,8 @@
{
"id": "6e8deddb-b4d6-4e2e-b389-b397d3f74fcd",
"clientId": "web_app",
"rootUrl": "http://localhost:<%= serverPort %>",
"adminUrl": "http://localhost:<%= serverPort %>",
"rootUrl": "http://localhost:<%= entryPort %>",
"adminUrl": "http://localhost:<%= entryPort %>",
"surrogateAuthRequired": false,
"enabled": true,
"alwaysDisplayInConsole": false,
Expand Down
3 changes: 1 addition & 2 deletions generators/docker-prompts.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const shelljs = require('shelljs');
const { loadConfigs, setClusteredApps } = require('./docker-base');
const { getBase64Secret } = require('./utils');
const { MICROSERVICE, MONOLITH, GATEWAY } = require('../jdl/jhipster/application-types');
const { COUCHBASE, MONGODB } = require('../jdl/jhipster/database-types');
const { PROMETHEUS } = require('../jdl/jhipster/monitoring-types');
const monitoring = require('../jdl/jhipster/monitoring-types');

Expand Down Expand Up @@ -183,7 +182,7 @@ async function askForClustersMode() {

const clusteredDbApps = [];
this.appConfigs.forEach((appConfig, index) => {
if (appConfig.prodDatabaseType === MONGODB || appConfig.prodDatabaseType === COUCHBASE) {
if (appConfig.databaseTypeMongodb || appConfig.databaseTypeCouchbase) {
clusteredDbApps.push(this.appsFolders[index]);
}
});
Expand Down
25 changes: 1 addition & 24 deletions test/__snapshots__/docker-compose.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ Launch all your infrastructure by running: \`docker-compose up -d\`.

- jhgate (gateway application)
- jhgate's mysql database
- jhgate's no search engine
- mscouchbase (microservice application)
- mscouchbase's couchbase database

Expand Down Expand Up @@ -129,7 +128,7 @@ eureka:
}
`;

exports[`JHipster Docker Compose Sub Generator gateway and 1 microservice, with Cassandra cluster should match files snapshot 1`] = `
exports[`JHipster Docker Compose Sub Generator gateway and 1 microservice, with Cassandra should match files snapshot 1`] = `
Object {
".yo-rc.json": Object {
"contents": "{
Expand Down Expand Up @@ -163,10 +162,8 @@ Launch all your infrastructure by running: \`docker-compose up -d\`.

- jhgate (gateway application)
- jhgate's mysql database
- jhgate's no search engine
- mscassandra (microservice application)
- mscassandra's cassandra database
- mscassandra's no search engine

### Additional Services:
",
Expand Down Expand Up @@ -295,18 +292,15 @@ Launch all your infrastructure by running: \`docker-compose up -d\`.

- jhgate (gateway application)
- jhgate's mysql database
- jhgate's no search engine
- msmysql (microservice application)
- msmysql's mysql database
- msmysql's no search engine
- mspsql (microservice application)
- mspsql's postgresql database
- mspsql's elasticsearch search engine
- msmongodb (microservice application)
- msmongodb's mongodb database
- msmariadb (microservice application)
- msmariadb's mariadb database
- msmariadb's no search engine

### Additional Services:
",
Expand Down Expand Up @@ -463,10 +457,8 @@ Launch all your infrastructure by running: \`docker-compose up -d\`.

- jhgate (gateway application)
- jhgate's mysql database
- jhgate's no search engine
- msmysql (microservice application)
- msmysql's mysql database
- msmysql's no search engine
- mspsql (microservice application)
- mspsql's postgresql database
- mspsql's elasticsearch search engine
Expand Down Expand Up @@ -629,18 +621,15 @@ Launch all your infrastructure by running: \`docker-compose up -d\`.

- jhgate (gateway application)
- jhgate's mysql database
- jhgate's no search engine
- msmysql (microservice application)
- msmysql's mysql database
- msmysql's no search engine
- mspsql (microservice application)
- mspsql's postgresql database
- mspsql's elasticsearch search engine
- mscouchbase (microservice application)
- mscouchbase's couchbase database
- msmariadb (microservice application)
- msmariadb's mariadb database
- msmariadb's no search engine

### Additional Services:
",
Expand Down Expand Up @@ -801,10 +790,8 @@ Launch all your infrastructure by running: \`docker-compose up -d\`.

- jhgate (gateway application)
- jhgate's mysql database
- jhgate's no search engine
- msmysql (microservice application)
- msmysql's mysql database
- msmysql's no search engine

### Additional Services:
",
Expand Down Expand Up @@ -920,10 +907,8 @@ Launch all your infrastructure by running: \`docker-compose up -d\`.

- jhgate (gateway application)
- jhgate's mysql database
- jhgate's no search engine
- msmysql (microservice application)
- msmysql's mysql database
- msmysql's no search engine

### Additional Services:
",
Expand Down Expand Up @@ -1039,10 +1024,8 @@ Launch all your infrastructure by running: \`docker-compose up -d\`.

- jhgate (gateway application)
- jhgate's mysql database
- jhgate's no search engine
- msmysql (microservice application)
- msmysql's mysql database
- msmysql's no search engine

### Additional Services:

Expand Down Expand Up @@ -1274,10 +1257,8 @@ Launch all your infrastructure by running: \`docker-compose up -d\`.

- jhgate (gateway application)
- jhgate's mysql database
- jhgate's no search engine
- msmysql (microservice application)
- msmysql's mysql database
- msmysql's no search engine

### Additional Services:
",
Expand Down Expand Up @@ -1453,7 +1434,6 @@ Launch all your infrastructure by running: \`docker-compose up -d\`.

- msmysql (microservice application)
- msmysql's mysql database
- msmysql's no search engine

### Additional Services:
",
Expand Down Expand Up @@ -1553,7 +1533,6 @@ Launch all your infrastructure by running: \`docker-compose up -d\`.

- jhgate (gateway application)
- jhgate's mysql database
- jhgate's no search engine

### Additional Services:
",
Expand Down Expand Up @@ -1655,7 +1634,6 @@ Launch all your infrastructure by running: \`docker-compose up -d\`.

- msmysql (microservice application)
- msmysql's mysql database
- msmysql's no search engine

### Additional Services:
",
Expand Down Expand Up @@ -1751,7 +1729,6 @@ Launch all your infrastructure by running: \`docker-compose up -d\`.

- oracle-mono (monolith application)
- oracle-mono's oracle database
- oracle-mono's no search engine

### Additional Services:
",
Expand Down
3 changes: 2 additions & 1 deletion test/app/database-changelog.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const path = require('path');
const fse = require('fs-extra');
const helpers = require('yeoman-test');
const { createMockedConfig } = require('../support/mock-config.cjs');

const { SERVER_MAIN_RES_DIR } = require('../../generators/generator-constants');

Expand All @@ -12,7 +13,7 @@ describe('jhipster:app database changelogs', () => {
helpers
.create(require.resolve('../../generators/app'))
.doInDir(dir => {
fse.copySync(path.join(__dirname, '../templates/compose/05-cassandra'), dir);
createMockedConfig('05-cassandra', dir, { appDir: '' });
fse.copySync(path.join(__dirname, '../templates/.jhipster/Simple.json'), path.join(dir, '.jhipster/Foo.json'));
})
.withOptions({ withEntities: true, force: true, skipClient: true })
Expand Down
Loading