Unify Wiki and Studio application and simplify deployment
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
// Only invoked inside the dedicated test network with this run's bucket name.
|
||||
import {S3Client,ListObjectsV2Command,DeleteObjectsCommand,DeleteBucketCommand} from '@aws-sdk/client-s3';
|
||||
const bucket=process.env.S3_BUCKET;
|
||||
if (!/^ci-[1-9][0-9]*$/.test(bucket || '')) throw Error('Refusing non-CI bucket');
|
||||
const client=new S3Client({endpoint:'http://objects:9000',region:'us-east-1',forcePathStyle:true,credentials:{accessKeyId:process.env.S3_ACCESS_KEY,secretAccessKey:process.env.S3_SECRET_KEY}});
|
||||
try {
|
||||
// Re-list the first page after each deletion so no pagination token can skip keys.
|
||||
for (;;) {
|
||||
const result=await client.send(new ListObjectsV2Command({Bucket:bucket,MaxKeys:1000}));
|
||||
const keys=(result.Contents || []).map(({Key})=>({Key}));
|
||||
if (!keys.length) break;
|
||||
const deleted=await client.send(new DeleteObjectsCommand({Bucket:bucket,Delete:{Objects:keys,Quiet:true}}));
|
||||
if (deleted.Errors?.length) throw Error('CI object cleanup failed');
|
||||
}
|
||||
await client.send(new DeleteBucketCommand({Bucket:bucket}));
|
||||
} catch (error) {
|
||||
if (error.name !== 'NoSuchBucket') throw error;
|
||||
}
|
||||
Reference in New Issue
Block a user