testcontainers / testcontainers/testcontainers-java
Container lifecycle management as Maven and Gradle plugins
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Java
- Star
- 8.7k
- Fork
- 1.9k
- Merge trung bình
- 2 ngày 17 giờ
- Pull request đã merge (30 ngày)
- 9
Mô tả
In jOOQ, one of the most re-occurring ideas is that jOOQ should tightly couple Testcontainers, Flyway/Liquibase and jOOQ's code generation. See e.g. https://github.com/jOOQ/jOOQ/issues/6551
This coupling is obviously a bad idea, because the glue code is only a few lines of code, but to make it sufficiently configurable on behalf of all 3 involved products, we'd have to go through a lot of hassle. Much better if all 3 products could be configured completely independently in a CI/CD pipeline.
This is already possible for Flyway/Liquibase and jOOQ, both in Maven and Gradle, but I think it's not trivial to do for Testcontainers yet? What I'd love to see is to have Maven and Gradle plugins available that would allow for controlling the lifecycle of a test container instance in a build, for example (in pseudo-Maven):
<plugins>
<!-- Start the database container -->
<plugin>
<artifactId>testcontainers-postgres-maven<artifactId>
<phase>initialize</phase>
<goal>start</goal>
</plugin>
<!-- Apply all schema migrations -->
<plugin>
<artifactId>flyway-maven<artifactId>
<phase>initialize</phase>
</plugin>
<!-- Generate jOOQ sources -->
<plugin>
<artifactId>jooq-codegen-maven<artifactId>
<phase>generate-sources</phase>
</plugin>
<!-- Stop the containers -->
<plugin>
<artifactId>testcontainers-postgres-maven<artifactId>
<phase>post-integration-test</phase>
<goal>stop</goal>
</plugin>
</plugin>
I don't think Maven has an equivalent of Java's finally clause (i.e. a phase that runs at the end irrespective of how many phases were run), so if the post-integration-test phase isn't reached, then the containers won't stop, but that can be handled:
- E.g. they could stop at the latest when the build VM terminates (might be possible?)
- Gradle might not have this problem
- The start goal could reset the container first, if it is already running
- They could use Maven profiles for the whole thing and put all 4 plugin executions in there
There are many details to flesh out, but you get the idea. I think the sort of versatility this offers to highly generic, configurable builds would be yet another killer feature for testcontainers, not just for testing, but for CI/CD pipelines in general.
I've found an example project here, that does something like what I have in mind:
https://github.com/squark-io/testcontainers-maven-plugin
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng việc xem xét ví dụ squark-io/testcontainers-maven-plugin được liên kết và các yêu cầu về vòng đời được mô tả ở đây cho Maven và Gradle. Xác định cách các goal có thể cấu hình để khởi động và dừng container cần được tích hợp với các giai đoạn build, bao gồm việc dọn dẹp khi build kết thúc sớm; được xem là hoàn tất khi cả hai tích hợp plugin đều hỗ trợ vòng đời được đề xuất một cách độc lập với Flyway, Liquibase và jOOQ.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- docker, java
- Lĩnh vực
- build-system, devops, testing
- Loại issue
- Tính năng
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Sôi nổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100