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

feature/docs v2 #297

Merged
merged 3 commits into from
Aug 28, 2024
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
1 change: 1 addition & 0 deletions src/commands/foundation/TestModuleType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export class TestModuleType extends StringType {
const excludes = {
testModules: false,
tenantModules: true,
platformModules: false,
};

const modules = await repo.processFilesGlob(
Expand Down
24 changes: 23 additions & 1 deletion src/commands/foundation/deploy.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { LiteralArgsParser } from "../LiteralArgsParser.ts";
import { TopLevelCommand } from "../TopLevelCommand.ts";
import { getCurrentWorkingFoundation } from "../../cli/commandOptionsConventions.ts";
import { NullProgressReporter } from "../../cli/NullProgressReporter.ts";
import { FoundationDeployer } from "../../foundation/FoundationDeployer.ts";

interface DeployOptions {
platform?: string;
Expand All @@ -29,7 +30,7 @@ export function registerDeployCmd(program: TopLevelCommand) {
const cmd = program
.command("deploy [foundation:foundation]")
.description(
"Deploy platform modules in your cloud foundations using terragrunt",
"Deploy foundation and platform modules in your cloud foundations using terragrunt",
)
.type("module", new PlatformModuleType())
.option(
Expand Down Expand Up @@ -121,6 +122,27 @@ export async function deployFoundation(

const terragrunt = factory.buildTerragrunt();

// unless targeting a specific platform, always deploy foundation modules
if (!opts.platform) {
const deployer = new FoundationDeployer(
repo,
foundation,
terragrunt,
logger,
);

await deployer.deployFoundationModules(
mode,
opts.module,
!!opts.autoApprove,
);

// if all we had to do was deploy a specific foundation module, we are done and can exit
if (opts.module) {
return;
}
}

const platforms = findPlatforms(opts.platform, foundation, logger);

for (const platform of platforms) {
Expand Down
97 changes: 17 additions & 80 deletions src/commands/foundation/docs.command.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
import * as fs from "std/fs";
import { CliApiFacadeFactory } from "../../api/CliApiFacadeFactory.ts";
import { Logger } from "../../cli/Logger.ts";
import { ProgressReporter } from "../../cli/ProgressReporter.ts";
import { ComplianceControlRepository } from "../../compliance/ComplianceControlRepository.ts";
import { ComplianceDocumentationGenerator } from "../../docs/ComplianceDocumentationGenerator.ts";
import { DocumentationGenerator } from "../../docs/DocumentationGenerator.ts";
import { DocumentationRepository } from "../../docs/DocumentationRepository.ts";
import { KitModuleDocumentationGenerator } from "../../docs/KitModuleDocumentationGenerator.ts";
import { PlatformDocumentationGenerator } from "../../docs/PlatformDocumentationGenerator.ts";
import { KitDependencyAnalyzer } from "../../kit/KitDependencyAnalyzer.ts";
import { KitModuleRepository } from "../../kit/KitModuleRepository.ts";
import { CollieRepository } from "../../model/CollieRepository.ts";
import { FoundationRepository } from "../../model/FoundationRepository.ts";
import { ModelValidator } from "../../model/schemas/ModelValidator.ts";
import { GlobalCommandOptions } from "../GlobalCommandOptions.ts";
import { TopLevelCommand } from "../TopLevelCommand.ts";
import { getCurrentWorkingFoundation } from "../../cli/commandOptionsConventions.ts";
import { exists } from "std/fs";

interface DocsCommandOptions {
update?: boolean;
Expand Down Expand Up @@ -89,59 +82,34 @@ export function registerDocsCmd(program: TopLevelCommand) {
}

async function updateDocumentation(
repo: CollieRepository,
_repo: CollieRepository,
foundation: FoundationRepository,
logger: Logger,
) {
const docsModulePath = foundation.resolvePath("docs");

if (!await exists(docsModulePath)) {
logger.error(
`Foundation-level docs module at "${docsModulePath}" does not exist.`,
);
logger.tip(
"Import a starter docs module using 'collie kit import docs' command.",
);
return;
}

const foundationProgress = new ProgressReporter(
"generating docs",
`foundation "${foundation.name}"`,
logger,
);

const validator = new ModelValidator(logger);
const modules = await KitModuleRepository.load(repo, validator, logger);
const controls = await ComplianceControlRepository.load(
repo,
validator,
logger,
);
const moduleDocumentation = new KitModuleDocumentationGenerator(
repo,
modules,
controls,
logger,
);

const complianceDocumentation = new ComplianceDocumentationGenerator(
repo,
logger,
);

const analyzer = new KitDependencyAnalyzer(repo, modules, logger);

const factory = new CliApiFacadeFactory(logger);
const terragrunt = factory.buildTerragrunt();
const platformDocumentation = new PlatformDocumentationGenerator(
repo,
foundation,
analyzer,
controls,
terragrunt,
logger,
);

const docsRepo = new DocumentationRepository(foundation);

await prepareSiteTemplate(docsRepo, repo, logger);

const generator = new DocumentationGenerator(
moduleDocumentation,
complianceDocumentation,
platformDocumentation,
);

await generator.generateFoundationDocumentation(docsRepo);
await terragrunt.run(docsModulePath, { raw: ["apply"] }, {
autoApprove: true,
});

foundationProgress.done();
}
Expand Down Expand Up @@ -171,34 +139,3 @@ async function buildDocumentation(
await npm.run(["install"], { cwd: dir });
await npm.run(["run", "docs:build"], { cwd: dir });
}

async function prepareSiteTemplate(
docsRepo: DocumentationRepository,
repo: CollieRepository,
logger: Logger,
) {
// TODO: throw if it doesn't work
const srcDir = repo.resolvePath("kit", "foundation", "docs", "template");

try {
await fs.copy(srcDir, docsRepo.resolvePath(), { overwrite: true });
} catch (e) {
if (e instanceof Deno.errors.NotFound) {
logger.error(
(fmt) =>
`could not find kit module with template for documentation site at ${
fmt.kitPath(
srcDir,
)
}`,
);

logger.tipCommand(
"This module is essential for documentation generation. To import this module run",
"kit import foundation/docs",
);
Deno.exit(1);
}
throw e;
}
}
14 changes: 13 additions & 1 deletion src/commands/prepareAnalyzeCommand.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Logger } from "../cli/Logger.ts";
import { ComplianceControlRepository } from "../compliance/ComplianceControlRepository.ts";
import {
FoundationDependencies,
KitDependencyAnalyzer,
Expand Down Expand Up @@ -32,11 +33,22 @@ async function analyze(
const validator = new ModelValidator(logger);

const modules = await KitModuleRepository.load(collie, validator, logger);
const controls = await ComplianceControlRepository.load(
collie,
validator,
logger,
);

const foundations = await collie.listFoundations();

const tasks = foundations.map(async (f) => {
const foundation = await FoundationRepository.load(collie, f, validator);
const analyzer = new KitDependencyAnalyzer(collie, modules, logger);
const analyzer = new KitDependencyAnalyzer(
collie,
modules,
controls,
logger,
);

return {
foundation,
Expand Down
28 changes: 0 additions & 28 deletions src/docs/ComplianceDocumentationGenerator.ts

This file was deleted.

19 changes: 0 additions & 19 deletions src/docs/DocumentationGenerator.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/docs/DocumentationRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class DocumentationRepository {
// we use a "hidden" directory with a leading "." because terragrunt excludes hidden files and dirs
// when building a terragrunt-cache folder, see https://terragrunt.gruntwork.io/docs/reference/config-blocks-and-attributes/#terraform "include_in_copy"
// > By default, Terragrunt excludes hidden files and folders during the copy step.
private readonly docsRootDir = ".docs";
private readonly docsRootDir = ".docs-v2";
private readonly docsContentDir = "docs";

constructor(private readonly foundation: FoundationRepository) {}
Expand Down
102 changes: 0 additions & 102 deletions src/docs/KitModuleDocumentationGenerator.ts

This file was deleted.

Loading
Loading