Skip to content

Commit 9ef83b6

Browse files
authored
pin wrangler version to fix hanging miniflare invocations (#86)
1 parent 81d1c94 commit 9ef83b6

File tree

7 files changed

+26
-14
lines changed

7 files changed

+26
-14
lines changed

aws-replicator/aws_replicator/client/auth_proxy.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def _fix_host_and_path(self, request: Request, service_name: str):
278278
regex_base_domain = rf"((amazonaws\.com)|({LOCALHOST_HOSTNAME}))"
279279
host = request.headers.pop(HEADER_HOST_ORIGINAL, None)
280280
host = host or request.headers.get("Host") or ""
281-
match = re.match(rf"(.+)\.s3\.{regex_base_domain}", host)
281+
match = re.match(rf"(.+)\.s3\..*{regex_base_domain}", host)
282282
if match:
283283
# prepend the bucket name (extracted from the host) to the path of the request (path-based addressing)
284284
request.path = f"/{match.group(1)}{request.path}"

aws-replicator/tests/test_proxy_requests.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def _add_header(request, **kwargs):
6565
url = urlparse(request.url)
6666
match = re.match(r"(.+)\.s3\.localhost\.localstack\.cloud", url.netloc)
6767
if match:
68-
request.headers.add_header("host", f"{match.group(1)}.s3.amazonaws.com")
68+
request.headers.add_header("host", f"{match.group(1)}.s3.us-east-1.amazonaws.com")
6969

7070
s3_client.meta.events.register_first("before-sign.*.*", _add_header)
7171

miniflare/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ clean:
1818
rm -rf *.egg-info/
1919

2020
lint: ## Run code linter to check code style
21-
$(VENV_RUN); python -m pflake8 --show-source --ignore=E501
21+
$(VENV_RUN); python -m pflake8 --show-source --ignore=E501 --exclude .venv,build
2222

2323
format: ## Run black and isort code formatter
24-
$(VENV_RUN); python -m isort .; python -m black .
24+
$(VENV_RUN); python -m isort .; python -m black miniflare
2525

2626
install: venv
2727
$(VENV_RUN); python -m pip install -e .[dev]

miniflare/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Hello World!
3434

3535
## Change Log
3636

37+
* `0.1.2`: Pin wrangler version to fix hanging miniflare invocations; fix encoding headers for invocation responses
3738
* `0.1.1`: Adapt for LocalStack v3.0
3839
* `0.1.0`: Upgrade to Miniflare 3.0
3940
* `0.0.1`: Initial version.

miniflare/miniflare/cloudflare_api.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,19 @@ def handle_invocation(request: Request, path: str, script_name: str, port: str):
4242
port = SCRIPT_SERVERS[script_name].port
4343
response = requests.request(
4444
method=request.method,
45-
url=f"http://localhost:{port}{request.path}",
45+
url=f"http://localhost:{port}/{path}",
4646
data=request.get_data(),
4747
)
4848
result = Response()
4949
result.status_code = response.status_code
5050
result.set_data(response.content)
51-
result.headers.update(dict(response.headers))
51+
headers = dict(response.headers)
52+
if headers.get('Transfer-Encoding') == 'chunked':
53+
headers.pop('Transfer-Encoding')
54+
if headers.get('Content-Encoding') == 'gzip':
55+
headers.pop('Content-Encoding')
56+
LOG.debug("Miniflare invocation response headers/body: %s / %s", headers, response.content)
57+
result.headers.update(headers)
5258
return result
5359

5460

@@ -154,9 +160,11 @@ def handle_services(request: Request, account_id: str, service_name: str) -> dic
154160
}
155161
)
156162

163+
157164
def handle_standard(request: Request, account_id: str) -> dict:
158165
return _wrap({})
159166

167+
160168
def handle_subdomain(request: Request, account_id: str) -> dict:
161169
return _wrap({})
162170

miniflare/miniflare/extension.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626

2727
LOG = logging.getLogger(__name__)
2828

29-
# identifier for default version installed by package installer
30-
DEFAULT_VERSION = "latest"
29+
# Identifier for default version of `wrangler` installed by package installer.
30+
# Note: Currently pinned to 3.1.0, as newer versions make the invocations hang in the LS container
31+
WRANGLER_VERSION = "3.1.0"
3132

3233

3334
class MiniflareExtension(Extension):
@@ -36,6 +37,10 @@ class MiniflareExtension(Extension):
3637
def update_gateway_routes(self, router: http.Router[http.RouteHandler]):
3738
from miniflare.config import HANDLER_PATH_MINIFLARE
3839

40+
logging.getLogger("miniflare").setLevel(
41+
logging.DEBUG if config.DEBUG else logging.INFO
42+
)
43+
3944
LOG.info("miniflare: adding routes to activate extension")
4045
all_methods = ["GET", "POST", "PUT", "DELETE"]
4146

@@ -83,7 +88,7 @@ def __init__(self, script: WorkerScript, port: int):
8388
super().__init__(port)
8489

8590
def do_run(self):
86-
root_dir = os.path.join(config.dirs.var_libs, "miniflare", DEFAULT_VERSION)
91+
root_dir = os.path.join(config.dirs.var_libs, "miniflare", WRANGLER_VERSION)
8792
wrangler_bin = os.path.join(root_dir, "node_modules", ".bin", "wrangler")
8893

8994
# add global aliases, and variable bindings
@@ -102,7 +107,6 @@ def do_run(self):
102107
cmd = [
103108
wrangler_bin,
104109
"dev",
105-
"--experimental-local",
106110
"--port",
107111
str(self.port),
108112
script_path_final,
@@ -115,7 +119,7 @@ def do_run(self):
115119

116120
class MiniflareInstaller(ExecutableInstaller):
117121
def __init__(self):
118-
super().__init__("miniflare", version=DEFAULT_VERSION)
122+
super().__init__("miniflare", version=WRANGLER_VERSION)
119123

120124
def _get_install_marker_path(self, install_dir: str) -> str:
121125
# force re-install on every start (requires npm package + system libs like libc++)
@@ -134,5 +138,4 @@ def _install(self, target: InstallTarget) -> None:
134138
run(["apt", "install", "-y", "libc++-dev"])
135139

136140
# install npm package
137-
run(["npm", "install", "--prefix", target_dir, "wrangler"])
138-
run(["npm", "install", "--prefix", target_dir, "@miniflare/tre"])
141+
run(["npm", "install", "--prefix", target_dir, f"wrangler@{WRANGLER_VERSION}"])

miniflare/setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = localstack-extension-miniflare
3-
version = 0.1.2
3+
version = 0.1.3
44
summary = LocalStack Extension: Miniflare
55
description = This extension makes Miniflare (dev environment for Cloudflare workers) available directly in LocalStack
66
long_description = file: README.md

0 commit comments

Comments
 (0)