Question: Test postgres container
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 20/100
- Type d'issue
- Bug
- Clarté
- À clarifier
- Activité
- À l'abandon
- Stack technique
- docker, kubernetes, postgresql, python
- Domaine
- databases, devops, testing-qa
Piste de recherche
Reproduisez l’exemple avec python3 test_postgres_container.py et examinez le comportement de test_postgres_container.py, kubernetes/postgres.yaml et app.yaml. L’issue n’indique aucune erreur ni modification attendue ; identifiez donc d’abord l’étape qui échoue et déterminez si le conteneur PostgreSQL, les manifestes Kubernetes ou la requête de vérification de l’état en sont responsables.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
What are you trying to do?
Run a minimal example with testcontainers. Run command:
pip install pytest
python3 test_postgres_container.py
test_postgres_container.py
import requests
import yaml
import time
import os
from testcontainers.k3s import K3SContainer
from testcontainers.postgres import PostgresContainer
from kubernetes import client, config
def wait_for_pod_ready(config_dict, namespace="default", timeout=120):
"""
Wait for all pods in the namespace to be ready.
"""
from kubernetes import client, config
config.load_kube_config(config_file=config_dict)
v1 = client.CoreV1Api()
end_time = time.time() + timeout
while time.time() < end_time:
pods = v1.list_namespaced_pod(namespace=namespace)
if all(p.status.phase == "Running" for p in pods.items):
return True
time.sleep(5)
raise TimeoutError("Timeout waiting for pods to be ready")
def test_kubernetes_app():
# Spin up PostgreSQL Container
with PostgresContainer("postgres:15.0") as postgres:
postgres_host = postgres.get_container_host_ip()
postgres_port = postgres.get_exposed_port(5432)
# Set up Kubernetes cluster
with K3SContainer() as k3s:
config_dict=yaml.safe_load(k3s.config_yaml())
config.load_kube_config_from_dict(config_dict)
os.environ["KUBECONFIG"] = config_dict
# Apply Kubernetes manifests
os.system(f"kubectl apply -f kubernetes/app.yaml")
os.system(f"kubectl apply -f kubernetes/postgres.yaml")
# Wait for all pods to be ready
wait_for_pod_ready(config_dict)
# Send an HTTP request to the application
response = requests.get("http://localhost:8080/health")
assert response.status_code == 200
assert "healthy" in response.text
kubernetes/postgres.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres
spec:
replicas: 1
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgres:15.0
env:
- name: POSTGRES_USER
value: "user"
- name: POSTGRES_PASSWORD
value: "password"
- name: POSTGRES_DB
value: "mydb"
---
apiVersion: v1
kind: Service
metadata:
name: postgres
spec:
ports:
- port: 5432
selector:
app: postgres
app.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 1
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app
image: my-app-image:latest
ports:
- containerPort: 8080
env:
- name: DATABASE_URL
value: "postgresql://user:password@postgres:5432/mydb"
---
apiVersion: v1
kind: Service
metadata:
name: my-app
spec:
type: NodePort
selector:
app: my-app
ports:
- protocol: TCP
port: 8080
targetPort: 8080
Runtime environment
>> uname -a
Linux DESKTOP-UP6B64S 5.15.153.1-microsoft-standard-WSL2 #1 SMP Fri Mar 29 23:14:13 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
>> docker info
Client: Docker Engine - Community
Version: 27.5.1
Context: default
Debug Mode: false
Plugins:
Server:
Containers: 8
Running: 7
Paused: 0
Stopped: 1
Images: 34
Server Version: 27.5.1
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Using metacopy: false
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
Swarm: active
NodeID: q8b9mpmb1zgtsz81plpx97g6q
Is Manager: true
ClusterID: ayrevwl1es784e2k38ogh2j8g
Managers: 1
Nodes: 1
Default Address Pool: 10.0.0.0/8
SubnetSize: 24
Data Path Port: 4789
Orchestration:
Task History Retention Limit: 5
Raft:
Snapshot Interval: 10000
Number of Old Snapshots to Retain: 0
Heartbeat Tick: 1
Election Tick: 10
Dispatcher:
Heartbeat Period: 5 seconds
CA Configuration:
Expiry Duration: 3 months
Force Rotate: 0
Autolock Managers: false
Root Rotation In Progress: false
Node Address: 172.17.138.216
Manager Addresses:
172.17.138.216:2377
Runtimes: io.containerd.runc.v2 runc
Default Runtime: runc
Init Binary: docker-init
containerd version: bcc810d6b9066471b0b6fa75f557a15a1cbf31bb
runc version: v1.2.4-0-g6c52b3f
init version: de40ad0
Security Options:
seccomp
Profile: builtin
Kernel Version: 5.15.153.1-microsoft-standard-WSL2
Operating System: Ubuntu 22.04.5 LTS
OSType: linux
Architecture: x86_64
CPUs: 12
Total Memory: 7.607GiB
Name: DESKTOP-UP6B64S
ID: fe231f46-b911-4db9-b4e0-7a80f27d8058
Docker Root Dir: /var/lib/docker
Debug Mode: false
Username: brunolnetto1234
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
- Langage dominant
- Python
- Étoiles
- 2.3k
- Forks
- 397
- Merge moyen
- 8 j 16 h
- PR mergées (30 j)
- 5
Préparer son environnement
Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.
- Fournit un Dockerfile ou un fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de testcontainers/testcontainers-python
-
Feature: Stream bytes out on copy_from_containerPeut-être pris @archit15singh l’a pris il y a 11 jours. Ouverte🚀 enhancement
Difficulté 2/5 1-3 heures Accessibilité débutants 67/100
-
Bug: HttpWaitStrategy ignores response predicates for accepted HTTP error statusesPeut-être pris @PranavMulakala l’a pris il y a 41 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 85/100
-
Bug: LogMessageWaitStrategy: a container that exits before its message raises without its logs, and __enter__ then removes the containerPeut-être pris @granzer69 l’a pris il y a 42 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
-
Updating the documentationOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 67/100
testcontainers/testcontainers-python#1086 · 1 commentaire ·
-
Bug: [minio] _healthcheck calls for nested wait_container_is_ready resulting in long wait timeOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
testcontainers/testcontainers-python#578 · 5 commentaires ·
Toutes les issues de testcontainers/testcontainers-python
Issues similaires
-
bug feature request
Difficulté 2/5 1-3 heures Accessibilité débutants 67/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 1/5 1-3 heures Accessibilité débutants 66/100
Les mainteneurs répondent en général sous 3 jours
-
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
Qiskit/qiskit-obp#156 ·
-
perf(batch-jobs): discover-misses reads the state list without running the whole stage reportOuverteaction-item enhancement
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
getcommunityone/open-navigator#1658 ·
Les mainteneurs répondent en général sous 1 jour
-
review-panel severity:low
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
kristovatlas/coin-accounting#636 ·
Les mainteneurs répondent en général sous 1 jour