1
0
mirror of https://github.com/google/nomulus synced 2026-04-22 17:20:44 +00:00

Make a best effort attempt to support multiple CPU architectures (#2672)

I obtained access to an IBM s390x VM so I thought I'd see how multi-arch
Nomulus is.

Our main application is in Java so it is already multi-arch, but several
tests use docker images that are by default x64. Luckily postgres has an
s390x port, but selenium does not. So I had to disable Screenshot tests
when the arch is not amd64.
This commit is contained in:
Lai Jiang
2025-02-07 17:19:42 -05:00
committed by GitHub
parent 34103ec815
commit c918258fb1
19 changed files with 134 additions and 116 deletions

View File

@@ -105,7 +105,7 @@ public class GenerateSqlErDiagramCommand implements Command {
}
try (PostgreSQLContainer<?> postgresContainer =
new PostgreSQLContainer<>(NomulusPostgreSql.getDockerTag())) {
new PostgreSQLContainer<>(NomulusPostgreSql.getDockerImageName())) {
postgresContainer
.withDatabaseName(DB_NAME)
.withUsername(DB_USER)

View File

@@ -83,7 +83,7 @@ public class GenerateSqlSchemaCommand implements Command {
// Start the container and store the address information.
postgresContainer =
new PostgreSQLContainer<>(NomulusPostgreSql.getDockerTag())
new PostgreSQLContainer<>(NomulusPostgreSql.getDockerImageName())
.withDatabaseName(DB_NAME)
.withUsername(DB_USERNAME)
.withPassword(DB_PASSWORD);
@@ -93,20 +93,20 @@ public class GenerateSqlSchemaCommand implements Command {
} else if (databaseHost == null) {
System.err.println(
"""
You must specify either --start_postgresql to start a PostgreSQL database in a
docker instance, or specify --db_host (and, optionally, --db_port) to identify
the location of a running instance. To start a long-lived instance (suitable
for running this command multiple times) run this:
You must specify either --start_postgresql to start a PostgreSQL database in a
docker instance, or specify --db_host (and, optionally, --db_port) to identify
the location of a running instance. To start a long-lived instance (suitable
for running this command multiple times) run this:
docker run --rm --name some-postgres -e POSTGRES_PASSWORD=domain-registry \\
-d postgres:9.6.12
docker run --rm --name some-postgres -e POSTGRES_PASSWORD=domain-registry \\
-d postgres:9.6.12
Copy the container id output from the command, then run:
Copy the container id output from the command, then run:
docker inspect <container-id> | grep IPAddress
docker inspect <container-id> | grep IPAddress
To obtain the value for --db-host.
""");
To obtain the value for --db-host.
""");
// TODO(mmuller): need exit(1), see above.
return;
}
@@ -124,20 +124,20 @@ public class GenerateSqlSchemaCommand implements Command {
// existing data in the file.
String copyright =
"""
-- Copyright 2019 The Nomulus Authors. All Rights Reserved.
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
""";
-- Copyright 2019 The Nomulus Authors. All Rights Reserved.
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
""";
try {
Files.writeString(outputFile.toPath(), copyright);
} catch (IOException e) {

View File

@@ -68,7 +68,7 @@ public abstract class PostgresqlCommand implements Command {
// Start the container and store the address information.
postgresContainer =
new PostgreSQLContainer<>(NomulusPostgreSql.getDockerTag())
new PostgreSQLContainer<>(NomulusPostgreSql.getDockerImageName())
.withDatabaseName(DB_NAME)
.withUsername(DB_USERNAME)
.withPassword(DB_PASSWORD);
@@ -89,7 +89,7 @@ public abstract class PostgresqlCommand implements Command {
+ "for running this command multiple times) run this:\n\n"
+ " docker run --rm --name some-postgres -e POSTGRES_PASSWORD=domain-registry \\\n"
+ " -d "
+ NomulusPostgreSql.getDockerTag()
+ NomulusPostgreSql.getDockerImageName()
+ "\n\nCopy the container id output from the command, then run:\n\n"
+ " docker inspect <container-id> | grep IPAddress\n\n"
+ "To obtain the value for --db-host.\n");

View File

@@ -38,7 +38,7 @@ class HibernateSchemaExporterTest {
@Container
private static final PostgreSQLContainer database =
new PostgreSQLContainer(NomulusPostgreSql.getDockerTag());
new PostgreSQLContainer(NomulusPostgreSql.getDockerImageName());
private static HibernateSchemaExporter exporter;
@@ -61,12 +61,12 @@ class HibernateSchemaExporterTest {
.isEqualTo(
"""
create table "TestEntity" (
name text not null,
cu text,
primary key (name)
);
"""
create table "TestEntity" (
name text not null,
cu text,
primary key (name)
);
"""
.getBytes(StandardCharsets.UTF_8));
}

View File

@@ -42,7 +42,7 @@ class PersistenceModuleTest {
@Container
private final PostgreSQLContainer database =
new PostgreSQLContainer(NomulusPostgreSql.getDockerTag());
new PostgreSQLContainer(NomulusPostgreSql.getDockerImageName());
private EntityManagerFactory emf;

View File

@@ -140,7 +140,7 @@ public abstract class JpaTransactionManagerExtension
private static JdbcDatabaseContainer<?> create() {
PostgreSQLContainer<?> container =
new PostgreSQLContainer<>(NomulusPostgreSql.getDockerTag())
new PostgreSQLContainer<>(NomulusPostgreSql.getDockerImageName())
.withDatabaseName(POSTGRES_DB_NAME);
container.start();
return container;

View File

@@ -39,7 +39,7 @@ class GenerateSqlSchemaCommandTest extends CommandTestCase<GenerateSqlSchemaComm
@Container
private static final PostgreSQLContainer<?> postgres =
new PostgreSQLContainer<>(NomulusPostgreSql.getDockerTag())
new PostgreSQLContainer<>(NomulusPostgreSql.getDockerImageName())
.withDatabaseName("postgres")
.withUsername("postgres")
.withPassword("domain-registry");

View File

@@ -23,6 +23,7 @@ import google.registry.model.console.RegistrarRole;
import google.registry.server.RegistryTestServer;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junitpioneer.jupiter.RetryingTest;
import org.openqa.selenium.By;
@@ -47,6 +48,8 @@ import org.openqa.selenium.WebElement;
* the color fading over a short period of time. We must wait for the highlighting to fade to get
* cnosistent images to avoid spurious failures.
*/
// The Selenium image only supports amd64 architecture.
@EnabledIfSystemProperty(named = "os.arch", matches = "amd64")
public class ConsoleScreenshotTest extends WebDriverTestCase {
@RegisterExtension

View File

@@ -37,7 +37,11 @@ class DockerWebDriverExtension implements BeforeAllCallback, AfterAllCallback {
// This port number is defined in this Dockerfile:
// https://github.com/SeleniumHQ/docker-selenium/blob/master/StandaloneChrome/Dockerfile#L21
private static final int CHROME_DRIVER_SERVICE_PORT = 4444;
private static final URL WEB_DRIVER_URL = getWebDriverUrl();
// The selenium image only supports amd64 architecture. We disable the call to getWebDriverUrl()
// here as the extension is instantiated in the test class before the test runner had a chance to
// disable the tests.
private static final URL WEB_DRIVER_URL =
System.getProperty("os.arch").equals("amd64") ? getWebDriverUrl() : null;
private WebDriver webDriver;
private static URL getWebDriverUrl() {