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

feat(core): Added ServerContainer #595

Merged
merged 6 commits into from
Jun 18, 2024

Conversation

Tranquility2
Copy link
Contributor

@Tranquility2 Tranquility2 commented Jun 1, 2024

As part of the effort described, detailed and presented on #559
This is the seconds PR (out of 4) that should provide all the groundwork to support containers running a server.

This would allow users to use custom images:

with DockerImage(path=".", tag="test:latest") as image:
    with ServerContainer(port=9000, image=image) as srv:
        # Test something with/on the server using port 9000

Next in line are:
feat(core): Added FastAPI module
feat(core): Added AWS Lambda module


Based on the work done on #585
Expended from issue #83

Added doctest to SrcContainer and update readme

Fix issue with SrcContainer image handle

Add test for SrcContainer

Fixed doctest

Improve SrvContainer

Fix test_srv_container logs check

Improve SrvContainer and update tests

Updates for SrvContainer
@alexanderankin
Copy link
Collaborator

some thoughts:

  1. can you rename as ServerContainer
  2. can we make this a module under modules? I guess if we do this we have to figure out how to make those modules depend on each other but assuming we can make that work, how do we feel about this.

Copy link

codecov bot commented Jun 6, 2024

Codecov Report

Attention: Patch coverage is 90.00000% with 4 lines in your changes missing coverage. Please review.

Please upload report for BASE (main@59cb6fc). Learn more about missing BASE report.

Files Patch % Lines
core/testcontainers/core/generic.py 87.50% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #595   +/-   ##
=======================================
  Coverage        ?   79.55%           
=======================================
  Files           ?       10           
  Lines           ?      582           
  Branches        ?       80           
=======================================
  Hits            ?      463           
  Misses          ?       92           
  Partials        ?       27           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Tranquility2
Copy link
Contributor Author

Yes, you are right, ServerContainer is a much better name and it correlates to your second point, I do think its very general and more in par with DBContainer than a specific module (thats why I placed it under generics). I think the modules should remain specific product related. I'll try and support my claim with the java implementation of "nginx container" (which I'll probably add later on 😅 ) https://github.com/testcontainers/testcontainers-java/blob/6658a2c0a880d01c6d402ea9a4cb5f72eb15083c/modules/nginx/src/main/java/org/testcontainers/containers/NginxContainer.java#L12C13-L12C29
Notice it uses GenericContainer which is (in a way) the combination of DBContainer and ServerContainer.

So to conclude I think we should keep ServerContainer under generics, and maybe plan in the future to merge DBContainer and ServerContainer (?) into GenericContainer (but to be honest I think the separation is good at this stage)

@alexanderankin
Copy link
Collaborator

alexanderankin commented Jun 6, 2024

for context, we are trying to remove DbContainer as well.

will take a look.

@alexanderankin alexanderankin changed the title feat(core): Added SrvContainer feat(core): Added ServerContainer Jun 6, 2024
@Tranquility2
Copy link
Contributor Author

Tranquility2 commented Jun 6, 2024

I can offer another alternative, completely skip ServerContainer and just make the modules repeat some code, I can also check it out and propose a draft if you like. (with ServerContainer I tried to create something useful, maybe I just missed the big picture / context)

@alexanderankin
Copy link
Collaborator

opened Tranquility2#2

…refactor

* fix the docs so that we can mark DbContainer as deprecated for removal
* add a warning to ServerContainer just in case it is actually possible to move it out of core
* use glob for modules/index.rst
* clean up the table of contents so that deprecated classes do not appear on the front page
* prepare to refactor the dockerimage stuff with the same class name/structure as Java (DockerImageName, ImageFromDockerfile)
@Tranquility2
Copy link
Contributor Author

rebased with new improvements

@alexanderankin alexanderankin merged commit 0768490 into testcontainers:main Jun 18, 2024
12 checks passed
alexanderankin pushed a commit that referenced this pull request Jun 20, 2024
🤖 I have created a release *beep* *boop*
---


##
[4.6.0](testcontainers-v4.5.1...testcontainers-v4.6.0)
(2024-06-18)


### Features

* **core:** Added ServerContainer
([#595](#595))
([0768490](0768490))
* **core:** Image build (Dockerfile support)
([#585](#585))
([54c88cf](54c88cf))


### Bug Fixes

* Add Cockroach DB Module to Testcontainers
([#608](#608))
([4aff679](4aff679))
* Container for Milvus database
([#606](#606))
([ec76df2](ec76df2))
* move TESTCONTAINERS_HOST_OVERRIDE to config.py
([#603](#603))
([2a5a190](2a5a190)),
closes
[#602](#602)
* **mqtt:** Add mqtt.MosquittoContainer
([#568](#568))
([#599](#599))
([59cb6fc](59cb6fc))


### Documentation

* **main:** Private registry
([#598](#598))
([9045c0a](9045c0a))
* Update private registry instructions
([#604](#604))
([f5a019b](f5a019b))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
alexanderankin pushed a commit that referenced this pull request Jun 28, 2024
As part of the effort described, detailed and presented on
#559
This is the third PR (out of 4) that should provide all the groundwork
to support containers running a server.

As discussed on #595 this PR aims to refactor the `ServerContainer`
under a new dedicated module called "generic".

![image](https://github.com/testcontainers/testcontainers-python/assets/7189138/b7a3395b-ce3c-40ef-8baa-dfa3eff1b056)

The idea is that this module could include multiple generic
implementations such as ```server.py``` with the proper documentation
and examples to allow users simpler usage and QOL.
This PR adds the original FastAPI implementation as a simple doc
example, I think this aligns better following #595
        
Next in line is ```feat(core): Added AWS Lambda module```

Based on the work done on
#585 and
#595
Expended from issue
#83

---
Please note an extra commit is included to simulate the relations when
importing between and with other modules.
alexanderankin pushed a commit that referenced this pull request Jul 31, 2024
As part of the effort described, detailed and presented on
#559
This is the 4th (and final in this track) PR that should provide support
for AWS Lambda containers.

This module will add the ability to test and run Amazon Lambdas (using
the built-in runtime interface emulator)
For example:

```python
from testcontainers.aws import AWSLambdaContainer
from testcontainers.core.waiting_utils import wait_for_logs
from testcontainers.core.image import DockerImage

with DockerImage(path="./modules/aws/tests/lambda_sample", tag="test-lambda:latest") as image:
    with AWSLambdaContainer(image=image, port=8080) as func:
        response = func.send_request(data={'payload': 'some data'})
        assert response.status_code == 200
        assert "Hello from AWS Lambda using Python" in response.json()
        delay = wait_for_logs(func, "START RequestId:")
```

This can (and probably will) be used with the provided
[LocalStackContainer](https://testcontainers-python.readthedocs.io/en/latest/modules/localstack/README.html)
to help simulate more advance AWS cases.

---

Based on the work done on:
- #585 
- #595 
- #612

Expended from issue
#83
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants