Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --extra-host arguments to services #1086

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions src/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,10 @@ export class Job {
dockerCmd += `--volume ${volume} `;
}

for (const extraHost of this.argv.extraHost) {
dockerCmd += `--add-host=${extraHost} `;
}

const serviceAlias = service.alias;
const serviceName = service.name;
const serviceNameWithoutVersion = serviceName.replace(/(.*)(:.*)/, "$1");
Expand Down
9 changes: 9 additions & 0 deletions tests/test-cases/extra-host/.gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,12 @@ test-job:
image: docker.io/curlimages/curl:7.69.1
script:
- curl -I http://fake-google.com

service-job:
image: docker.io/curlimages/curl:7.69.1
services:
- name: docker.io/alpine:latest
entrypoint: ["/bin/sh", "-c"]
command: ["getent hosts fake-google.com"]
script:
- "true"
18 changes: 17 additions & 1 deletion tests/test-cases/extra-host/integration.extra-host.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {handler} from "../../../src/handler";
import chalk from "chalk";
import {initSpawnSpy} from "../../mocks/utils.mock";
import {WhenStatics} from "../../mocks/when-statics";
import fs from "fs-extra";

beforeAll(() => {
initSpawnSpy(WhenStatics.all);
Expand All @@ -17,7 +18,22 @@ test("add-host <test-job>", async () => {
}, writeStreams);

const expected = [
chalk`{blueBright test-job} {greenBright >} HTTP/1.1 404 Not Found`,
chalk`{blueBright test-job } {greenBright >} HTTP/1.1 404 Not Found`,
];
expect(writeStreams.stdoutLines).toEqual(expect.arrayContaining(expected));
});

test("add-host <service-job>", async () => {
await fs.promises.rm("tests/test-cases/extra-host/.gitlab-ci-local/services-output/service-job/docker.io/alpine:latest-0.log", {force: true});

const writeStreams = new WriteStreamsMock();
await handler({
cwd: "tests/test-cases/extra-host",
job: ["service-job"],
extraHost: ["fake-google.com:142.250.185.206"],
}, writeStreams);

expect(writeStreams.stderrLines.length).toEqual(2);
expect(await fs.pathExists("tests/test-cases/extra-host/.gitlab-ci-local/services-output/service-job/docker.io/alpine:latest-0.log")).toEqual(true);
expect(await fs.readFile("tests/test-cases/extra-host/.gitlab-ci-local/services-output/service-job/docker.io/alpine:latest-0.log", "utf-8")).toMatch(/142.250.185.206/);
});
Loading