Skip to content

Commit 97db436

Browse files
committed
add test case for windows
1 parent 907c19e commit 97db436

7 files changed

Lines changed: 93 additions & 0 deletions

File tree

.github/workflows/test-windows.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ jobs:
4141
# "src/test/container-templates/containerTemplatesOCI.test.ts",
4242
# "src/test/container-templates/templatesCLICommands.test.ts",
4343
# "src/test/dockerComposeUtils.test.ts",
44+
"src/test/dockerfilePreprocessorWindows.test.ts",
4445
# "src/test/dockerfileUtils.test.ts",
4546
# "src/test/dockerUtils.test.ts",
4647
# "src/test/imageMetadata.test.ts",
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"build": {
3+
"dockerfile": "Dockerfile.in"
4+
},
5+
"dockerfilePreprocessor": {
6+
"tool": "clang",
7+
"outputMode": "single-file",
8+
"args": [
9+
"-E",
10+
"-P",
11+
"-x",
12+
"c",
13+
"-"
14+
]
15+
},
16+
"features": {
17+
"ghcr.io/devcontainers/features/github-cli:1": {
18+
"version": "latest"
19+
}
20+
}
21+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#define BASE_IMAGE ubuntu:20.04
2+
#define INSTALL_NODE
3+
#define INSTALL_PYTHON
4+
5+
FROM BASE_IMAGE
6+
7+
#ifdef INSTALL_NODE
8+
RUN apt-get update && apt-get install -y nodejs
9+
#endif
10+
11+
#ifdef INSTALL_PYTHON
12+
RUN apt-get update && apt-get install -y python3
13+
#endif
14+
15+
#include "common.Dockerfile"
16+
#include "tools.Dockerfile"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
RUN apt-get update && apt-get install -y curl wget
2+
3+
ENV APP_ENV=development
4+
ENV APP_DEBUG=true
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
echo "hello! clang test"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
RUN apt-get update && apt-get install -y vim
2+
COPY ./test.sh /usr/local/bin/test.sh
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
*--------------------------------------------------------------------------------------------*/
4+
5+
import * as fs from 'fs/promises';
6+
import * as path from 'path';
7+
8+
import { devContainerDown, devContainerUp, shellExec } from './testUtils';
9+
10+
const pkg = require('../../package.json');
11+
12+
(process.platform === 'win32' ? describe : describe.skip)('dockerfilePreprocessor integration (Windows)', function () {
13+
this.timeout('240s');
14+
15+
const tmp = path.relative(process.cwd(), path.join(__dirname, 'tmp'));
16+
const cli = `npx --prefix ${tmp} devcontainer`;
17+
const generatedArtifacts = ['Dockerfile', '.devcontainer-lock.json', '.devcontainer-preprocessed'];
18+
let clangAvailable = false;
19+
20+
const cleanupGeneratedArtifacts = async (testFolder: string) => {
21+
await Promise.all(generatedArtifacts.map(relative => fs.rm(path.join(testFolder, relative), { recursive: true, force: true })));
22+
};
23+
24+
before('Install', async () => {
25+
await fs.rm(path.join(__dirname, 'tmp', 'node_modules'), { recursive: true, force: true });
26+
await fs.mkdir(path.join(__dirname, 'tmp'), { recursive: true });
27+
await shellExec(`npm --prefix ${tmp} install devcontainers-cli-${pkg.version}.tgz`);
28+
const clangCheck = await shellExec('where clang', undefined, true, true);
29+
clangAvailable = !clangCheck.error && Boolean(clangCheck.stdout.trim());
30+
});
31+
32+
it('should preprocess a Dockerfile.in during up clang on Windows', async function () {
33+
if (!clangAvailable) {
34+
this.skip();
35+
}
36+
const testFolder = `${__dirname}/configs/dockerfile-clang-preprocessor`;
37+
await cleanupGeneratedArtifacts(testFolder);
38+
let containerId: string | undefined;
39+
try {
40+
containerId = (await devContainerUp(cli, testFolder)).containerId;
41+
await shellExec(`${cli} exec --workspace-folder ${testFolder} sh -lc 'command -v nodejs && command -v python3 && command -v curl && command -v wget && command -v vim && test -f /usr/local/bin/test.sh'`);
42+
} finally {
43+
await devContainerDown({ containerId, doNotThrow: true });
44+
await cleanupGeneratedArtifacts(testFolder);
45+
}
46+
});
47+
});

0 commit comments

Comments
 (0)