diff --git a/action.yml b/action.yml index f215933d..37580742 100644 --- a/action.yml +++ b/action.yml @@ -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) @@ -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 diff --git a/azdo-task/DevcontainersCi/src/main.ts b/azdo-task/DevcontainersCi/src/main.ts index 424cd24f..1c1920f5 100644 --- a/azdo-task/DevcontainersCi/src/main.ts +++ b/azdo-task/DevcontainersCi/src/main.ts @@ -45,6 +45,7 @@ export async function runMain(): Promise { 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'; @@ -70,7 +71,7 @@ export async function runMain(): Promise { } 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 @@ -94,6 +95,7 @@ export async function runMain(): Promise { platform, additionalCacheFroms: cacheFrom, output: buildxOutput, + noCache, }; console.log('\n\n'); diff --git a/azdo-task/DevcontainersCi/task.json b/azdo-task/DevcontainersCi/task.json index 13d27360..f7a3d446 100644 --- a/azdo-task/DevcontainersCi/task.json +++ b/azdo-task/DevcontainersCi/task.json @@ -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": [{ diff --git a/azdo-task/README.md b/azdo-task/README.md index 4eb1affb..4775fbc8 100644 --- a/azdo-task/README.md +++ b/azdo-task/README.md @@ -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 | @@ -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 diff --git a/common/src/dev-container-cli.ts b/common/src/dev-container-cli.ts index b9a5ae60..5a58828b 100644 --- a/common/src/dev-container-cli.ts +++ b/common/src/dev-container-cli.ts @@ -140,6 +140,7 @@ export interface DevContainerCliBuildArgs { additionalCacheFroms?: string[]; userDataFolder?: string; output?: string, + noCache?: boolean, } async function devContainerBuild( args: DevContainerCliBuildArgs, @@ -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), ); diff --git a/docs/azure-devops-task.md b/docs/azure-devops-task.md index 4eb1affb..4775fbc8 100644 --- a/docs/azure-devops-task.md +++ b/docs/azure-devops-task.md @@ -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 | @@ -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 diff --git a/docs/github-action.md b/docs/github-action.md index 8284f2e3..3725d2f9 100644 --- a/docs/github-action.md +++ b/docs/github-action.md @@ -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 | @@ -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 diff --git a/github-action/src/main.ts b/github-action/src/main.ts index eef38426..93049589 100644 --- a/github-action/src/main.ts +++ b/github-action/src/main.ts @@ -43,6 +43,7 @@ export async function runMain(): Promise { 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', ); @@ -59,8 +60,6 @@ export async function runMain(): Promise { } 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); @@ -72,7 +71,7 @@ export async function runMain(): Promise { } 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 @@ -104,6 +103,7 @@ export async function runMain(): Promise { additionalCacheFroms: cacheFrom, userDataFolder, output: buildxOutput, + noCache, }; const result = await devcontainer.build(args, log);