Skip to content

Commit

Permalink
Merge pull request #159 from stuartleeks/sl/150-runcmd-optional
Browse files Browse the repository at this point in the history
Make runCmd optional
  • Loading branch information
stuartleeks authored Aug 1, 2022
2 parents feeeb38 + d3c8058 commit 36f569c
Show file tree
Hide file tree
Showing 14 changed files with 308 additions and 219 deletions.
6 changes: 6 additions & 0 deletions .azure-devops/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,10 @@ jobs:
imageTag: $(IMAGE_TAG)
sourceBranchFilterForPush: ''

- job: test_no_runCmd
displayName: Test without runCmd
steps:
- task: DevcontainersCi@0
inputs:
subFolder: github-tests/Dockerfile/build-only

21 changes: 21 additions & 0 deletions .github/workflows/ci_common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ jobs:
- test-gh-skip-user-update
- test-compose-features
- test-simple
- test-no-run
runs-on: ubuntu-latest
if: ${{ inputs.prHeadSha }}
steps:
Expand Down Expand Up @@ -211,6 +212,7 @@ jobs:
- test-gh-skip-user-update
- test-compose-features
- test-simple
- test-no-run
runs-on: ubuntu-latest
steps:
- name: Simple step
Expand All @@ -232,6 +234,7 @@ jobs:
- test-gh-skip-user-update
- test-compose-features
- test-simple
- test-no-run
if: ${{ inputs.release == true }}
env:
VERSION: ${{ needs.build.outputs.version }}
Expand Down Expand Up @@ -725,3 +728,21 @@ jobs:
eventFilterForPush: |
push
pull_request
test-no-run:
name: Run test without runCmd
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout
uses: actions/checkout@v2
with:
persist-credentials: false
# if the following value is missing (i.e. not triggered via comment workflow)
# then the default checkout will apply
ref: ${{ inputs.prRef }}

- name: Run test
uses: ./
with:
subFolder: github-tests/Dockerfile/build-only
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ inputs:
required: false
description: Image tag (defaults to latest)
runCmd:
required: true
description: Specify the command to run after building the dev container image
required: false
description: Specify the command to run after building the dev container image. Can be omitted to skip starting the container.
subFolder:
required: false
description: Specify a child folder (containing a .devcontainer) instead of using the repository root
Expand Down
75 changes: 38 additions & 37 deletions azdo-task/DevcontainersCi/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,7 @@ function runMain() {
const imageName = task.getInput('imageName');
const imageTag = task.getInput('imageTag');
const subFolder = (_b = task.getInput('subFolder')) !== null && _b !== void 0 ? _b : '.';
const runCommand = task.getInput('runCmd', true);
if (!runCommand) {
task.setResult(task.TaskResult.Failed, 'runCmd input is required');
return;
}
const runCommand = task.getInput('runCmd');
const envs = (_d = (_c = task.getInput('env')) === null || _c === void 0 ? void 0 : _c.split('\n')) !== null && _d !== void 0 ? _d : [];
const inputEnvsWithDefaults = envvars_1.populateDefaults(envs);
const cacheFrom = (_f = (_e = task.getInput('cacheFrom')) === null || _e === void 0 ? void 0 : _e.split('\n')) !== null && _f !== void 0 ? _f : [];
Expand Down Expand Up @@ -294,39 +290,44 @@ function runMain() {
if (buildResult.outcome !== 'success') {
return;
}
console.log('\n\n');
console.log('***');
console.log('*** Starting the dev container');
console.log('***');
const upArgs = {
workspaceFolder,
additionalCacheFroms: cacheFrom,
skipContainerUserIdUpdate,
};
const upResult = yield dev_container_cli_1.devcontainer.up(upArgs, log);
if (upResult.outcome !== 'success') {
console.log(`### ERROR: Dev container up failed: ${upResult.message} (exit code: ${upResult.code})\n${upResult.description}`);
task.setResult(task_1.TaskResult.Failed, upResult.message);
}
if (upResult.outcome !== 'success') {
return;
}
console.log('\n\n');
console.log('***');
console.log('*** Running command in the dev container');
console.log('***');
const execArgs = {
workspaceFolder,
command: ['bash', '-c', runCommand],
env: inputEnvsWithDefaults,
};
const execResult = yield dev_container_cli_1.devcontainer.exec(execArgs, log);
if (execResult.outcome !== 'success') {
console.log(`### ERROR: Dev container exec: ${execResult.message} (exit code: ${execResult.code})\n${execResult.description}`);
task.setResult(task_1.TaskResult.Failed, execResult.message);
if (runCommand) {
console.log('\n\n');
console.log('***');
console.log('*** Starting the dev container');
console.log('***');
const upArgs = {
workspaceFolder,
additionalCacheFroms: cacheFrom,
skipContainerUserIdUpdate,
};
const upResult = yield dev_container_cli_1.devcontainer.up(upArgs, log);
if (upResult.outcome !== 'success') {
console.log(`### ERROR: Dev container up failed: ${upResult.message} (exit code: ${upResult.code})\n${upResult.description}`);
task.setResult(task_1.TaskResult.Failed, upResult.message);
}
if (upResult.outcome !== 'success') {
return;
}
console.log('\n\n');
console.log('***');
console.log('*** Running command in the dev container');
console.log('***');
const execArgs = {
workspaceFolder,
command: ['bash', '-c', runCommand],
env: inputEnvsWithDefaults,
};
const execResult = yield dev_container_cli_1.devcontainer.exec(execArgs, log);
if (execResult.outcome !== 'success') {
console.log(`### ERROR: Dev container exec: ${execResult.message} (exit code: ${execResult.code})\n${execResult.description}`);
task.setResult(task_1.TaskResult.Failed, execResult.message);
}
if (execResult.outcome !== 'success') {
return;
}
}
if (execResult.outcome !== 'success') {
return;
else {
console.log('No runCmd set - skipping starting/running container');
}
// TODO - should we stop the container?
}
Expand Down
2 changes: 1 addition & 1 deletion azdo-task/DevcontainersCi/dist/index.js.map

Large diffs are not rendered by default.

75 changes: 38 additions & 37 deletions azdo-task/DevcontainersCi/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,7 @@ function runMain() {
const imageName = task.getInput('imageName');
const imageTag = task.getInput('imageTag');
const subFolder = (_b = task.getInput('subFolder')) !== null && _b !== void 0 ? _b : '.';
const runCommand = task.getInput('runCmd', true);
if (!runCommand) {
task.setResult(task.TaskResult.Failed, 'runCmd input is required');
return;
}
const runCommand = task.getInput('runCmd');
const envs = (_d = (_c = task.getInput('env')) === null || _c === void 0 ? void 0 : _c.split('\n')) !== null && _d !== void 0 ? _d : [];
const inputEnvsWithDefaults = envvars_1.populateDefaults(envs);
const cacheFrom = (_f = (_e = task.getInput('cacheFrom')) === null || _e === void 0 ? void 0 : _e.split('\n')) !== null && _f !== void 0 ? _f : [];
Expand Down Expand Up @@ -105,39 +101,44 @@ function runMain() {
if (buildResult.outcome !== 'success') {
return;
}
console.log('\n\n');
console.log('***');
console.log('*** Starting the dev container');
console.log('***');
const upArgs = {
workspaceFolder,
additionalCacheFroms: cacheFrom,
skipContainerUserIdUpdate,
};
const upResult = yield dev_container_cli_1.devcontainer.up(upArgs, log);
if (upResult.outcome !== 'success') {
console.log(`### ERROR: Dev container up failed: ${upResult.message} (exit code: ${upResult.code})\n${upResult.description}`);
task.setResult(task_1.TaskResult.Failed, upResult.message);
}
if (upResult.outcome !== 'success') {
return;
}
console.log('\n\n');
console.log('***');
console.log('*** Running command in the dev container');
console.log('***');
const execArgs = {
workspaceFolder,
command: ['bash', '-c', runCommand],
env: inputEnvsWithDefaults,
};
const execResult = yield dev_container_cli_1.devcontainer.exec(execArgs, log);
if (execResult.outcome !== 'success') {
console.log(`### ERROR: Dev container exec: ${execResult.message} (exit code: ${execResult.code})\n${execResult.description}`);
task.setResult(task_1.TaskResult.Failed, execResult.message);
if (runCommand) {
console.log('\n\n');
console.log('***');
console.log('*** Starting the dev container');
console.log('***');
const upArgs = {
workspaceFolder,
additionalCacheFroms: cacheFrom,
skipContainerUserIdUpdate,
};
const upResult = yield dev_container_cli_1.devcontainer.up(upArgs, log);
if (upResult.outcome !== 'success') {
console.log(`### ERROR: Dev container up failed: ${upResult.message} (exit code: ${upResult.code})\n${upResult.description}`);
task.setResult(task_1.TaskResult.Failed, upResult.message);
}
if (upResult.outcome !== 'success') {
return;
}
console.log('\n\n');
console.log('***');
console.log('*** Running command in the dev container');
console.log('***');
const execArgs = {
workspaceFolder,
command: ['bash', '-c', runCommand],
env: inputEnvsWithDefaults,
};
const execResult = yield dev_container_cli_1.devcontainer.exec(execArgs, log);
if (execResult.outcome !== 'success') {
console.log(`### ERROR: Dev container exec: ${execResult.message} (exit code: ${execResult.code})\n${execResult.description}`);
task.setResult(task_1.TaskResult.Failed, execResult.message);
}
if (execResult.outcome !== 'success') {
return;
}
}
if (execResult.outcome !== 'success') {
return;
else {
console.log('No runCmd set - skipping starting/running container');
}
// TODO - should we stop the container?
}
Expand Down
84 changes: 42 additions & 42 deletions azdo-task/DevcontainersCi/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ export async function runMain(): Promise<void> {
const imageName = task.getInput('imageName');
const imageTag = task.getInput('imageTag');
const subFolder = task.getInput('subFolder') ?? '.';
const runCommand = task.getInput('runCmd', true);
if (!runCommand) {
task.setResult(task.TaskResult.Failed, 'runCmd input is required');
return;
}
const runCommand = task.getInput('runCmd');
const envs = task.getInput('env')?.split('\n') ?? [];
const inputEnvsWithDefaults = populateDefaults(envs);
const cacheFrom = task.getInput('cacheFrom')?.split('\n') ?? [];
Expand Down Expand Up @@ -89,44 +85,48 @@ export async function runMain(): Promise<void> {
return;
}

console.log('\n\n');
console.log('***');
console.log('*** Starting the dev container');
console.log('***');
const upArgs: DevContainerCliUpArgs = {
workspaceFolder,
additionalCacheFroms: cacheFrom,
skipContainerUserIdUpdate,
};
const upResult = await devcontainer.up(upArgs, log);
if (upResult.outcome !== 'success') {
console.log(
`### ERROR: Dev container up failed: ${upResult.message} (exit code: ${upResult.code})\n${upResult.description}`,
);
task.setResult(TaskResult.Failed, upResult.message);
}
if (upResult.outcome !== 'success') {
return;
}
if (runCommand) {
console.log('\n\n');
console.log('***');
console.log('*** Starting the dev container');
console.log('***');
const upArgs: DevContainerCliUpArgs = {
workspaceFolder,
additionalCacheFroms: cacheFrom,
skipContainerUserIdUpdate,
};
const upResult = await devcontainer.up(upArgs, log);
if (upResult.outcome !== 'success') {
console.log(
`### ERROR: Dev container up failed: ${upResult.message} (exit code: ${upResult.code})\n${upResult.description}`,
);
task.setResult(TaskResult.Failed, upResult.message);
}
if (upResult.outcome !== 'success') {
return;
}

console.log('\n\n');
console.log('***');
console.log('*** Running command in the dev container');
console.log('***');
const execArgs: DevContainerCliExecArgs = {
workspaceFolder,
command: ['bash', '-c', runCommand],
env: inputEnvsWithDefaults,
};
const execResult = await devcontainer.exec(execArgs, log);
if (execResult.outcome !== 'success') {
console.log(
`### ERROR: Dev container exec: ${execResult.message} (exit code: ${execResult.code})\n${execResult.description}`,
);
task.setResult(TaskResult.Failed, execResult.message);
}
if (execResult.outcome !== 'success') {
return;
console.log('\n\n');
console.log('***');
console.log('*** Running command in the dev container');
console.log('***');
const execArgs: DevContainerCliExecArgs = {
workspaceFolder,
command: ['bash', '-c', runCommand],
env: inputEnvsWithDefaults,
};
const execResult = await devcontainer.exec(execArgs, log);
if (execResult.outcome !== 'success') {
console.log(
`### ERROR: Dev container exec: ${execResult.message} (exit code: ${execResult.code})\n${execResult.description}`,
);
task.setResult(TaskResult.Failed, execResult.message);
}
if (execResult.outcome !== 'success') {
return;
}
} else {
console.log('No runCmd set - skipping starting/running container');
}

// TODO - should we stop the container?
Expand Down
3 changes: 1 addition & 2 deletions azdo-task/DevcontainersCi/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
"name": "runCmd",
"type": "multiLine",
"label": "Specify the command to run after building the dev container image",
"required": true,
"defaultValue": "echo \"Put your command(s) here\""
"required": false
},
{
"name": "subFolder",
Expand Down
Loading

0 comments on commit 36f569c

Please sign in to comment.