Merge pull request #3794 from ayshiff/feature/techdocs-aws-s3

This commit is contained in:
Himanshu Mishra
2021-01-05 17:48:57 +01:00
committed by GitHub
15 changed files with 972 additions and 51 deletions
+44 -39
View File
@@ -133,49 +133,54 @@ export async function createRouter({
entity,
config,
});
if (publisherType === 'local') {
if (!(await docsBuilder.docsUpToDate())) {
await docsBuilder.build();
}
} else if (publisherType === 'googleGcs') {
// This block should be valid for all external storage implementations. So no need to duplicate in future,
// add the publisher type in the list here.
if (!(await publisher.hasDocsBeenGenerated(entity))) {
logger.info(
'No pre-generated documentation files found for the entity in the storage. Building docs...',
);
await docsBuilder.build();
// With a maximum of ~5 seconds wait, check if the files got published and if docs will be fetched
// on the user's page. If not, respond with a message asking them to check back later.
// The delay here is to make sure GCS registers newly uploaded files which is usually <1 second
let foundDocs = false;
for (let attempt = 0; attempt < 5; attempt++) {
if (await publisher.hasDocsBeenGenerated(entity)) {
foundDocs = true;
break;
}
await new Promise(r => setTimeout(r, 1000));
switch (publisherType) {
case 'local':
if (!(await docsBuilder.docsUpToDate())) {
await docsBuilder.build();
}
if (!foundDocs) {
logger.error(
'Published files are taking longer to show up in storage. Something went wrong.',
break;
case 'awsS3':
case 'googleGcs':
// This block should be valid for all external storage implementations. So no need to duplicate in future,
// add the publisher type in the list here.
if (!(await publisher.hasDocsBeenGenerated(entity))) {
logger.info(
'No pre-generated documentation files found for the entity in the storage. Building docs...',
);
res
.status(408)
.send(
'Sorry! It is taking longer for the generated docs to show up in storage. Check back later.',
await docsBuilder.build();
// With a maximum of ~5 seconds wait, check if the files got published and if docs will be fetched
// on the user's page. If not, respond with a message asking them to check back later.
// The delay here is to make sure GCS/AWS/etc. registers newly uploaded files which is usually <1 second
let foundDocs = false;
for (let attempt = 0; attempt < 5; attempt++) {
if (await publisher.hasDocsBeenGenerated(entity)) {
foundDocs = true;
break;
}
await new Promise(r => setTimeout(r, 1000));
}
if (!foundDocs) {
logger.error(
'Published files are taking longer to show up in storage. Something went wrong.',
);
return;
res
.status(408)
.send(
'Sorry! It is taking longer for the generated docs to show up in storage. Check back later.',
);
return;
}
} else {
logger.info(
'Found pre-generated docs for this entity. Serving them.',
);
// TODO: re-trigger build for cache invalidation.
// Compare the date modified of the requested file on storage and compare it against
// the last modified or last commit timestamp in the repository.
// Without this, docs will not be re-built once they have been generated.
}
} else {
logger.info(
'Found pre-generated docs for this entity. Serving them.',
);
// TODO: re-trigger build for cache invalidation.
// Compare the date modified of the requested file on storage and compare it against
// the last modified or last commit timestamp in the repository.
// Without this, docs will not be re-built once they have been generated.
}
break;
default:
}
}
+49 -4
View File
@@ -45,7 +45,7 @@ export interface Config {
/**
* attr: 'techdocs' - accepts a string value
* e.g. type: 'docker'
* aleternatives: 'local' etc.
* alternatives: 'local' etc.
* @see http://backstage.io/docs/features/techdocs/configuration
*/
techdocs: 'local' | 'docker';
@@ -59,16 +59,61 @@ export interface Config {
/**
* attr: 'type' - accepts a string value
* e.g. type: 'local'
* aleternatives: 'googleGcs' etc.
* alternatives: 'googleGcs' etc.
* @see http://backstage.io/docs/features/techdocs/configuration
*/
type: 'local' | 'awsS3';
type: 'local';
}
| {
/**
* attr: 'type' - accepts a string value
* e.g. type: 'awsS3'
* alternatives: 'googleGcs' etc.
* @see http://backstage.io/docs/features/techdocs/configuration
*/
type: 'awsS3';
/**
* awsS3 required when 'type' is set to awsS3
*/
awsS3?: {
/**
* Credentials used to access a storage bucket
* @visibility secret
*/
credentials: {
/**
* User access key id
* attr: 'accessKeyId' - accepts a string value
* @visibility secret
*/
accessKeyId: string;
/**
* User secret access key
* attr: 'secretAccessKey' - accepts a string value
* @visibility secret
*/
secretAccessKey: string;
};
/**
* Cloud Storage Bucket Name
* attr: 'bucketName' - accepts a string value
* @visibility secret
*/
bucketName: string;
/**
* AWS Region
* attr: 'region' - accepts a string value
* @visibility secret
*/
region?: string;
};
}
| {
/**
* attr: 'type' - accepts a string value
* e.g. type: 'googleGcs'
* aleternatives: 'googleGcs' etc.
* alternatives: 'googleGcs' etc.
* @see http://backstage.io/docs/features/techdocs/configuration
*/
type: 'googleGcs';