Skip to content

Commit

Permalink
rc1 - 1 (#3)
Browse files Browse the repository at this point in the history
* host ports turn of/off
* fix(uploadTmpTar): complicating code for predictable result
* feat(uploadTmpTar): сopy as base64 encoded string
* feat(uploadTmpTar): wait until the websocket message queue is empty
* feat(reusing): different ways of reuse pods: session limited or global
* dependency(lombok): update to 1.18.30
* feat(pod-name-generator): uses the docker image name as a suffix in a pod name.
* feat: migrates to testcontainers:1.19.7
  • Loading branch information
m4gshm authored Apr 27, 2024
1 parent 124e63e commit e93adc7
Show file tree
Hide file tree
Showing 55 changed files with 1,901 additions and 1,275 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Build

on:
push:
branches:
- main
- dev
- "releases/**"
- "feature/**"
- "bugfix/**"
pull_request:
branches:
- main
- dev
- "releases/**"
- "feature/**"
- "bugfix/**"

jobs:
build:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Create k8s Kind Cluster
uses: helm/kind-action@v1
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
- name: config kube namespace
run: kubectl config set-context --current --namespace=default
- name: Execute Gradle build
run: ./gradlew clean :test:build -Pno-pandoc
- name: Publish Test Report
uses: mikepenz/action-junit-report@v4
if: success() || failure() # always run even if the previous step fails
with:
report_paths: '**/build/test-results/test/TEST-*.xml'
44 changes: 4 additions & 40 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,42 +1,6 @@
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
.idea/
test/build/
test/logs*
gradle.properties
109 changes: 95 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,103 @@
# Testcontainers on kubernetes (under construction)
# Testcontainers on Kubernetes (under construction)

A tool to run testcontainers tests in a kubernetes environment.

Goal is Postgresql and Redis support.
Requires Java 17 or higher.

- to build run `./gradlew publishToMavenLocal`
- add next code in your `gradle.kts` script:
```gradle
repositories {
mavenLocal()
Compatibility with Testcontainers 1.19.7.

## Implementations

- [PostgresqlPod](./src/main/java/io/github/m4gshm/testcontainers/PostgresqlPod.java)

- [MongoDBPod](./src/main/java/io/github/m4gshm/testcontainers/MongoDBPod.java)

- [GenericPod](./src/main/java/io/github/m4gshm/testcontainers/GenericPod.java)

## Install

### Gradle (Kotlin syntax)

Add the code below to your `build.gradle.kts`

``` kotlin
repositories {
mavenCentral()
}

dependencies {
testImplementation("io.github.m4gshm:kubetestcontainers:0.0.1-rc1")
testImplementation("org.testcontainers:postgresql:1.19.7")
}
```

## Usage example

To run locally, it is highly recommended to use
[Minikube](https://minikube.sigs.k8s.io) or
[Kind](https://kind.sigs.k8s.io).

``` java
package example;

import io.github.m4gshm.testcontainers.PostgresqlPod;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.containers.PostgreSQLContainer;

import java.sql.SQLException;

import static java.sql.DriverManager.getConnection;

public class JdbcTest {

private final static JdbcDatabaseContainer<?> postgres = useKubernetes()
? new PostgresqlPod() : new PostgreSQLContainer<>();

private static boolean useKubernetes() {
return "kuber".equals(System.getProperty("testcontainers-engine", "kuber"));
}
dependencies {
testImplementation("com.github.m4gshm:kubetestcontainers:0.1-SNAPSHOT")
testImplementation("org.testcontainers:postgresql:1.19.0")

@BeforeAll
static void beforeAll() {
postgres.start();
}
```
- start experimenting.

See tests as an example [here](./tests/src/test/java/com/github/m4gshm/testcontainers).
@Test
public void jdbcInsertSelectTest() throws SQLException {
var url = postgres.getJdbcUrl();
var username = postgres.getUsername();
var password = postgres.getPassword();
try (var connection = getConnection(url, username, password)) {
try (var statement = connection.prepareStatement("""
create table participant (
id integer,
name text
);
"""
)) {
statement.execute();
}

And don't forget to install [Minikube](https://kubernetes.io/ru/docs/tasks/tools/install-minikube/).
try (var statement = connection.prepareStatement(
"insert into participant(id, name) values(?,?)")) {
statement.setInt(1, 1);
statement.setString(2, "Alice");
statement.execute();
}

try (var statement = connection.prepareStatement(
"select name from participant where id=?")) {
statement.setInt(1, 1);
try (var resultSet = statement.executeQuery()) {
Assertions.assertTrue(resultSet.next());
var name = resultSet.getString(1);
Assertions.assertEquals("Alice", name);
}
}
}
}
}
```
67 changes: 60 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
plugins {
`java-library`
`maven-publish`
signing
id("com.gradleup.nmcp").version("0.0.4")
id("org.asciidoctor.jvm.convert") version "4.0.1"
}

group = "com.github.m4gshm"
version = "0.1-SNAPSHOT"
group = "io.github.m4gshm"
version = "0.0.1-rc1"

repositories {
mavenCentral()
}

dependencies {
annotationProcessor("org.projectlombok:lombok:1.18.28")
annotationProcessor("org.projectlombok:lombok:1.18.30")
compileOnly("org.projectlombok:lombok:1.18.28")
testAnnotationProcessor("org.projectlombok:lombok:1.18.28")
testAnnotationProcessor("org.projectlombok:lombok:1.18.30")

implementation("org.testcontainers:testcontainers:1.19.1")
compileOnly("org.testcontainers:jdbc:1.19.1")
compileOnly("org.testcontainers:postgresql:1.19.1")
compileOnly("org.testcontainers:mongodb:1.19.0")
compileOnly("org.testcontainers:jdbc:1.19.7")
compileOnly("org.testcontainers:postgresql:1.19.7")
compileOnly("org.testcontainers:mongodb:1.19.7")

implementation("io.fabric8:kubernetes-client:6.8.1")
implementation("commons-codec:commons-codec:1.16.0")
Expand All @@ -36,15 +39,38 @@ tasks.test {

java {
withSourcesJar()
// withJavadocJar()
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_17
modularity.inferModulePath.set(true)
}

tasks.asciidoctor {
dependsOn(":test:classes")
baseDirFollowsSourceFile()
outputOptions {
backends("docbook")
}
}

tasks.create<Exec>("pandoc") {
dependsOn("asciidoctor")
group = "documentation"
commandLine = "pandoc -f docbook -t gfm $buildDir/docs/asciidoc/readme.xml -o $rootDir/README.md".split(" ")
}

tasks.build {
if (properties["no-pandoc"] == null) {
dependsOn("pandoc")
}
}

publishing {
publications {
create<MavenPublication>("java") {
pom {
description.set("Like test containers, but using Kubernetes")
url.set("https://github.com/m4gshm/kubetestcontainers")
properties.put("maven.compiler.target", "${java.targetCompatibility}")
properties.put("maven.compiler.source", "${java.sourceCompatibility}")
developers {
Expand All @@ -59,8 +85,35 @@ publishing {
developerConnection.set("scm:git:https://github.com/m4gshm/kubetestcontainers.git")
url.set("https://github.com/m4gshm/kubetestcontainers")
}
licenses {
license {
name.set("MIT License")
url.set("https://github.com/m4gshm/kubetestcontainers?tab=MIT-1-ov-file#readme")
}
}
}
from(components["java"])
}
}
repositories {
maven("file://$rootDir/../m4gshm.github.io/maven2") {
name = "GithubMavenRepo"
}
}
}

//signing {
// val extension = extensions.getByName("publishing") as PublishingExtension
// sign(extension.publications)
//}

nmcp {
publishAllProjectsProbablyBreakingProjectIsolation {
val ossrhUsername = project.properties["ossrhUsername"] as String?
val ossrhPassword = project.properties["ossrhPassword"] as String?
username.set(ossrhUsername)
password.set(ossrhPassword)
publicationType = "USER_MANAGED"
// publicationType = "AUTOMATIC"
}
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sat Aug 26 10:32:41 MSK 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
rootProject.name = "kubetestcontainers"

include(":tests")
include(":test")
38 changes: 38 additions & 0 deletions src/docs/asciidoc/readme.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
= Kubetestcontainers

== Testcontainers on Kubernetes (under construction)

A tool to run testcontainers tests in a kubernetes environment.

Requires Java 17 or higher.

Compatibility with Testcontainers 1.19.7.

=== Implementations
- link:./src/main/java/io/github/m4gshm/testcontainers/PostgresqlPod.java[PostgresqlPod]
- link:./src/main/java/io/github/m4gshm/testcontainers/MongoDBPod.java[MongoDBPod]
- link:./src/main/java/io/github/m4gshm/testcontainers/GenericPod.java[GenericPod]

=== Install
==== Gradle (Kotlin syntax)
Add the code below to your `build.gradle.kts`
[source,kotlin]
----
repositories {
mavenCentral()
}
dependencies {
testImplementation("io.github.m4gshm:kubetestcontainers:0.0.1-rc1")
testImplementation("org.testcontainers:postgresql:1.19.7")
}
----

=== Usage example

To run locally, it is highly recommended to use link:https://minikube.sigs.k8s.io[Minikube] or link:https://kind.sigs.k8s.io[Kind].

[source,java]
----
include::../../../test/src/test/java/example/JdbcTest.java[]
----

This file was deleted.

Loading

0 comments on commit e93adc7

Please sign in to comment.