Thank you! I can definitely use this for some of what I'm doing.
Is there a way to do this with .with though? In TypeScript, .with has the signature with(arg: (param: Container) => Container): Container; so I'm not able to use sync or grab the id because of the promises, and I don't want to mix async with sync calls.
I currently have this code
export type ContainerRet = (container: Container) => Container;
export const withAws = (client: Client): ContainerRet => {
const home = homedir();
const awsConfigPath = ".aws/config";
const awsSsoCachePath = ".aws/sso/cache/";
const homeAwsConfigPath = `${home}/${awsConfigPath}`;
const homeAwsSsoCachePath = `${home}/${awsSsoCachePath}`;
const configSource = client.host().file(homeAwsConfigPath);
const ssoCacheSource = client.host().directory(homeAwsSsoCachePath);
return (container: Container) => container
.pipeline("Setup AWS")
.withDirectory(`/root/${awsSsoCachePath}`, ssoCacheSource)
.withFile(`/root/${awsConfigPath}`, configSource)
.withEnvVariable("AWS_PROFILE", "dev");
};
But if I use it using .with(withAws(client)).pipeline("something"), the something sub pipeline get nested within Setup AWS.
Switching that code to
export type ContainerRet = (container: Container) => Container | Promise<Container>;
export const withAws = (client: Client): ContainerRet => {
const home = homedir();
const awsConfigPath = ".aws/config";
const awsSsoCachePath = ".aws/sso/cache/";
const homeAwsConfigPath = `${home}/${awsConfigPath}`;
const homeAwsSsoCachePath = `${home}/${awsSsoCachePath}`;
const configSource = client.host().file(homeAwsConfigPath);
const ssoCacheSource = client.host().directory(homeAwsSsoCachePath);
return async (container: Container) => {
const setupAws = await container
.pipeline("Setup AWS")
.withDirectory(`/root/${awsSsoCachePath}`, ssoCacheSource)
.withFile(`/root/${awsConfigPath}`, configSource)
.withEnvVariable("AWS_PROFILE", "dev").sync();
const id = await setupAws.id();
return client.container({
id,
});
};
};
no longer works with with() type signature.