Skip to content

Commit fab937b

Browse files
authored
fix: connect service containers to local registry network (#1847)
1 parent f67605f commit fab937b

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

src/job.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,6 +1582,11 @@ If you know what you're doing and would like to suppress this warning, use one o
15821582
dockerCmd += `--add-host=${extraHost} `;
15831583
}
15841584

1585+
if (this.argv.registry) {
1586+
dockerCmd += `--volume ${Utils.gclRegistryPrefix}.certs:/etc/containers/certs.d:ro `;
1587+
dockerCmd += `--volume ${Utils.gclRegistryPrefix}.certs:/etc/docker/certs.d:ro `;
1588+
}
1589+
15851590
if (this.argv.caFile) {
15861591
const caFilePath = path.isAbsolute(this.argv.caFile) ? this.argv.caFile : path.resolve(this.argv.cwd, this.argv.caFile);
15871592
if (await fs.pathExists(caFilePath)) {
@@ -1638,6 +1643,10 @@ If you know what you're doing and would like to suppress this warning, use one o
16381643
await Utils.spawn([this.argv.containerExecutable, "network", "connect", network, `${containerId}`]);
16391644
}
16401645

1646+
if (this.argv.registry) {
1647+
await Utils.spawn([this.argv.containerExecutable, "network", "connect", `${Utils.gclRegistryPrefix}.net`, `${containerId}`]);
1648+
}
1649+
16411650
await Utils.spawn([this.argv.containerExecutable, "start", `${containerId}`]);
16421651

16431652
const endTime = process.hrtime(time);

tests/test-cases/local-registry/.gitlab-ci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,10 @@ registry-login-oci:
1515
image: quay.io/podman/stable
1616
script:
1717
- echo "$CI_REGISTRY_PASSWORD" | podman login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
18+
19+
registry-login-dind:
20+
image: docker:cli
21+
services:
22+
- docker:dind
23+
script:
24+
- echo "$CI_REGISTRY_PASSWORD" | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY

tests/test-cases/local-registry/integration.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,16 @@ test("local-registry login <oci>", async () => {
4444

4545
expect(writeStreams.stdoutLines).toEqual(expect.arrayContaining(["registry-login-oci > Login Succeeded!"]));
4646
});
47+
48+
test("local-registry login <dind>", async () => {
49+
const writeStreams = new WriteStreamsMock();
50+
await handler({
51+
cwd: "tests/test-cases/local-registry",
52+
job: ["registry-login-dind"],
53+
registry: true,
54+
privileged: true,
55+
noColor: true,
56+
}, writeStreams);
57+
58+
expect(writeStreams.stdoutLines).toEqual(expect.arrayContaining(["registry-login-dind > Login Succeeded"]));
59+
});

0 commit comments

Comments
 (0)