Skip to content

Commit 80f211c

Browse files
committed
Add cacheTo argument to ci action
1 parent 4f6b93e commit 80f211c

File tree

10 files changed

+33
-2
lines changed

10 files changed

+33
-2
lines changed

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ inputs:
6363
required: false
6464
default: false
6565
description: Builds the image with `--no-cache` (takes precedence over `cacheFrom`)
66+
cacheTo:
67+
required: false
68+
description: Specify the image to cache the built image to
6669
outputs:
6770
runCmdOutput:
6871
description: The output of the command specified in the runCmd input

azdo-task/DevcontainersCi/src/docker.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export async function buildImage(
1212
subFolder: string,
1313
skipContainerUserIdUpdate: boolean,
1414
cacheFrom: string[],
15+
cacheTo: string | undefined,
1516
): Promise<string> {
1617
console.log('🏗 Building dev container...');
1718
try {
@@ -23,6 +24,7 @@ export async function buildImage(
2324
subFolder,
2425
skipContainerUserIdUpdate,
2526
cacheFrom,
27+
cacheTo,
2628
);
2729
} catch (error) {
2830
task.setResult(task.TaskResult.Failed, error);

azdo-task/DevcontainersCi/src/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export async function runMain(): Promise<void> {
4848
const inputEnvsWithDefaults = populateDefaults(envs, inheritEnv);
4949
const cacheFrom = task.getInput('cacheFrom')?.split('\n') ?? [];
5050
const noCache = (task.getInput('noCache') ?? 'false') === 'true';
51+
const cacheTo = task.getInput('cacheTo') ?? undefined;
5152
const skipContainerUserIdUpdate =
5253
(task.getInput('skipContainerUserIdUpdate') ?? 'false') === 'true';
5354

@@ -101,6 +102,7 @@ export async function runMain(): Promise<void> {
101102
additionalCacheFroms: cacheFrom,
102103
output: buildxOutput,
103104
noCache,
105+
cacheTo,
104106
};
105107

106108
console.log('\n\n');

azdo-task/DevcontainersCi/task.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@
122122
"type": "boolean",
123123
"label": "Builds the image with `--no-cache` (takes precedence over `cacheFrom`)",
124124
"required": false
125+
},
126+
{
127+
"name": "cacheTo",
128+
"type": "string",
129+
"label": "Specify the image to cache the built image to",
130+
"required": false
125131
}
126132
],
127133
"outputVariables": [{

azdo-task/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ In the example above, the devcontainer-build-run will perform the following step
8282
| skipContainerUserIdUpdate | false | For non-root Dev Containers (i.e. where `remoteUser` is specified), the action attempts to make the container user UID and GID match those of the host user. Set this to true to skip this step (defaults to false) |
8383
| cacheFrom | false | Specify additional images to use for build caching |
8484
| noCache | false | Builds the image with `--no-cache` (takes precedence over `cacheFrom`) |
85+
| cacheTo | false | Specify the image to cache the built image to
8586
| platform | false | Platforms for which the image should be built. If omitted, defaults to the platform of the GitHub Actions Runner. Multiple platforms should be comma separated. |
8687

8788
## Outputs

common/src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface DevContainerConfig {
1515
context?: string;
1616
args?: Record<string, string>;
1717
cacheFrom?: string | string[];
18+
cacheTo?: string;
1819
};
1920
runArgs?: string[];
2021
mounts?: string[];

common/src/dev-container-cli.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ export interface DevContainerCliBuildArgs {
161161
userDataFolder?: string;
162162
output?: string,
163163
noCache?: boolean,
164+
cacheTo?: string,
164165
}
165166
async function devContainerBuild(
166167
args: DevContainerCliBuildArgs,
@@ -194,6 +195,9 @@ async function devContainerBuild(
194195
args.additionalCacheFroms.forEach(cacheFrom =>
195196
commandArgs.push('--cache-from', cacheFrom),
196197
);
198+
if (args.cacheTo) {
199+
commandArgs.push('--cache-to', args.cacheTo);
200+
}
197201
}
198202
return await runSpecCliJsonCommand<DevContainerCliBuildResult>({
199203
args: commandArgs,

common/src/docker.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export async function buildImage(
2121
subFolder: string,
2222
skipContainerUserIdUpdate: boolean,
2323
cacheFrom: string[],
24+
cacheTo: string | undefined,
2425
): Promise<string> {
2526
const folder = path.join(checkoutPath, subFolder);
2627
const devcontainerJsonPath = path.join(
@@ -37,6 +38,7 @@ export async function buildImage(
3738
folder,
3839
devcontainerConfig,
3940
cacheFrom,
41+
cacheTo,
4042
);
4143

4244
if (!devcontainerConfig.remoteUser || skipContainerUserIdUpdate == true) {
@@ -61,6 +63,7 @@ async function buildImageBase(
6163
folder: string,
6264
devcontainerConfig: config.DevContainerConfig,
6365
cacheFrom: string[],
66+
cacheTo: string | undefined,
6467
): Promise<void> {
6568
const configDockerfile = config.getDockerfile(devcontainerConfig);
6669
if (!configDockerfile) {
@@ -85,8 +88,13 @@ async function buildImageBase(
8588
);
8689
}
8790
cacheFrom.forEach(cacheValue => args.push('--cache-from', cacheValue));
88-
args.push('--cache-to');
89-
args.push('type=inline');
91+
if (cacheTo) {
92+
args.push('--cache-to');
93+
args.push(cacheTo);
94+
} else {
95+
args.push('--cache-to');
96+
args.push('type=inline');
97+
}
9098
args.push('--output=type=docker');
9199

92100
const buildArgs = devcontainerConfig.build?.args;

github-action/src/docker.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export async function buildImage(
1212
subFolder: string,
1313
skipContainerUserIdUpdate: boolean,
1414
cacheFrom: string[],
15+
cacheTo: string | undefined,
1516
): Promise<string> {
1617
core.startGroup('🏗 Building dev container...');
1718
try {
@@ -23,6 +24,7 @@ export async function buildImage(
2324
subFolder,
2425
skipContainerUserIdUpdate,
2526
cacheFrom,
27+
cacheTo,
2628
);
2729
} catch (error) {
2830
core.setFailed(error);

github-action/src/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export async function runMain(): Promise<void> {
5757
const inputEnvsWithDefaults = populateDefaults(inputEnvs, inheritEnv);
5858
const cacheFrom: string[] = core.getMultilineInput('cacheFrom');
5959
const noCache: boolean = core.getBooleanInput('noCache');
60+
const cacheTo = emptyStringAsUndefined(core.getInput('cacheTo'));
6061
const skipContainerUserIdUpdate = core.getBooleanInput(
6162
'skipContainerUserIdUpdate',
6263
);
@@ -121,6 +122,7 @@ export async function runMain(): Promise<void> {
121122
userDataFolder,
122123
output: buildxOutput,
123124
noCache,
125+
cacheTo,
124126
};
125127
const result = await devcontainer.build(args, log);
126128

0 commit comments

Comments
 (0)