Skip to content

Commit 788a191

Browse files
authored
Merge pull request #80 from firecow/fix-entrypoint-pwd-and-output
Fixed entrypoint pwd, and made sure entrypoint output actually gets caught
2 parents 1e0bb7a + 5ff94dc commit 788a191

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

src/job.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ export class Job {
301301
process.stdout.write(`${this.getJobNameString()} ${magentaBright('pulled')} in ${magenta(prettyHrtime(endTime))}\n`);
302302

303303
let dockerCmd = ``;
304-
dockerCmd += `docker run -u 0:0 -d -i -w //builds/ ${this.image} `;
304+
dockerCmd += `docker create -u 0:0 -i ${this.image} `;
305305
dockerCmd += `sh -c "\n`
306306
dockerCmd += `if [ -x /usr/local/bin/bash ]; then\n`
307307
dockerCmd += `\texec /usr/local/bin/bash \n`;
@@ -331,7 +331,7 @@ export class Job {
331331
process.stdout.write(`${this.getJobNameString()} ${magentaBright('copied')} in ${magenta(prettyHrtime(endTime))}\n`);
332332
}
333333

334-
const cp = childProcess.spawn(this.containerId ? `docker attach ${this.containerId}` : `bash -e`, {
334+
const cp = childProcess.spawn(this.containerId ? `docker start --attach -i ${this.containerId}` : `bash -e`, {
335335
shell: 'bash',
336336
stdio: ['pipe', 'pipe', 'pipe'],
337337
cwd: this.cwd,
@@ -340,6 +340,7 @@ export class Job {
340340
cp.stdin.write(`set -eo pipefail\n`);
341341

342342
if (this.image) {
343+
cp.stdin.write(`cd /builds/\n`);
343344
cp.stdin.write(`chown root:root -R .\n`);
344345
cp.stdin.write(`chmod a+w -R .\n`);
345346
}

tests/cases.test.ts

+14
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,20 @@ test('image <test-job>', async () => {
100100
expect(mockProcessStdout).toHaveBeenCalledWith("Test something\n");
101101
});
102102

103+
test('image <test-entrypoint>', async () => {
104+
await defaultCmd.handler({
105+
cwd: 'tests/test-cases/image',
106+
job: 'test-entrypoint'
107+
});
108+
109+
expect(mockProcessStdout).toHaveBeenCalledWith("/\n");
110+
expect(mockProcessStdout).toHaveBeenCalledWith("Hello from 'firecow/gitlab-ci-local-test-image' image entrypoint\n");
111+
expect(mockProcessStdout).toHaveBeenCalledWith("/builds\n");
112+
expect(mockProcessStdout).toHaveBeenCalledWith("Test Entrypoint\n");
113+
expect(mockProcessStdout).toHaveBeenCalledWith("I'm a test file\n");
114+
115+
});
116+
103117
test('no-script <test-job>', async () => {
104118
try {
105119
await defaultCmd.handler({

tests/test-cases/image/.gitlab-ci.yml

+7
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,10 @@ test-job:
55
image: ${PHP_IMAGE_URL}
66
script:
77
- echo "Test something"
8+
9+
test-entrypoint:
10+
image: firecow/gitlab-ci-local-test-image
11+
script:
12+
- pwd
13+
- echo "Test Entrypoint"
14+
- cat test-file.txt

tests/test-cases/image/test-file.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
I'm a test file

0 commit comments

Comments
 (0)