Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add noCache option #199

Merged
merged 8 commits into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ inputs:
subFolder:
required: false
description: Specify a child folder (containing a .devcontainer) instead of using the repository root
default:
default:
checkoutPath:
required: false
description: Specify path to checked out folder if not using default (or for testing with nektos/act)
Expand Down Expand Up @@ -48,8 +48,13 @@ inputs:
required: false
description: Some steps for building the dev container (e.g. container-features) require generating additional build files. To aid docker build cache re-use, you can use this property to set the path that these files will be generated under and use the actions/cache action to cache that folder across runs
cacheFrom:
required: False
required: false
description: Specify additional images to use for build caching
noCache:
type: boolean
required: false
default: false
description: Builds the image with `--no-cache` (takes precedence over `cacheFrom`)
outputs:
runCmdOutput:
description: The output of the command specified in the runCmd input
Expand Down
4 changes: 3 additions & 1 deletion azdo-task/DevcontainersCi/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export async function runMain(): Promise<void> {
const envs = task.getInput('env')?.split('\n') ?? [];
const inputEnvsWithDefaults = populateDefaults(envs);
const cacheFrom = task.getInput('cacheFrom')?.split('\n') ?? [];
const noCache = (task.getInput('noCache') ?? 'false') === 'true';
const skipContainerUserIdUpdate =
(task.getInput('skipContainerUserIdUpdate') ?? 'false') === 'true';

Expand All @@ -70,7 +71,7 @@ export async function runMain(): Promise<void> {
}
if (imageName) {
if (fullImageNameArray.length === 1) {
if (!cacheFrom.includes(fullImageNameArray[0])) {
if (!noCache && !cacheFrom.includes(fullImageNameArray[0])) {
// If the cacheFrom options don't include the fullImageName, add it here
// This ensures that when building a PR where the image specified in the action
// isn't included in devcontainer.json (or docker-compose.yml), the action still
Expand All @@ -94,6 +95,7 @@ export async function runMain(): Promise<void> {
platform,
additionalCacheFroms: cacheFrom,
output: buildxOutput,
noCache,
};

console.log('\n\n');
Expand Down
6 changes: 6 additions & 0 deletions azdo-task/DevcontainersCi/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@
"type": "multiLine",
"label": "Specify additional images to use for build caching",
"required": false
},
{
"name": "noCache",
"type": "boolean",
"label": "Builds the image with `--no-cache` (takes precedence over `cacheFrom`)",
"required": false
}
],
"outputVariables": [{
Expand Down
5 changes: 3 additions & 2 deletions azdo-task/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ In the example above, the devcontainer-build-run will perform the following step
| Name | Required | Description |
| ------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| imageName | true | Image name to use when building the dev container image (including registry) |
| imageTag | false | One or more comma-separated image tags (defaults to `latest`) |
| imageTag | false | One or more comma-separated image tags (defaults to `latest`) |
| subFolder | false | Use this to specify the repo-relative path to the folder containing the dev container (i.e. the folder that contains the `.devcontainer` folder). Defaults to repo root |
| runCmd | true | The command to run after building the dev container image |
| env | false | Specify environment variables to pass to the dev container when run |
Expand All @@ -79,7 +79,8 @@ In the example above, the devcontainer-build-run will perform the following step
| buildReasonsForPush | false | Allows you to limit the Build.Reason values that are allowed to push to the registry. Defaults to Manual, IndividualCI, BatchedCI. See https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&viewFallbackFrom=vsts&tabs=yaml |
| 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) |
| cacheFrom | false | Specify additional images to use for build caching |
| 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. |
| noCache | false | Builds the image with `--no-cache` (takes precedence over `cacheFrom`) |
| 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. |

## Outputs

Expand Down
5 changes: 4 additions & 1 deletion common/src/dev-container-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export interface DevContainerCliBuildArgs {
additionalCacheFroms?: string[];
userDataFolder?: string;
output?: string,
noCache?: boolean,
}
async function devContainerBuild(
args: DevContainerCliBuildArgs,
Expand All @@ -164,7 +165,9 @@ async function devContainerBuild(
if (args.userDataFolder) {
commandArgs.push("--user-data-folder", args.userDataFolder);
}
if (args.additionalCacheFroms) {
if (args.noCache) {
commandArgs.push("--no-cache");
} else if (args.additionalCacheFroms) {
args.additionalCacheFroms.forEach(cacheFrom =>
commandArgs.push('--cache-from', cacheFrom),
);
Expand Down
5 changes: 3 additions & 2 deletions docs/azure-devops-task.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ In the example above, the devcontainer-build-run will perform the following step
| Name | Required | Description |
| ------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| imageName | true | Image name to use when building the dev container image (including registry) |
| imageTag | false | One or more comma-separated image tags (defaults to `latest`) |
| imageTag | false | One or more comma-separated image tags (defaults to `latest`) |
| subFolder | false | Use this to specify the repo-relative path to the folder containing the dev container (i.e. the folder that contains the `.devcontainer` folder). Defaults to repo root |
| runCmd | true | The command to run after building the dev container image |
| env | false | Specify environment variables to pass to the dev container when run |
Expand All @@ -79,7 +79,8 @@ In the example above, the devcontainer-build-run will perform the following step
| buildReasonsForPush | false | Allows you to limit the Build.Reason values that are allowed to push to the registry. Defaults to Manual, IndividualCI, BatchedCI. See https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&viewFallbackFrom=vsts&tabs=yaml |
| 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) |
| cacheFrom | false | Specify additional images to use for build caching |
| 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. |
| noCache | false | Builds the image with `--no-cache` (takes precedence over `cacheFrom`) |
| 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. |

## Outputs

Expand Down
5 changes: 3 additions & 2 deletions docs/github-action.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ The [`devcontainers/ci` action](https://github.com/marketplace/actions/devcontai
| Name | Required | Description |
| ------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| imageName | true | Image name to use when building the dev container image (including registry) |
| imageTag | false | One or more comma-separated image tags (defaults to `latest`) |
| imageTag | false | One or more comma-separated image tags (defaults to `latest`) |
| subFolder | false | Use this to specify the repo-relative path to the folder containing the dev container (i.e. the folder that contains the `.devcontainer` folder). Defaults to repo root |
| runCmd | true | The command to run after building the dev container image |
| env | false | Specify environment variables to pass to the dev container when run |
Expand All @@ -138,7 +138,8 @@ The [`devcontainers/ci` action](https://github.com/marketplace/actions/devcontai
| eventFilterForPush | false | Set the event names (e.g. `pull_request`, `push`) that are allowed to trigger a push of the dev container image. Defaults to `push`. Leave empty for all |
| 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) |
| cacheFrom | false | Specify additional images to use for build caching |
| 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. |
| noCache | false | Builds the image with `--no-cache` (takes precedence over `cacheFrom`) |
| 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. |

## Outputs

Expand Down
6 changes: 3 additions & 3 deletions github-action/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export async function runMain(): Promise<void> {
const inputEnvs: string[] = core.getMultilineInput('env');
const inputEnvsWithDefaults = populateDefaults(inputEnvs);
const cacheFrom: string[] = core.getMultilineInput('cacheFrom');
const noCache: boolean = core.getBooleanInput('noCache');
const skipContainerUserIdUpdate = core.getBooleanInput(
'skipContainerUserIdUpdate',
);
Expand All @@ -59,8 +60,6 @@ export async function runMain(): Promise<void> {
}
const buildxOutput = platform ? 'type=oci,dest=/tmp/output.tar' : undefined;

// TODO - nocache

const log = (message: string): void => core.info(message);
const workspaceFolder = path.resolve(checkoutPath, subFolder);

Expand All @@ -72,7 +71,7 @@ export async function runMain(): Promise<void> {
}
if (imageName) {
if (fullImageNameArray.length === 1) {
if (!cacheFrom.includes(fullImageNameArray[0])) {
if (!noCache && !cacheFrom.includes(fullImageNameArray[0])) {
// If the cacheFrom options don't include the fullImageName, add it here
// This ensures that when building a PR where the image specified in the action
// isn't included in devcontainer.json (or docker-compose.yml), the action still
Expand Down Expand Up @@ -104,6 +103,7 @@ export async function runMain(): Promise<void> {
additionalCacheFroms: cacheFrom,
userDataFolder,
output: buildxOutput,
noCache,
};
const result = await devcontainer.build(args, log);

Expand Down