Skip to content

Use of tasks groups for workspace generators #29900

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
12 changes: 12 additions & 0 deletions generators/base-workspaces/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ export default abstract class BaseWorkspacesGenerator<
return this.getContextData(CONTEXT_DATA_WORKSPACES_KEY, { factory: () => ({}) });
}

get promptingWorkspaces() {
return {};
}

get configuringWorkspaces() {
return {};
}

get preparingWorkspaces() {
return {};
}

protected loadWorkspacesConfig(opts?) {
const { context = this } = opts ?? {};
context.appsFolders = this.jhipsterConfig.appsFolders;
Expand Down
7 changes: 3 additions & 4 deletions generators/base/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ import path, { join, relative } from 'path';
import { rm } from 'fs/promises';
import chalk from 'chalk';
import semver, { lt as semverLessThan } from 'semver';

import { union } from 'lodash-es';
import { execaCommandSync } from 'execa';
import { union } from 'lodash-es';
import type { PackageJson } from 'type-fest';
import { packageJson } from '../../lib/index.js';
import CoreGenerator from '../base-core/index.js';
Expand Down Expand Up @@ -184,8 +183,8 @@ export default class BaseGenerator<
},
get enviromentHasDockerCompose(): boolean {
if (enviromentHasDockerCompose === undefined) {
const { exitCode } = execaCommandSync('docker compose version', { reject: false, stdio: 'pipe' });
enviromentHasDockerCompose = exitCode === 0;
const commandReturn = execaCommandSync('docker compose version', { reject: false, stdio: 'pipe' });
enviromentHasDockerCompose = !commandReturn || !commandReturn.failed; // TODO looks to be a bug on ARM MaCs and execaCommandSync, does not return anything, assuming mac users are smart and install docker.
}
return enviromentHasDockerCompose;
},
Expand Down
14 changes: 13 additions & 1 deletion generators/bootstrap-workspaces/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,16 @@ export default class BootstrapWorkspacesGenerator extends BaseWorkspacesGenerato
return this.delegateTasksToBlueprint(() => this.postPreparing);
}

get [BaseWorkspacesGenerator.PROMPTING_WORKSPACES]() {
return this.delegateTasksToBlueprint(() => this.promptingWorkspaces);
}

get [BaseWorkspacesGenerator.CONFIGURING_WORKSPACES]() {
return this.delegateTasksToBlueprint(() => this.configuringWorkspaces);
}

get loadingWorkspaces() {
return this.asAnyTaskGroup({
return this.asLoadingWorkspacesTaskGroup({
loadWorkspacesConfig({ workspaces }) {
this.loadWorkspacesConfig({ context: workspaces });
},
Expand All @@ -87,4 +95,8 @@ export default class BootstrapWorkspacesGenerator extends BaseWorkspacesGenerato
get [BaseWorkspacesGenerator.LOADING_WORKSPACES]() {
return this.delegateTasksToBlueprint(() => this.loadingWorkspaces);
}

get [BaseWorkspacesGenerator.PREPARING_WORKSPACES]() {
return this.delegateTasksToBlueprint(() => this.preparingWorkspaces);
}
}
2 changes: 0 additions & 2 deletions generators/docker-compose/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ const { EUREKA, NO: NO_SERVICE_DISCOVERY } = serviceDiscoveryTypes;
const { Options: DeploymentOptions } = deploymentOptions;

export default class DockerComposeGenerator extends BaseWorkspacesGenerator<BaseDeployment, BaseWorkspaces, BaseWorkspacesApplication> {
existingDeployment;

async beforeQueue() {
if (this.appsFolders && this.appsFolders.length > 0) {
this.jhipsterConfig.appsFolders = this.appsFolders;
Expand Down
152 changes: 70 additions & 82 deletions generators/kubernetes-helm/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
searchEngineTypes,
serviceDiscoveryTypes,
} from '../../lib/jhipster/index.js';
import { asWritingTask } from '../base-application/support/index.js';

const { ELASTICSEARCH } = searchEngineTypes;
const { GATEWAY, MONOLITH } = applicationTypes;
Expand All @@ -35,90 +36,77 @@ const { ServiceTypes } = kubernetesPlatformTypes;

const { INGRESS } = ServiceTypes;

export default {
writeFiles,
};

export function writeFiles() {
export const writeFiles = asWritingTask(async function writeFiles() {
const suffix = 'helm';
return {
writeAppChart() {
const kubernetesSubgenPath = this.fetchFromInstalledJHipster('kubernetes/templates');
if (this.kubernetesNamespace !== 'default') {
this.writeFile(`${kubernetesSubgenPath}/namespace.yml.ejs`, 'namespace.yml');
}
for (let i = 0; i < this.appConfigs.length; i++) {
const appName = this.appConfigs[i].baseName.toLowerCase();
const appOut = appName.concat('-', suffix);
this.app = this.appConfigs[i];
// app charts
const kubernetesSubgenPath = this.fetchFromInstalledJHipster('kubernetes/templates');
if (this.kubernetesNamespace !== 'default') {
await this.writeFile(`${kubernetesSubgenPath}/namespace.yml.ejs`, 'namespace.yml');
}
for (let i = 0; i < this.appConfigs.length; i++) {
const appName = this.appConfigs[i].baseName.toLowerCase();
const appOut = appName.concat('-', suffix);
this.app = this.appConfigs[i];

this.writeFile(`${kubernetesSubgenPath}/deployment.yml.ejs`, `${appOut}/templates/${appName}-deployment.yml`);
this.writeFile(`${kubernetesSubgenPath}/service.yml.ejs`, `${appOut}/templates/${appName}-service.yml`);
this.writeFile('app/values.yml.ejs', `${appOut}/values.yaml`);
this.writeFile('app/Chart.yml.ejs', `${appOut}/Chart.yaml`);
this.writeFile('app/requirements.yml.ejs', `${appOut}/requirements.yaml`);
this.writeFile('app/helpers.tpl.ejs', `${appOut}/templates/_helpers.tpl`);
await this.writeFile(`${kubernetesSubgenPath}/deployment.yml.ejs`, `${appOut}/templates/${appName}-deployment.yml`);
await this.writeFile(`${kubernetesSubgenPath}/service.yml.ejs`, `${appOut}/templates/${appName}-service.yml`);
await this.writeFile('app/values.yml.ejs', `${appOut}/values.yaml`);
await this.writeFile('app/Chart.yml.ejs', `${appOut}/Chart.yaml`);
await this.writeFile('app/requirements.yml.ejs', `${appOut}/requirements.yaml`);
await this.writeFile('app/helpers.tpl.ejs', `${appOut}/templates/_helpers.tpl`);

if (this.app.searchEngine === ELASTICSEARCH) {
this.writeFile(`${kubernetesSubgenPath}/db/elasticsearch.yml.ejs`, `${appOut}/templates/${appName}-elasticsearch.yml`);
}
if (this.app.applicationType === GATEWAY || this.app.applicationType === MONOLITH) {
if (this.istio) {
this.writeFile(`${kubernetesSubgenPath}/istio/gateway.yml.ejs`, `${appOut}/templates/${appName}-gateway.yml`);
} else if (this.kubernetesServiceType === INGRESS) {
this.writeFile(`${kubernetesSubgenPath}/ingress.yml.ejs`, `${appOut}/templates/${appName}-ingress.yml`);
}
}
if (!this.app.serviceDiscoveryAny && this.app.authenticationType === JWT) {
this.writeFile(`${kubernetesSubgenPath}/secret/jwt-secret.yml.ejs`, `${appOut}/templates/jwt-secret.yml`);
}
if (this.app.databaseTypeCouchbase) {
this.writeFile(`${kubernetesSubgenPath}/secret/couchbase-secret.yml.ejs`, `${appOut}/templates/couchbase-secret.yml`);
}
if (this.istio) {
this.writeFile(`${kubernetesSubgenPath}/istio/destination-rule.yml.ejs`, `${appOut}/templates/${appName}-destination-rule.yml`);
this.writeFile(`${kubernetesSubgenPath}/istio/virtual-service.yml.ejs`, `${appOut}/templates/${appName}-virtual-service.yml`);
}
}
},

writeCommonServiceChart() {
const k8s = this.fetchFromInstalledJHipster('kubernetes/templates');
const csOut = 'csvc'.concat('-', suffix);
if (this.useKafka || this.monitoring === PROMETHEUS || this.serviceDiscoveryType === EUREKA || this.serviceDiscoveryType === CONSUL) {
this.writeFile('csvc/values.yml.ejs', `${csOut}/values.yaml`);
this.writeFile('csvc/Chart.yml.ejs', `${csOut}/Chart.yaml`);
this.writeFile('csvc/requirements.yml.ejs', `${csOut}/requirements.yaml`);
this.writeFile('csvc/helpers.tpl.ejs', `${csOut}/templates/_helpers.tpl`);
}
if (this.monitoring === PROMETHEUS) {
if (this.istio && this.kubernetesServiceType === INGRESS) {
this.writeFile(`${k8s}/istio/gateway/jhipster-grafana-gateway.yml.ejs`, `${csOut}/templates/jhipster-grafana-gateway.yml`);
}
}
if (this.serviceDiscoveryType === EUREKA) {
this.writeFile(`${k8s}/registry/jhipster-registry.yml.ejs`, `${csOut}/templates/jhipster-registry.yml`);
this.writeFile(`${k8s}/registry/application-configmap.yml.ejs`, `${csOut}/templates/application-configmap.yml`);
}
if (this.serviceDiscoveryType === CONSUL) {
this.writeFile(`${k8s}/registry/consul.yml.ejs`, `${csOut}/templates/consul.yml`);
this.writeFile(`${k8s}/registry/consul-config-loader.yml.ejs`, `${csOut}/templates/consul-config-loader.yml`);
this.writeFile(`${k8s}/registry/application-configmap.yml.ejs`, `${csOut}/templates/application-configmap.yml`);
}
if (this.app.searchEngine === ELASTICSEARCH) {
await this.writeFile(`${kubernetesSubgenPath}/db/elasticsearch.yml.ejs`, `${appOut}/templates/${appName}-elasticsearch.yml`);
}
if (this.app.applicationType === GATEWAY || this.app.applicationType === MONOLITH) {
if (this.istio) {
this.writeFile(`${k8s}/istio/gateway/grafana-gateway.yml.ejs`, `${csOut}/templates/grafana-gateway.yml`);
this.writeFile(`${k8s}/istio/gateway/zipkin-gateway.yml.ejs`, `${csOut}/templates/zipkin-gateway.yml`);
this.writeFile(`${k8s}/istio/gateway/kiali-gateway.yml.ejs`, `${csOut}/templates/kiali-gateway.yml`);
await this.writeFile(`${kubernetesSubgenPath}/istio/gateway.yml.ejs`, `${appOut}/templates/${appName}-gateway.yml`);
} else if (this.kubernetesServiceType === INGRESS) {
await this.writeFile(`${kubernetesSubgenPath}/ingress.yml.ejs`, `${appOut}/templates/${appName}-ingress.yml`);
}
},

writeReadme() {
this.writeFile('README-KUBERNETES-HELM.md.ejs', 'HELM-README.md');
},

writeConfigRunFile() {
this.writeFile('helm-apply.sh.ejs', 'helm-apply.sh');
this.writeFile('helm-upgrade.sh.ejs', 'helm-upgrade.sh');
},
};
}
}
if (!this.app.serviceDiscoveryAny && this.app.authenticationType === JWT) {
await this.writeFile(`${kubernetesSubgenPath}/secret/jwt-secret.yml.ejs`, `${appOut}/templates/jwt-secret.yml`);
}
if (this.app.databaseTypeCouchbase) {
await this.writeFile(`${kubernetesSubgenPath}/secret/couchbase-secret.yml.ejs`, `${appOut}/templates/couchbase-secret.yml`);
}
if (this.istio) {
await this.writeFile(`${kubernetesSubgenPath}/istio/destination-rule.yml.ejs`, `${appOut}/templates/${appName}-destination-rule.yml`);
await this.writeFile(`${kubernetesSubgenPath}/istio/virtual-service.yml.ejs`, `${appOut}/templates/${appName}-virtual-service.yml`);
}
}
// common services
const k8s = this.fetchFromInstalledJHipster('kubernetes/templates');
const csOut = 'csvc'.concat('-', suffix);
if (this.useKafka || this.monitoring === PROMETHEUS || this.serviceDiscoveryType === EUREKA || this.serviceDiscoveryType === CONSUL) {
await this.writeFile('csvc/values.yml.ejs', `${csOut}/values.yaml`);
await this.writeFile('csvc/Chart.yml.ejs', `${csOut}/Chart.yaml`);
await this.writeFile('csvc/requirements.yml.ejs', `${csOut}/requirements.yaml`);
await this.writeFile('csvc/helpers.tpl.ejs', `${csOut}/templates/_helpers.tpl`);
}
if (this.monitoring === PROMETHEUS) {
if (this.istio && this.kubernetesServiceType === INGRESS) {
await this.writeFile(`${k8s}/istio/gateway/jhipster-grafana-gateway.yml.ejs`, `${csOut}/templates/jhipster-grafana-gateway.yml`);
}
}
if (this.serviceDiscoveryType === EUREKA) {
await this.writeFile(`${k8s}/registry/jhipster-registry.yml.ejs`, `${csOut}/templates/jhipster-registry.yml`);
await this.writeFile(`${k8s}/registry/application-configmap.yml.ejs`, `${csOut}/templates/application-configmap.yml`);
}
if (this.serviceDiscoveryType === CONSUL) {
await this.writeFile(`${k8s}/registry/consul.yml.ejs`, `${csOut}/templates/consul.yml`);
await this.writeFile(`${k8s}/registry/consul-config-loader.yml.ejs`, `${csOut}/templates/consul-config-loader.yml`);
await this.writeFile(`${k8s}/registry/application-configmap.yml.ejs`, `${csOut}/templates/application-configmap.yml`);
}
if (this.istio) {
await this.writeFile(`${k8s}/istio/gateway/grafana-gateway.yml.ejs`, `${csOut}/templates/grafana-gateway.yml`);
await this.writeFile(`${k8s}/istio/gateway/zipkin-gateway.yml.ejs`, `${csOut}/templates/zipkin-gateway.yml`);
await this.writeFile(`${k8s}/istio/gateway/kiali-gateway.yml.ejs`, `${csOut}/templates/kiali-gateway.yml`);
}
// Readme
await this.writeFile('README-KUBERNETES-HELM.md.ejs', 'HELM-README.md');
// run files
await this.writeFile('helm-apply.sh.ejs', 'helm-apply.sh');
await this.writeFile('helm-upgrade.sh.ejs', 'helm-upgrade.sh');
});
47 changes: 22 additions & 25 deletions generators/kubernetes-helm/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,30 +75,27 @@ export default class KubernetesHelmGenerator extends BaseWorkspacesGenerator {
}

get initializing() {
return {
return this.asInitializingTaskGroup({
sayHello() {
this.log.log(chalk.white(`${chalk.bold('⎈')} Welcome to the JHipster Kubernetes Helm Generator ${chalk.bold('⎈')}`));
this.log.log(chalk.white(`Files will be generated in folder: ${chalk.yellow(this.destinationRoot())}`));
},
existingDeployment() {
this.regenerate = this.regenerate || this.config.existed;
},
loadDockerDependenciesTask,
checkDocker,
checkKubernetes,
checkHelm,
loadConfig,
setupKubernetesConstants,
setupHelmConstants,
};
});
}

get [BaseWorkspacesGenerator.INITIALIZING]() {
return this.delegateTasksToBlueprint(() => this.initializing);
}

get prompting() {
return {
return this.asPromptingTaskGroup({
askForApplicationType,
askForPath,
askForApps,
Expand All @@ -113,43 +110,43 @@ export default class KubernetesHelmGenerator extends BaseWorkspacesGenerator {
askForKubernetesServiceType,
askForIngressType,
askForIngressDomain,
};
});
}

get [BaseWorkspacesGenerator.PROMPTING]() {
return this.delegateTasksToBlueprint(() => this.prompting);
}

get configuring() {
return {
get configuringWorkspaces() {
return this.asConfiguringWorkspacesTaskGroup({
generateJwtSecret,
};
});
}

get [BaseWorkspacesGenerator.CONFIGURING]() {
return this.delegateTasksToBlueprint(() => this.configuring);
get [BaseWorkspacesGenerator.CONFIGURING_WORKSPACES]() {
return this.delegateTasksToBlueprint(() => this.configuringWorkspaces);
}

get loading() {
return {
get loadingWorkspaces() {
return this.asLoadingWorkspacesTaskGroup({
loadFromYoRc,
loadSharedConfig() {
for (const app of this.appConfigs) {
loadDerivedAppConfig({ application: app });
loadDerivedServerAndPlatformProperties({ application: app });
}
loadDeploymentConfig.call(this);
derivedKubernetesPlatformProperties(this);
},
};
loadDeploymentConfig,
derivedKubernetesPlatformProperties,
});
}

get [BaseWorkspacesGenerator.LOADING]() {
return this.delegateTasksToBlueprint(() => this.loading);
get [BaseWorkspacesGenerator.LOADING_WORKSPACES]() {
return this.delegateTasksToBlueprint(() => this.loadingWorkspaces);
}

get preparing() {
return {
get preparingWorkspaces() {
return this.asPreparingWorkspacesTaskGroup({
configureImageNames,

setPostPromptProp() {
Expand All @@ -162,15 +159,15 @@ export default class KubernetesHelmGenerator extends BaseWorkspacesGenerator {
});
this.useKeycloak = false;
},
};
});
}

get [BaseWorkspacesGenerator.PREPARING]() {
return this.delegateTasksToBlueprint(() => this.preparing);
get [BaseWorkspacesGenerator.PREPARING_WORKSPACES]() {
return this.delegateTasksToBlueprint(() => this.preparingWorkspaces);
}

get writing() {
return writeFiles();
return this.asWritingTaskGroup({ writeFiles });
}

get [BaseWorkspacesGenerator.WRITING]() {
Expand Down
Loading
Loading