Skip to content
Closed
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
7 changes: 4 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { CosmosClient, PartitionKeyKind } from "@azure/cosmos";
import * as https from "node:https";
import { expect } from "vitest";
import { AzureCosmosDbEmulatorContainer } from "./azure-cosmosdb-emulator-container";

const IMAGE = "mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:vnext-EN20250228";
Expand Down
1 change: 0 additions & 1 deletion packages/modules/hivemq/src/hivemq-container.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import mqtt from "mqtt";
import { expect } from "vitest";
import { HiveMQContainer } from "./hivemq-container";

const IMAGE = "hivemq/hivemq-ce:2023.5";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM node:10-alpine

MAINTAINER Cristian Greco

EXPOSE 8080

RUN --mount=type=tmpfs,target=/buildkit-test \
echo "BuildKit tmpfs mount is working" > /buildkit-test/success.txt && \
cat /buildkit-test/success.txt

RUN apk add --no-cache curl dumb-init libcap openssl

RUN openssl req -x509 -nodes -days 36500 \
-subj "/C=CA/ST=QC/O=Company Inc/CN=localhost" \
-newkey rsa:2048 -keyout /etc/ssl/private/cert.key \
-out /etc/ssl/certs/cert.crt \
&& chmod 666 /etc/ssl/private/cert.key

RUN npm init -y && \
npm install [email protected]

COPY index.js .

ENTRYPOINT ["/usr/bin/dumb-init", "--"]
CMD ["node", "index.js"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:
container:
build:
context: .
dockerfile: Dockerfile
ports:
- 8080
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const fs = require("fs");
const http = require("http");
const https = require("https");
const express = require("express");

const app = express();

app.get("/hello-world", (req, res) => {
res.status(200).send("hello-world");
});

app.get("/hello-world-delay", (req, res) => {
setTimeout(() => {
res.status(200).send("hello-world");
}, 3000);
});

app.post("/hello-world-post", (req, res) => {
res.status(200).send("hello-world");
});

app.get("/env", (req, res) => {
res.status(200).json(process.env);
});

app.get("/cmd", (req, res) => {
res.status(200).json(process.argv);
});

app.get("/auth", (req, res) => {
const auth = req.headers.authorization;
const [, base64Encoded] = auth.split(" ");
const credentials = Buffer.from(base64Encoded, "base64").toString("ascii");
const [username, password] = credentials.split(":");
if (username === "user" && password === "pass") {
res.status(200).end();
} else {
res.status(401).end();
}
});

app.get("/header-or-400/:headerName", (req, res) => {
if (req.headers[req.params["headerName"]] !== undefined) {
res.status(200).end();
} else {
res.status(400).end();
}
});

const PORT = 8080;
const TLS_PORT = 8443;

http.createServer(app).listen(PORT, () => console.log(`Listening on port ${PORT}`));
https
.createServer(
{
key: fs.readFileSync("/etc/ssl/private/cert.key", "utf8"),
cert: fs.readFileSync("/etc/ssl/certs/cert.crt", "utf8"),
},
app
)
.listen(TLS_PORT, () => console.log(`Listening on secure port ${TLS_PORT}`));
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM node:10-alpine

MAINTAINER Cristian Greco

EXPOSE 8080

RUN --mount=type=tmpfs,target=/buildkit-test \
echo "BuildKit tmpfs mount is working" > /buildkit-test/success.txt && \
cat /buildkit-test/success.txt

RUN apk add --no-cache curl dumb-init libcap openssl

RUN openssl req -x509 -nodes -days 36500 \
-subj "/C=CA/ST=QC/O=Company Inc/CN=localhost" \
-newkey rsa:2048 -keyout /etc/ssl/private/cert.key \
-out /etc/ssl/certs/cert.crt \
&& chmod 666 /etc/ssl/private/cert.key

RUN npm init -y && \
npm install [email protected]

COPY index.js .

ENTRYPOINT ["/usr/bin/dumb-init", "--"]
CMD ["node", "index.js"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const fs = require("fs");
const http = require("http");
const https = require("https");
const express = require("express");

const app = express();

app.get("/hello-world", (req, res) => {
res.status(200).send("hello-world");
});

app.get("/hello-world-delay", (req, res) => {
setTimeout(() => {
res.status(200).send("hello-world");
}, 3000);
});

app.post("/hello-world-post", (req, res) => {
res.status(200).send("hello-world");
});

app.get("/env", (req, res) => {
res.status(200).json(process.env);
});

app.get("/cmd", (req, res) => {
res.status(200).json(process.argv);
});

app.get("/auth", (req, res) => {
const auth = req.headers.authorization;
const [, base64Encoded] = auth.split(" ");
const credentials = Buffer.from(base64Encoded, "base64").toString("ascii");
const [username, password] = credentials.split(":");
if (username === "user" && password === "pass") {
res.status(200).end();
} else {
res.status(401).end();
}
});

app.get("/header-or-400/:headerName", (req, res) => {
if (req.headers[req.params["headerName"]] !== undefined) {
res.status(200).end();
} else {
res.status(400).end();
}
});

const PORT = 8080;
const TLS_PORT = 8443;

http.createServer(app).listen(PORT, () => console.log(`Listening on port ${PORT}`));
https
.createServer(
{
key: fs.readFileSync("/etc/ssl/private/cert.key", "utf8"),
cert: fs.readFileSync("/etc/ssl/certs/cert.crt", "utf8"),
},
app
)
.listen(TLS_PORT, () => console.log(`Listening on secure port ${TLS_PORT}`));
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import path from "path";
import { RandomUuid } from "../common";
import { randomUuid } from "../common/uuid";
import { PullPolicy } from "../utils/pull-policy";
import {
checkEnvironmentContainerIsHealthy,
composeContainerName,
getDockerEventStream,
getRunningContainerNames,
getVolumeNames,
waitForDockerEvent,
} from "../utils/test-helper";
import { Wait } from "../wait-strategies/wait";
import { DockerComposeEnvironment } from "./docker-compose-environment";
Expand Down Expand Up @@ -43,32 +40,14 @@ describe("DockerComposeEnvironment", { timeout: 180_000 }, () => {
await startedEnvironment.down();
});

it("should use pull policy", async () => {
const env = new DockerComposeEnvironment(fixtures, "docker-compose-with-many-services.yml");
it("should work with buildkit features", async () => {
const buildkitFixtures = path.resolve(fixtures, "docker-compose-with-buildkit");

const startedEnv1 = await env.up();
const dockerEventStream = await getDockerEventStream();
const dockerPullEventPromise = waitForDockerEvent(dockerEventStream, "pull");
const startedEnv2 = await env.withPullPolicy(PullPolicy.alwaysPull()).up();
await dockerPullEventPromise;
const startedEnvironment = await new DockerComposeEnvironment(buildkitFixtures, "docker-compose.yml").up();

dockerEventStream.destroy();
await startedEnv1.stop();
await startedEnv2.stop();
});

it("should use pull policy for specific service", async () => {
const env = new DockerComposeEnvironment(fixtures, "docker-compose-with-many-services.yml");

const startedEnv1 = await env.up(["service_2"]);
const dockerEventStream = await getDockerEventStream();
const dockerPullEventPromise = waitForDockerEvent(dockerEventStream, "pull");
const startedEnv2 = await env.withPullPolicy(PullPolicy.alwaysPull()).up(["service_2"]);
await dockerPullEventPromise;
await checkEnvironmentContainerIsHealthy(startedEnvironment, await composeContainerName("container"));

dockerEventStream.destroy();
await startedEnv1.stop();
await startedEnv2.stop();
await startedEnvironment.down();
});

it("should start environment with multiple compose files", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export class GenericContainerBuilder {
labels,
target: this.target,
platform: this.platform,
version: "2",
};

if (this.pullPolicy.shouldPull()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { expect } from "vitest";
import { RandomUuid } from "../common";
import { getContainerRuntimeClient } from "../container-runtime";
import { getReaper } from "../reaper/reaper";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import path from "path";
import { RandomUuid } from "../common";
import { getContainerRuntimeClient, ImageName } from "../container-runtime";
import { getContainerRuntimeClient } from "../container-runtime";
import { getReaper } from "../reaper/reaper";
import { LABEL_TESTCONTAINERS_SESSION_ID } from "../utils/labels";
import { PullPolicy } from "../utils/pull-policy";
import {
checkContainerIsHealthy,
deleteImageByName,
getDockerEventStream,
getImageLabelsByName,
waitForDockerEvent,
} from "../utils/test-helper";
import { checkContainerIsHealthy, deleteImageByName, getImageLabelsByName } from "../utils/test-helper";
import { Wait } from "../wait-strategies/wait";
import { GenericContainer } from "./generic-container";

Expand All @@ -28,6 +21,15 @@ describe("GenericContainer Dockerfile", { timeout: 180_000 }, () => {
await startedContainer.stop();
});

it("should build and start with buildkit", async () => {
const context = path.resolve(fixtures, "docker-with-buildkit");
const container = await GenericContainer.fromDockerfile(context).build();
const startedContainer = await container.withExposedPorts(8080).start();

await checkContainerIsHealthy(startedContainer);

await startedContainer.stop();
});
it("should have a session ID label to be cleaned up by the Reaper", async () => {
const context = path.resolve(fixtures, "docker");
const imageName = `${uuidGen.nextUuid()}:${uuidGen.nextUuid()}`;
Expand All @@ -54,41 +56,6 @@ describe("GenericContainer Dockerfile", { timeout: 180_000 }, () => {
await deleteImageByName(imageName);
});

// https://github.com/containers/podman/issues/17779
if (!process.env.CI_PODMAN) {
it("should use pull policy", async () => {
const dockerfile = path.resolve(fixtures, "docker");
const containerSpec = GenericContainer.fromDockerfile(dockerfile).withPullPolicy(PullPolicy.alwaysPull());

await containerSpec.build();
const dockerEventStream = await getDockerEventStream();
const dockerPullEventPromise = waitForDockerEvent(dockerEventStream, "pull");
await containerSpec.build();
await dockerPullEventPromise;

dockerEventStream.destroy();
});

it("should not pull existing image without pull policy", async () => {
const client = await getContainerRuntimeClient();
await client.image.pull(new ImageName("docker.io", "node", "10-alpine"));

const dockerfile = path.resolve(fixtures, "docker");
const containerSpec = GenericContainer.fromDockerfile(dockerfile);

await containerSpec.build();
const dockerEventStream = await getDockerEventStream();
const dockerPullEventPromise = waitForDockerEvent(dockerEventStream, "pull");
let hasResolved = false;
dockerPullEventPromise.then(() => (hasResolved = true));
await containerSpec.build();

expect(hasResolved).toBeFalsy();

dockerEventStream.destroy();
});
}

it("should build and start with custom file name", async () => {
const context = path.resolve(fixtures, "docker-with-custom-filename");
const container = await GenericContainer.fromDockerfile(context, "Dockerfile-A").build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ import path from "path";
import { RandomUuid } from "../common";
import { getContainerRuntimeClient } from "../container-runtime";
import { PullPolicy } from "../utils/pull-policy";
import {
checkContainerIsHealthy,
getDockerEventStream,
getRunningContainerNames,
waitForDockerEvent,
} from "../utils/test-helper";
import { checkContainerIsHealthy, getRunningContainerNames } from "../utils/test-helper";
import { GenericContainer } from "./generic-container";

describe("GenericContainer", { timeout: 180_000 }, () => {
Expand Down Expand Up @@ -310,20 +305,6 @@ describe("GenericContainer", { timeout: 180_000 }, () => {
await container.stop();
});

it("should use pull policy", async () => {
const container = new GenericContainer("cristianrgreco/testcontainer:1.1.14").withExposedPorts(8080);

const startedContainer1 = await container.start();
const dockerEventStream = await getDockerEventStream();
const dockerPullEventPromise = waitForDockerEvent(dockerEventStream, "pull");
const startedContainer2 = await container.withPullPolicy(PullPolicy.alwaysPull()).start();
await dockerPullEventPromise;

dockerEventStream.destroy();
await startedContainer1.stop();
await startedContainer2.stop();
});

it("should set the IPC mode", async () => {
const container = await new GenericContainer("cristianrgreco/testcontainer:1.1.14")
.withIpcMode("host")
Expand Down Expand Up @@ -488,7 +469,6 @@ describe("GenericContainer", { timeout: 180_000 }, () => {
expect(output).not.toContain("example5.txt");
expect(output).not.toContain("example6.txt");
expect(output).not.toContain("example7.txt");
expect(output).not.toContain("Dockerfile");

await startedContainer.stop();
});
Expand Down
Loading