Skip to content

Commit

Permalink
update direct-tarball to follow spec + refactor `processFeatureIden…
Browse files Browse the repository at this point in the history
…tifier` tests (#105)

* refactor tests to iterate on feature tests faster

* package in container-features test

* restore existing file path parsing logic

* update test to search in correct path for local tests sourcing local features

* bump version

* revise path resolution tests

* relative to --workspace-folder

* respect absolute paths (for now)

* take new in rebase

* need to revisit tar

* rebase and comment tests

* update test

* clean up featureHelpers.test.ts

* update tests

* tarball parsing for v2

* typo in file name

* update tests

* remove unuseful test

* update tests

* remove import
  • Loading branch information
joshspicer authored Aug 9, 2022
1 parent fb94533 commit cbdb8b3
Show file tree
Hide file tree
Showing 7 changed files with 384 additions and 284 deletions.
22 changes: 16 additions & 6 deletions src/spec-configuration/containerFeaturesConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,16 +546,26 @@ export async function processFeatureIdentifier(output: Log, env: NodeJS.ProcessE
// remote tar file
if (type === 'direct-tarball') {
output.write(`Remote tar file found.`);
let input = userFeature.id.replace(/\/+$/, '');
const featureIdDelimiter = input.lastIndexOf('#');
const id = input.substring(featureIdDelimiter + 1);
const tarballUri = new URL.URL(userFeature.id);

const fullPath = tarballUri.pathname;
const tarballName = fullPath.substring(fullPath.lastIndexOf('/') + 1);
output.write(`tarballName = ${tarballName}`, LogLevel.Trace);

const regex = new RegExp('devcontainer-feature-(.*).tgz');
const matches = regex.exec(tarballName);

if (!matches || matches.length !== 2) {
output.write(`Expected tarball name to follow 'devcontainer-feature-<feature-id>.tgz' format. Received '${tarballName}'`, LogLevel.Error);
return undefined;
}
const id = matches[1];

if (id === '' || !allowedFeatureIdRegex.test(id)) {
output.write(`Parse error. Specify a feature id with alphanumeric, dash, or underscore characters. Provided: ${id}.`, LogLevel.Error);
output.write(`Parse error. Specify a feature id with alphanumeric, dash, or underscore characters. Received ${id}.`, LogLevel.Error);
return undefined;
}

const tarballUri = new URL.URL(input.substring(0, featureIdDelimiter)).toString();
let feat: Feature = {
id: id,
name: userFeature.id,
Expand All @@ -566,7 +576,7 @@ export async function processFeatureIdentifier(output: Log, env: NodeJS.ProcessE
let newFeaturesSet: FeatureSet = {
sourceInformation: {
type: 'direct-tarball',
tarballUri: tarballUri
tarballUri: tarballUri.toString()
},
features: [feat],
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"image": "mcr.microsoft.com/vscode/devcontainers/typescript-node:16",
"features": {
"https://github.com/codspace/features/releases/download/tarball02/devcontainer-feature-docker-in-docker.tgz": {}
}
}
1 change: 0 additions & 1 deletion src/test/container-features/containerFeaturesOCI.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { createPlainLog, LogLevel, makeLog } from '../../spec-utils/log';
export const output = makeLog(createPlainLog(text => process.stdout.write(text), () => LogLevel.Trace));

describe('Test OCI Pull', () => {

it('Parse OCI identifier', async () => {
const feat = getFeatureRef(output, 'ghcr.io/codspace/features/ruby:1');
output.write(`feat: ${JSON.stringify(feat)}`);
Expand Down
19 changes: 18 additions & 1 deletion src/test/container-features/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ describe('Dev Container Features E2E (remote)', function () {
});
});


describe('v2 - Dockerfile feature Configs', () => {

describe(`dockerfile-with-v2-oci-features`, () => {
Expand All @@ -71,6 +70,24 @@ describe('Dev Container Features E2E (remote)', function () {
});
});
});

describe('v2 - Image property feature Configs', () => {

describe(`image-with-v2-tarball`, () => {
let containerId: string | null = null;
const testFolder = `${__dirname}/configs/image-with-v2-tarball`;
beforeEach(async () => containerId = (await devContainerUp(cli, testFolder, { 'logLevel': 'trace' })).containerId);
afterEach(async () => await devContainerDown({ containerId }));
it('should detect docker installed (--privileged flag implicitly passed)', async () => {
// NOTE: Doing a docker ps will ensure that the --privileged flag was set by the feature
const res = await shellExec(`${cli} exec --workspace-folder ${testFolder} docker ps`);
const response = JSON.parse(res.stdout);
console.log(res.stderr);
assert.equal(response.outcome, 'success');
assert.match(res.stderr, /CONTAINER ID/);
});
});
});
});


Expand Down
Loading

0 comments on commit cbdb8b3

Please sign in to comment.