Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
7 changes: 6 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
"name": "devcontainers-ci",
"dockerFile": "Dockerfile",
"build": {
"cacheFrom": "ghcr.io/devcontainers/ci-devcontainer:latest"
"cacheFrom": "ghcr.io/devcontainers/ci-devcontainer:latest",
"args": {
// This is a temporary workaround when developing from host -> remote host -> devcontainer
// see: https://github.com/microsoft/vscode-remote-release/issues/7958
"BUILDKIT_INLINE_CACHE": "0"
}
},
"mounts": [
// Keep command history
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ inputs:
required: false
default: false
description: Builds the image with `--no-cache` (takes precedence over `cacheFrom`)
cliVersion:
required: false
default: latest
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the default now 0?

description: The version of the devcontainer CLI to use
outputs:
runCmdOutput:
description: The output of the command specified in the runCmd input
Expand Down
12 changes: 10 additions & 2 deletions azdo-task/DevcontainersCi/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,18 @@ export async function runMain(): Promise<void> {
);
return;
}
const devContainerCliInstalled = await devcontainer.isCliInstalled(exec);
const specifiedDevContainerCliVersion =
task.getInput('cliVersion') ?? 'latest';
const devContainerCliInstalled = await devcontainer.isCliInstalled(
exec,
specifiedDevContainerCliVersion,
);
if (!devContainerCliInstalled) {
console.log('Installing @devcontainers/cli...');
const success = await devcontainer.installCli(exec);
const success = await devcontainer.installCli(
exec,
specifiedDevContainerCliVersion,
);
if (!success) {
task.setResult(
task.TaskResult.Failed,
Expand Down
3 changes: 2 additions & 1 deletion azdo-task/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ In the example above, the devcontainer-build-run will perform the following step
| 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 |
| 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. |
| 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. |
| cliVersion | false | The version of the [devcontainers CLI](https://github.com/devcontainers/cli) to use |

## Outputs

Expand Down
14 changes: 5 additions & 9 deletions common/src/dev-container-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import {env} from 'process';
import {promisify} from 'util';
import {ExecFunction} from './exec';

const cliVersion = "0"; // Use 'latest' to get latest CLI version, or pin to specific version e.g. '0.14.1' if required

export interface DevContainerCliError {
outcome: 'error';
code: number;
Expand All @@ -25,18 +23,16 @@ function getSpecCliInfo() {
};
}

async function isCliInstalled(exec: ExecFunction): Promise<boolean> {
async function isCliInstalled(exec: ExecFunction, cliVersion: string): Promise<boolean> {
try {
const {exitCode} = await exec(getSpecCliInfo().command, ['--help'], {
silent: true,
});
return exitCode === 0;
const {exitCode, stdout} = await exec(getSpecCliInfo().command, ['--version'], {});
return exitCode === 0 && stdout === cliVersion;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could stdout include a newline? Maybe use .trim() on the string.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I have addressed the change.

} catch (error) {
return false;
}
}
const fstat = promisify(fs.stat);
async function installCli(exec: ExecFunction): Promise<boolean> {
async function installCli(exec: ExecFunction, cliVersion: string): Promise<boolean> {
// if we have a local 'cli' folder, then use that as we're testing a private cli build
let cliStat = null;
try {
Expand All @@ -52,7 +48,7 @@ async function installCli(exec: ExecFunction): Promise<boolean> {
}
return exitCode === 0;
}
console.log('** Installing @devcontainers/cli');
console.log(`** Installing @devcontainers/cli@${cliVersion}`);
const {exitCode, stdout, stderr} = await exec('bash', ['-c', `npm install -g @devcontainers/cli@${cliVersion}`], {});
if (exitCode != 0) {
console.log(stdout);
Expand Down
3 changes: 2 additions & 1 deletion docs/azure-devops-task.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ In the example above, the devcontainer-build-run will perform the following step
| 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 |
| 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. |
| 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. |
| cliVersion | false | The version of the [devcontainers CLI](https://github.com/devcontainers/cli) to use |

## Outputs

Expand Down
3 changes: 2 additions & 1 deletion docs/github-action.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ The [`devcontainers/ci` action](https://github.com/marketplace/actions/devcontai
| 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 |
| 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. |
| 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. |
| cliVersion | false | The version of the [devcontainers CLI](https://github.com/devcontainers/cli) to use |

## Outputs

Expand Down
12 changes: 10 additions & 2 deletions github-action/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,18 @@ export async function runMain(): Promise<void> {
);
return;
}
const devContainerCliInstalled = await devcontainer.isCliInstalled(exec);
const specifiedDevContainerCliVersion =
core.getInput('cliVersion') ?? 'latest';
const devContainerCliInstalled = await devcontainer.isCliInstalled(
exec,
specifiedDevContainerCliVersion,
);
if (!devContainerCliInstalled) {
core.info('Installing @devcontainers/cli...');
const success = await devcontainer.installCli(exec);
const success = await devcontainer.installCli(
exec,
specifiedDevContainerCliVersion,
);
if (!success) {
core.setFailed('@devcontainers/cli install failed!');
return;
Expand Down