From c7268cad95e286c93ad47b32b809ddf94ef3928b Mon Sep 17 00:00:00 2001 From: Matt Wright Date: Thu, 1 Feb 2024 17:04:09 -0500 Subject: [PATCH] Use multi-stage build to compile javascript --- CI.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/CI.py b/CI.py index 426f692..9c8ca48 100644 --- a/CI.py +++ b/CI.py @@ -6,9 +6,25 @@ async def test(): async with dagger.Connection(dagger.Config(log_output=sys.stderr)) as client: - source = client.host().directory( + source_code = client.host().directory( ".", exclude=[".git", "node_modules", ".venv", "__ci__.py"] ) + + javascript = ( + client.container() + .from_("node:16.15.0-slim") + .with_workdir("/src") + .with_file("/src/package.json", client.host().file("package.json")) + .with_file( + "/src/package-lock.json", client.host().file("package-lock.json") + ) + .with_exec(["npm", "install"]) + .with_directory("/src", source_code) + .with_exec(["npx", "webpack", "--mode", "production"]) + ) + + await javascript.sync() + redis = client.container().from_("redis:7").with_exposed_port(6379).as_service() python = ( @@ -32,7 +48,11 @@ async def test(): .with_exec(["poetry", "install", "--only", "playwright"]) .with_exec(["poetry", "run", "playwright", "install-deps"]) .with_exec(["poetry", "run", "playwright", "install", "chromium"]) - .with_directory("/src", source) + .with_directory("/src", source_code) + .with_directory( + "/src/example_app/static/bundles", + javascript.directory("/src/example_app/static/bundles"), + ) .with_exec(["poetry", "install", "--without", "playwright"]) .with_exec(["poetry", "run", "pytest"]) )