问题描述
我正在尝试结合Google Cloud Build文档中的两个示例
This example where a container is built using a yaml file
And this example where a persistent volume is used
我的场景很简单,构建的第一步产生了一些我想捆绑到后续步骤中构建的Docker映像中的资产。但是,由于COPY命令是relative to the build directory of the image,因此我无法确定如何从用于第二步的Dockerfile中的第一步引用资产。
解决方法
可能有多种方法可以解决此问题,但是我发现最简单的方法是使用docker
cloud builder并运行andAnother
脚本(因为Docker映像中不包括Bash)
在此示例中,我们以问题中的示例为基础,在第一个构建步骤中生成资产IDayOfWeek
,然后在第二步的interface IDayOfWeek {
sunday?: boolean;
monday?: boolean;
tuesday?: boolean;
wednesday?: boolean;
thursday?: boolean;
friday?: boolean;
saturday?: boolean;
// These ⬇ won't work if you're assigning boolean values ❌
// someOtherValue?: string;
// andAnother?: Date;
}
interface ISelectOption<T> {
label: string;
value: T;
}
interface IUserInput {
someInputName: string;
weekday: ISelectOption<keyof IDayOfWeek>[]; // Note the use of keyof,not typeof
}
function saveUserInput(inp: IUserInput) {
let dayOfWeek: IDayOfWeek = {};
// This works ✅ as long as IDayOfWeek doesn't have any keys with non-boolean values!
for (const key of inp.weekday) {
dayOfWeek[key.value] = true;
}
}
中使用它。
cloudbuild.yaml
sh
docker-build.sh
file