Improvements around docker in Playwright (#12261)
* Extract Postgres Docker to its own class Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Don't specify docker `--rm` in CI as it makes debugging harder Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Improve docker commands and introspection Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Remove `HOST_DOCKER_INTERNAL` magic in favour of `host.containers.internal` Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Always pipe Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Re-add pipe flag to silence pg_isready and podman checks Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
dd5b7417be
commit
a9add4504f
8 changed files with 152 additions and 135 deletions
|
@ -57,20 +57,9 @@ async function cfgDirFromTemplate(opts: StartHomeserverOpts): Promise<Omit<Homes
|
|||
if (opts.oAuthServerPort) {
|
||||
hsYaml = hsYaml.replace(/{{OAUTH_SERVER_PORT}}/g, opts.oAuthServerPort.toString());
|
||||
}
|
||||
hsYaml = hsYaml.replace(/{{HOST_DOCKER_INTERNAL}}/g, await Docker.hostnameOfHost());
|
||||
if (opts.variables) {
|
||||
let fetchedHostContainer: Awaited<ReturnType<typeof Docker.hostnameOfHost>> | null = null;
|
||||
for (const key in opts.variables) {
|
||||
let value = String(opts.variables[key]);
|
||||
|
||||
if (value === "{{HOST_DOCKER_INTERNAL}}") {
|
||||
if (!fetchedHostContainer) {
|
||||
fetchedHostContainer = await Docker.hostnameOfHost();
|
||||
}
|
||||
value = fetchedHostContainer;
|
||||
}
|
||||
|
||||
hsYaml = hsYaml.replace(new RegExp("%" + key + "%", "g"), value);
|
||||
hsYaml = hsYaml.replace(new RegExp("%" + key + "%", "g"), String(opts.variables[key]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,26 +95,13 @@ export class Synapse implements Homeserver, HomeserverInstance {
|
|||
* Start a synapse instance: the template must be the name of
|
||||
* one of the templates in the playwright/plugins/synapsedocker/templates
|
||||
* directory.
|
||||
*
|
||||
* Any value in `opts.variables` that is set to `{{HOST_DOCKER_INTERNAL}}'
|
||||
* will be replaced with 'host.docker.internal' (if we are on Docker) or
|
||||
* 'host.containers.internal' if we are on Podman.
|
||||
*/
|
||||
public async start(opts: StartHomeserverOpts): Promise<HomeserverInstance> {
|
||||
if (this.config) await this.stop();
|
||||
|
||||
const synCfg = await cfgDirFromTemplate(opts);
|
||||
console.log(`Starting synapse with config dir ${synCfg.configDir}...`);
|
||||
const dockerSynapseParams = ["--rm", "-v", `${synCfg.configDir}:/data`, "-p", `${synCfg.port}:8008/tcp`];
|
||||
if (await Docker.isPodman()) {
|
||||
// Make host.containers.internal work to allow Synapse to talk to the test OIDC server.
|
||||
dockerSynapseParams.push("--network");
|
||||
dockerSynapseParams.push("slirp4netns:allow_host_loopback=true");
|
||||
} else {
|
||||
// Make host.docker.internal work to allow Synapse to talk to the test OIDC server.
|
||||
dockerSynapseParams.push("--add-host");
|
||||
dockerSynapseParams.push("host.docker.internal:host-gateway");
|
||||
}
|
||||
const dockerSynapseParams = ["-v", `${synCfg.configDir}:/data`, "-p", `${synCfg.port}:8008/tcp`];
|
||||
const synapseId = await this.docker.run({
|
||||
image: "matrixdotorg/synapse:develop",
|
||||
containerName: `react-sdk-playwright-synapse`,
|
||||
|
|
|
@ -81,10 +81,8 @@ oidc_providers:
|
|||
issuer: "http://localhost:{{OAUTH_SERVER_PORT}}/oauth"
|
||||
authorization_endpoint: "http://localhost:{{OAUTH_SERVER_PORT}}/oauth/auth.html"
|
||||
# the token endpoint receives requests from synapse, rather than the webapp, so needs to escape the docker container.
|
||||
# Hence, HOST_DOCKER_INTERNAL rather than localhost. This is set to
|
||||
# host.docker.internal on Docker and host.containers.internal on Podman.
|
||||
token_endpoint: "http://{{HOST_DOCKER_INTERNAL}}:{{OAUTH_SERVER_PORT}}/oauth/token"
|
||||
userinfo_endpoint: "http://{{HOST_DOCKER_INTERNAL}}:{{OAUTH_SERVER_PORT}}/oauth/userinfo"
|
||||
token_endpoint: "http://host.containers.internal:{{OAUTH_SERVER_PORT}}/oauth/token"
|
||||
userinfo_endpoint: "http://host.containers.internal:{{OAUTH_SERVER_PORT}}/oauth/userinfo"
|
||||
client_id: "synapse"
|
||||
discover: false
|
||||
scopes: ["profile"]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue