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

extracts kubernetes api classes #3

Merged
merged 32 commits into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
d96a40d
host ports turn of/off
m4gshm Nov 18, 2023
532c31a
fix(uploadTmpTar): complicating code for predictable result
m4gshm Nov 19, 2023
956f708
feat(uploadTmpTar): сopy as base64 encoded string
m4gshm Nov 20, 2023
829a2fc
feat(uploadTmpTar): wait until the websocket message queue is empty
m4gshm Nov 21, 2023
ded378c
dep: update lombok, gradle version
m4gshm Apr 4, 2024
0e31022
feat(reusing): different ways of reuse pods: session limited or global
m4gshm Apr 12, 2024
5a85965
Merge remote-tracking branch 'origin/dev' into dev
m4gshm Apr 12, 2024
29549c0
dependency(lombok): update to 1.18.30
m4gshm Apr 12, 2024
5ad8067
preparation for merging
m4gshm Apr 13, 2024
ce17c40
preparation for merging
m4gshm Apr 13, 2024
13620fc
fix: readme
m4gshm Apr 13, 2024
2f5cdd0
fix: readme
m4gshm Apr 13, 2024
fd21cb7
fix: readme
m4gshm Apr 13, 2024
1f35d46
fix: readme
m4gshm Apr 13, 2024
3fb69a8
feat(pod-name-generator): uses the docker image name as a suffix in a…
m4gshm Apr 14, 2024
ba8989a
cicd: github
m4gshm Apr 14, 2024
ce204b7
cicd: github
m4gshm Apr 14, 2024
67338e8
cicd: github
m4gshm Apr 14, 2024
6821023
cicd: github
m4gshm Apr 14, 2024
0efde63
cicd: github
m4gshm Apr 14, 2024
41f7d1e
cicd: github
m4gshm Apr 14, 2024
48ec824
version: 0.0.1-rc1
m4gshm Apr 14, 2024
cc21c2a
minor changes
m4gshm Apr 14, 2024
e80668b
feat: migrates to testcontainers:1.19.7
m4gshm Apr 16, 2024
6c31c4d
refactor: extracts Kubernetes related classes
m4gshm Apr 16, 2024
b8059d7
refactor: extracts Kubernetes related classes
m4gshm Apr 17, 2024
8398b21
refactor: extracts Kubernetes related classes
m4gshm Apr 17, 2024
a7d00bf
refactor: extracts Kubernetes related classes
m4gshm Apr 17, 2024
1fbc073
logging, error handling
m4gshm Apr 21, 2024
a46afdf
logging, error handling
m4gshm Apr 27, 2024
97150c5
readme
m4gshm Apr 27, 2024
db34570
Merge remote-tracking branch 'refs/remotes/origin/master' into dev
m4gshm Apr 27, 2024
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
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