techdocs-common: Unify response type of Local and googleGcs publisher

This commit is contained in:
Himanshu Mishra
2020-12-09 20:32:41 +01:00
parent ac88ca2038
commit 92ecddbe24
5 changed files with 15 additions and 15 deletions
+6 -6
View File
@@ -50,8 +50,8 @@ built.
We assume each entity lives in a repository somewhere (GitHub, GitLab, etc.). We
recommend using a CI/CD pipeline with the repository that has a dedicated
step/job to generate docs for TechDocs. The generated static files are then stored
in a cloud storage solution of your choice.
step/job to generate docs for TechDocs. The generated static files are then
stored in a cloud storage solution of your choice.
[Track progress here](https://github.com/backstage/backstage/issues/3096).
Similar to how it is done in the Basic setup, the TechDocs Reader requests
@@ -62,8 +62,8 @@ TechDocs Reader.
We will provide instructions, scripts and/or templates (e.g. GitHub Actions) to
generate docs in your CI/CD system.
[Track progress here.](https://github.com/backstage/backstage/issues/3400) You
will be able to use `techdocs-cli` to generate docs and publish the generated docs
site files to your cloud storage system.
will be able to use `techdocs-cli` to generate docs and publish the generated
docs site files to your cloud storage system.
Note about caching: We have noticed internally that some storage providers can
be quite slow, which is why we are recommending a cache that sits between the
@@ -120,8 +120,8 @@ docs site in real-time?**
A: Generating the content from Markdown on the fly is not optimal (although that
is how the basic out-of-the-box setup is implemented). Storage solutions act as
a cache for the generated static content. TechDocs is also currently built on
MkDocs which does not allow us to generate docs per-page, so we would have to build
all docs for a entity on every request.
MkDocs which does not allow us to generate docs per-page, so we would have to
build all docs for a entity on every request.
# Future work
@@ -75,6 +75,6 @@ describe('GoogleGCSPublish', () => {
const entity = createMockEntity();
return expect(
publisher.publish({ entity, directory: '/path/to/generatedDirectory' }),
).resolves.toStrictEqual({});
).resolves.toBeUndefined();
});
});
@@ -93,7 +93,7 @@ export class GoogleGCSPublish implements PublisherBase {
* Upload all the files from the generated `directory` to the GCS bucket.
* Directory structure used in the bucket is - entityNamespace/entityKind/entityName/index.html
*/
publish({ entity, directory }: PublishRequest): Promise<{}> {
publish({ entity, directory }: PublishRequest): Promise<void> {
return new Promise((resolve, reject) => {
// Path of all files to upload, relative to the root of the source directory
// e.g. ['index.html', 'sub-page/index.html', 'assets/images/favicon.png']
@@ -140,7 +140,7 @@ export class GoogleGCSPublish implements PublisherBase {
this.logger.info(
`Successfully uploaded all the generated files for Entity ${entityRootDir}. Total number of files: ${allFilesToUpload.length}`,
);
resolve({});
resolve(undefined);
});
});
}
@@ -23,10 +23,7 @@ import {
PluginEndpointDiscovery,
} from '@backstage/backend-common';
import { Config } from '@backstage/config';
import { PublisherBase, PublishRequest } from './types';
/* `remoteUrl` is the URL which serves files from the local publisher's static directory. */
export type LocalPublishReturn = Promise<{ remoteUrl: string }>;
import { PublisherBase, PublishRequest, PublishResponse } from './types';
const staticDocsDir = resolvePackagePath(
'@backstage/plugin-techdocs-backend',
@@ -52,7 +49,7 @@ export class LocalPublish implements PublisherBase {
this.discovery = discovery;
}
publish({ entity, directory }: PublishRequest): LocalPublishReturn {
publish({ entity, directory }: PublishRequest): Promise<PublishResponse> {
const entityNamespace = entity.metadata.namespace ?? 'default';
const publishDir = resolvePackagePath(
@@ -27,7 +27,10 @@ export type PublishRequest = {
directory: string;
};
export type PublishResponse = {};
/* `remoteUrl` is the URL which serves files from the local publisher's static directory. */
export type PublishResponse = {
remoteUrl?: string;
} | void;
/**
* Base class for a TechDocs publisher (e.g. Local, Google GCS Bucket, AWS S3, etc.)