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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update container images (database) #30067

Open
wants to merge 6 commits into
base: integration
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*******************************************************************************
* Copyright (c) 2021, 2022 IBM Corporation and others.
* Copyright (c) 2021, 2024 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-2.0/
*
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
Expand Down Expand Up @@ -70,7 +70,7 @@ public class ContainersTest extends FATServletClient {
* have been used here. This is just an example of how to setup a GenericContainer.
*/
@ClassRule
public static GenericContainer<?> container = new GenericContainer<>("postgres:14.1-alpine")
public static GenericContainer<?> container = new GenericContainer<>("postgres:17.0-alpine")
.withExposedPorts(POSTGRE_PORT)
.withEnv("POSTGRES_DB", POSTGRES_DB)
.withEnv("POSTGRES_USER", POSTGRES_USER)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*******************************************************************************
* Copyright (c) 2021 IBM Corporation and others.
* Copyright (c) 2021, 2024 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-2.0/
*
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
Expand Down Expand Up @@ -51,6 +51,6 @@ public class FATSuite extends TestContainerSuite {
* In this example suite I am going to use a different container for each example.
*/
@ClassRule
public static PostgreSQLContainer<?> container = new PostgreSQLContainer<>("postgres:14.1-alpine");
public static PostgreSQLContainer<?> container = new PostgreSQLContainer<>("postgres:17.0-alpine");

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021, 2022 IBM Corporation and others.
* Copyright (c) 2021, 2024 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -64,18 +64,18 @@ public class ProgrammaticImageTest {
*
* NOTE: building from a Dockerfile should be avoided at all costs.
*
* Here we are pulling from a base image postgres:14.1-alpine
* Here we are pulling from a base image postgres:17.0-alpine
*
* However, we use special processing for the image name to ensure that when testing locally we pull
* from DockerHub, and when testing against a remote docker image we use a subsituted image name to pull
* from artifactory.
*
* Example:
* ImageNameSubstitutor.instance().apply(DockerImageName.parse("postgres:14.1-alpine")).asCanonicalNameString()
* ImageNameSubstitutor.instance().apply(DockerImageName.parse("postgres:17.0-alpine")).asCanonicalNameString()
*
* When testing locally a DefaultImageNameSubstitutor will be used and postgres:14.1-alpine will be returned as normal.
* When testing locally a DefaultImageNameSubstitutor will be used and postgres:17.0-alpine will be returned as normal.
* When testing on a remote docker host, our internal ArtifactoryImageNameSubstitutor will be used and
* [ARTIFACTORY_REGISTRY]/wasliberty-docker-remote/postgres:14.1-alpine will be returned
* [ARTIFACTORY_REGISTRY]/wasliberty-docker-remote/postgres:17.0-alpine will be returned
*
* </pre>
*
Expand All @@ -86,20 +86,20 @@ public class ProgrammaticImageTest {
public static GenericContainer<?> container = new GenericContainer<>(//
new ImageFromDockerfile().withDockerfileFromBuilder(builder -> builder.from(//
ImageNameSubstitutor.instance()
.apply(DockerImageName.parse("postgres:14.1-alpine"))
.apply(DockerImageName.parse("postgres:17.0-alpine"))
.asCanonicalNameString()) //
.copy("/docker-entrypoint-initdb.d/initDB.sql", "/docker-entrypoint-initdb.d/initDB.sql")
.build())
.withFileFromFile("/docker-entrypoint-initdb.d/initDB.sql", new File("lib/LibertyFATTestFiles/postgres/scripts/initDB.sql"), 644))
.withExposedPorts(POSTGRE_PORT)
.withEnv("POSTGRES_DB", POSTGRES_DB)
.withEnv("POSTGRES_USER", POSTGRES_USER)
.withEnv("POSTGRES_PASSWORD", POSTGRES_PASSWORD)
.withLogConsumer(new SimpleLogConsumer(ContainersTest.class, "postgres"))
.waitingFor(new LogMessageWaitStrategy()
.withRegEx(".*database system is ready to accept connections.*\\s")
.withTimes(2)
.withStartupTimeout(Duration.ofSeconds(60)));
.withExposedPorts(POSTGRE_PORT)
.withEnv("POSTGRES_DB", POSTGRES_DB)
.withEnv("POSTGRES_USER", POSTGRES_USER)
.withEnv("POSTGRES_PASSWORD", POSTGRES_PASSWORD)
.withLogConsumer(new SimpleLogConsumer(ContainersTest.class, "postgres"))
.waitingFor(new LogMessageWaitStrategy()
.withRegEx(".*database system is ready to accept connections.*\\s")
.withTimes(2)
.withStartupTimeout(Duration.ofSeconds(60)));

@BeforeClass
public static void setUp() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# TODO update to 17.0-alpine

FROM postgres:14.1-alpine

COPY scripts/initDB.sql /docker-entrypoint-initdb.d/initDB.sql
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*******************************************************************************
* Copyright (c) 2017, 2021 IBM Corporation and others.
* Copyright (c) 2017, 2024 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-2.0/
*
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
Expand Down Expand Up @@ -35,7 +35,7 @@ public class FATSuite extends TestContainerSuite {

// Updated docker image to use TLS1.2 for secure communication
static final DockerImageName db2Image = DockerImageName.parse("kyleaure/db2-ssl:3.0")
.asCompatibleSubstituteFor("ibmcom/db2");
.asCompatibleSubstituteFor("ibmcom/db2"); //TODO update .asCompatibleSubstituteFor("icr.io/db2_community/db2")

@ClassRule
public static Db2Container db2 = new Db2Container(db2Image)
Expand Down
2 changes: 2 additions & 0 deletions dev/com.ibm.ws.jdbc_fat_db2/publish/files/db2-ssl/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# TODO update to use icr.io/db2_community/db2:11.5.9.0

FROM ibmcom/db2:11.5.7.0

#Contains vulnerable log4j library for features not needed for SSL
Expand Down
6 changes: 0 additions & 6 deletions dev/com.ibm.ws.jdbc_fat_db2/publish/files/db2/Dockerfile

This file was deleted.

30 changes: 0 additions & 30 deletions dev/com.ibm.ws.jdbc_fat_db2/publish/files/db2/release.sh

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*******************************************************************************
* Copyright (c) 2020, 2022 IBM Corporation and others.
* Copyright (c) 2020, 2024 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-2.0/
*
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
Expand All @@ -31,7 +31,7 @@ public class DB2KerberosContainer extends Db2Container {
// NOTE: If this is ever updated, don't forget to push to docker hub, but DO NOT overwrite existing versions
private static final String IMAGE = "kyleaure/db2-krb5:2.0";
private static final DockerImageName db2Image = DockerImageName.parse(IMAGE)
.asCompatibleSubstituteFor("ibmcom/db2");
.asCompatibleSubstituteFor("ibmcom/db2"); //TODO update .asCompatibleSubstituteFor("icr.io/db2_community/db2")

public DB2KerberosContainer(Network network) {
super(db2Image);
Expand Down
2 changes: 2 additions & 0 deletions dev/com.ibm.ws.jdbc_fat_krb5/publish/files/db2/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# TODO update to use icr.io/db2_community/db2:11.5.9.0

FROM ibmcom/db2:11.5.7.0

#Contains vulnerable log4j library for features not needed for kerberos
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# TODO update to 17.0-alpine

FROM postgres:12.4

RUN set -ex; \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2023 IBM Corporation and others.
* Copyright (c) 2019, 2024 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -35,7 +35,7 @@ public class FATSuite extends TestContainerSuite {
private static final String POSTGRES_PASS = "superSecret";

@ClassRule
public static PostgreSQLContainer postgre = new PostgreSQLContainer("postgres:14.1-alpine")
public static PostgreSQLContainer postgre = new PostgreSQLContainer("postgres:17.0-alpine")
.withDatabaseName(POSTGRES_DB)
.withUsername(POSTGRES_USER)
.withPassword(POSTGRES_PASS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class ThreadLocalConnectionTest extends FATServletClient {
//This also means that we can only run this test manually because if this test were to run more than once at the same time
//on the same host, the ports would conflict and it would fail.
//But it is still useful to have in case a similar incident happens in the future.
public static FixedHostPortGenericContainer<?> postgre = new FixedHostPortGenericContainer<>("postgres:14.1-alpine")
public static FixedHostPortGenericContainer<?> postgre = new FixedHostPortGenericContainer<>("postgres:17.0-alpine")
.withFixedExposedPort(POSTGRE_HOST_PORT, POSTGRE_CONTAINER_PORT)
.withEnv("POSTGRES_DB", POSTGRES_DB)
.withEnv("POSTGRES_USER", POSTGRES_USER)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# TODO update to 17.0-alpine

FROM postgres:14.1-alpine

COPY ssl-certs/server.crt /var/lib/postgresql/server.crt
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*******************************************************************************
* Copyright (c) 2019, 2021 IBM Corporation and others.
* Copyright (c) 2019, 2024 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-2.0/
*
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
Expand All @@ -19,14 +19,16 @@
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
import org.testcontainers.containers.MSSQLServerContainer;
import org.testcontainers.containers.JdbcDatabaseContainer;

import com.ibm.websphere.simplicity.log.Log;

import componenttest.containers.TestContainerSuite;
import componenttest.custom.junit.runner.AlwaysPassesTest;

@RunWith(Suite.class)
@SuiteClasses({
AlwaysPassesTest.class,
SQLServerTest.class,
SQLServerSSLTest.class
})
Expand All @@ -42,24 +44,7 @@ public class FATSuite extends TestContainerSuite {
*
* @throws SQLException
*/
public static void setupDatabase(MSSQLServerContainer<?> sqlserver, boolean ssl) throws SQLException {
/*
* IBM JDK will return TLSv1 when SSLContext.getInstance(TLS) is called.
* Force driver to use TLSv1.2 for this setup step.
* See documentation here: https://github.com/microsoft/mssql-jdbc/wiki/SSLProtocol
*/
if (ssl) {
sqlserver.withUrlParam("SSLProtocol", "TLSv1.2");
}

//Setup database and settings
Log.info(FATSuite.class, "setupDatabase", "Attempting to setup database with name: " + DB_NAME + "."
+ " With connection URL: " + sqlserver.getJdbcUrl());
try (Connection conn = sqlserver.createConnection(""); Statement stmt = conn.createStatement()) {
stmt.execute("CREATE DATABASE [" + DB_NAME + "];");
stmt.execute("EXEC sp_sqljdbc_xa_install");
stmt.execute("ALTER DATABASE " + DB_NAME + " SET ALLOW_SNAPSHOT_ISOLATION ON");
}
public static void setupDatabase(JdbcDatabaseContainer<?> sqlserver) throws SQLException {

//Create test table
sqlserver.withUrlParam("databaseName", DB_NAME);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021, 2023 IBM Corporation and others.
* Copyright (c) 2021, 2024 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand All @@ -12,6 +12,7 @@
*******************************************************************************/
package com.ibm.ws.jdbc.fat.sqlserver;

import static componenttest.annotation.SkipIfSysProp.NETWORK_AWS;
import static componenttest.custom.junit.runner.Mode.TestMode.FULL;
import static org.junit.Assume.assumeTrue;

Expand All @@ -20,12 +21,14 @@
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.containers.MSSQLServerContainer;
import org.testcontainers.utility.DockerImageName;

import com.ibm.websphere.simplicity.ShrinkHelper;

import componenttest.annotation.Server;
import componenttest.annotation.SkipIfSysProp;
import componenttest.annotation.TestServlet;
import componenttest.containers.SimpleLogConsumer;
import componenttest.custom.junit.runner.FATRunner;
Expand All @@ -37,6 +40,11 @@

@Mode(FULL)
@RunWith(FATRunner.class)
// TODO remove once we can update SSL image to 2019-CU28-ubuntu-20.04
// Avoiding bug in SQLServer docker image https://github.com/microsoft/mssql-docker/issues/881
// Which has logic that tightly couples the container kernel and host kernel
// Today the kernel available on the remote docker host for AWS causes SQLServer to fail to start.
@SkipIfSysProp(NETWORK_AWS)
public class SQLServerSSLTest extends FATServletClient {

public static final String APP_NAME = "sqlserversslfat";
Expand All @@ -50,13 +58,15 @@ public class SQLServerSSLTest extends FATServletClient {
.asCompatibleSubstituteFor("mcr.microsoft.com/mssql/server");

@ClassRule
public static MSSQLServerContainer<?> sqlserver = new MSSQLServerContainer<>(sqlserverImage) //
public static JdbcDatabaseContainer<?> sqlserver = new MSSQLServerContainer<>(sqlserverImage) //
.withLogConsumer(new SimpleLogConsumer(FATSuite.class, "sqlserver")) //
.withInitScript("init-sqlserver.sql") // from fattest.simplicity
.withUrlParam("SSLProtocol", "TLSv1.2") // See documentation here: https://github.com/microsoft/mssql-jdbc/wiki/SSLProtocol
.acceptLicense();

@BeforeClass
public static void setUp() throws Exception {
FATSuite.setupDatabase(sqlserver, true);
FATSuite.setupDatabase(sqlserver);

server.addEnvVar("SQL_DBNAME", FATSuite.DB_NAME);
server.addEnvVar("SQL_HOST", sqlserver.getHost());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2023 IBM Corporation and others.
* Copyright (c) 2019, 2024 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand All @@ -22,14 +22,15 @@
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.testcontainers.containers.MSSQLServerContainer;
import org.testcontainers.containers.JdbcDatabaseContainer;

import com.ibm.websphere.simplicity.ShrinkHelper;

import componenttest.annotation.Server;
import componenttest.annotation.TestServlet;
import componenttest.containers.SimpleLogConsumer;
import componenttest.custom.junit.runner.FATRunner;
import componenttest.topology.database.container.DatabaseContainerFactory;
import componenttest.topology.database.container.DatabaseContainerType;
import componenttest.topology.impl.LibertyServer;
import componenttest.topology.utils.FATServletClient;
import web.SQLServerTestServlet;
Expand All @@ -45,13 +46,11 @@ public class SQLServerTest extends FATServletClient {
public static LibertyServer server;

@ClassRule
public static MSSQLServerContainer<?> sqlserver = new MSSQLServerContainer<>("mcr.microsoft.com/mssql/server:2019-CU18-ubuntu-20.04") //
.withLogConsumer(new SimpleLogConsumer(FATSuite.class, "sqlserver")) //
.acceptLicense();
public static JdbcDatabaseContainer<?> sqlserver = DatabaseContainerFactory.createType(DatabaseContainerType.SQLServer);

@BeforeClass
public static void setUp() throws Exception {
FATSuite.setupDatabase(sqlserver, false);
FATSuite.setupDatabase(sqlserver);

server.addEnvVar("SQL_DBNAME", FATSuite.DB_NAME);
server.addEnvVar("SQL_HOST", sqlserver.getHost());
Expand Down
Loading