Question: Test postgres container
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 20/100
- Tipo de issue
- Bug
- Clareza
- Precisa de esclarecimento
- Status de atividade
- Estagnada
- Stack de tecnologia
- docker, kubernetes, postgresql, python
- Domínio
- databases, devops, testing-qa
Direção de pesquisa
Reproduza o exemplo com python3 test_postgres_container.py e inspecione o comportamento de test_postgres_container.py, kubernetes/postgres.yaml e app.yaml. A issue não informa nenhum erro ou alteração esperada; portanto, primeiro identifique a etapa que está falhando e determine se a responsabilidade é do contêiner PostgreSQL, dos manifestos do Kubernetes ou da requisição de verificação de integridade.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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
- Linguagem predominante
- Python
- Estrelas
- 2.3k
- Forks
- 397
- Merge médio
- 8d 16h
- PRs com merge (30d)
- 5
Preparar o ambiente
Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.
- Inclui um Dockerfile ou arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de testcontainers/testcontainers-python
-
Feature: Stream bytes out on copy_from_containerTalvez já em andamento @archit15singh assumiu há 11 dias. Aberta🚀 enhancement
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 67/100
-
Bug: HttpWaitStrategy ignores response predicates for accepted HTTP error statusesTalvez já em andamento @PranavMulakala assumiu há 41 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 85/100
-
Bug: LogMessageWaitStrategy: a container that exits before its message raises without its logs, and __enter__ then removes the containerTalvez já em andamento @granzer69 assumiu há 42 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
-
Updating the documentationAberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 67/100
testcontainers/testcontainers-python#1086 · 1 comentário ·
-
Bug: [minio] _healthcheck calls for nested wait_container_is_ready resulting in long wait timeAberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
testcontainers/testcontainers-python#578 · 5 comentários ·
Todas as issues de testcontainers/testcontainers-python
Issues semelhantes
-
bug feature request
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 67/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 66/100
Mantenedores costumam responder em até 3 dias
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
Qiskit/qiskit-obp#156 ·
-
perf(batch-jobs): discover-misses reads the state list without running the whole stage reportAbertaaction-item enhancement
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 88/100
getcommunityone/open-navigator#1658 ·
Mantenedores costumam responder em até 1 dia
-
review-panel severity:low
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
kristovatlas/coin-accounting#636 ·
Mantenedores costumam responder em até 1 dia