Skip to content

Commit ce9e90f

Browse files
committed
Try to make it work in CI
1 parent 46a080f commit ce9e90f

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

.github/workflows/test-integrations-aws.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ jobs:
6969
# see https://github.com/actions/setup-python/issues/544#issuecomment-1332535877
7070
os: [ubuntu-20.04]
7171
needs: check-permissions
72+
services:
73+
docker:
74+
image: docker:dind # Docker-in-Docker
75+
options: --privileged
7276
steps:
7377
- uses: actions/[email protected]
7478
with:

requirements-testing.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ socksio
1414
httpcore[http2]
1515
setuptools
1616
Brotli
17+
docker

tests/integrations/aws_lambda/test_aws_lambda.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import boto3
2+
import docker
23
import json
34
import pytest
5+
import socket
46
import subprocess
57
import tempfile
68
import time
@@ -20,14 +22,22 @@
2022
def test_environment():
2123
print("[test_environment fixture] Setting up AWS Lambda test infrastructure")
2224

25+
# Create a Docker network
26+
docker_client = docker.from_env()
27+
network = docker_client.networks.create("lambda-test-network", driver="bridge")
28+
2329
# Start Sentry server
2430
server = SentryServerForTesting()
2531
server.start()
2632
time.sleep(1) # Give it a moment to start up
2733

34+
# Get the host IP address
35+
hostname = socket.gethostname()
36+
host_ip = socket.gethostbyname(hostname)
37+
2838
# Create local AWS SAM stack
2939
app = App()
30-
stack = LocalLambdaStack(app, "LocalLambdaStack")
40+
stack = LocalLambdaStack(app, "LocalLambdaStack", host=host_ip)
3141

3242
# Write SAM template to file
3343
template = app.synth().get_stack_by_name("LocalLambdaStack").template
@@ -50,6 +60,8 @@ def test_environment():
5060
SAM_TEMPLATE_FILE,
5161
"--warm-containers",
5262
"EAGER",
63+
"--docker-network",
64+
"lambda-test-network",
5365
],
5466
stdout=debug_log,
5567
stderr=debug_log,

tests/integrations/aws_lambda/utils.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class LocalLambdaStack(Stack):
3030
"""
3131

3232
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
33+
host = kwargs.pop("host", "host-not-specified")
34+
3335
super().__init__(scope, construct_id, **kwargs)
3436
print("[LocalLambdaStack] Creating local SAM Lambda Stack: %s" % self)
3537

@@ -83,7 +85,7 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
8385
], # Add layer containing the Sentry SDK to function.
8486
"Environment": {
8587
"Variables": {
86-
"SENTRY_DSN": "http://123@host.docker.internal:9999/0",
88+
"SENTRY_DSN": f"http://123@{host}:9999/0",
8789
"SENTRY_INITIAL_HANDLER": "index.handler",
8890
"SENTRY_TRACES_SAMPLE_RATE": "1.0",
8991
}
@@ -127,8 +129,9 @@ class SentryServerForTesting:
127129
A simple Sentry.io style server that accepts envelopes and stores them in a list.
128130
"""
129131

130-
def __init__(self, port=9999, log_level="warning"):
132+
def __init__(self, host="0.0.0.0", port=9999, log_level="warning"):
131133
self.envelopes = []
134+
self.host = host
132135
self.port = port
133136
self.log_level = log_level
134137
self.app = FastAPI()
@@ -167,10 +170,10 @@ async def envelope(request: Request):
167170
return {"status": "ok"}
168171

169172
def run_server(self):
170-
uvicorn.run(self.app, host="0.0.0.0", port=self.port, log_level=self.log_level)
173+
uvicorn.run(self.app, host=self.host, port=self.port, log_level=self.log_level)
171174

172175
def start(self):
173-
print("[SentryServerForTesting] Starting server")
176+
print("[SentryServerForTesting] Starting server on %s:%s" % (self.host, self.port))
174177
server_thread = threading.Thread(target=self.run_server, daemon=True)
175178
server_thread.start()
176179

0 commit comments

Comments
 (0)