Skip to content

Commit 7d997b5

Browse files
author
Ryan Ragnell
committed
fix: Make quiet_archive_local_exec properly suppress Poetry/pip/npm output
- Pass quiet flag from Terraform to package.py via query data - Suppress stdout/stderr in Poetry, pip, and npm subprocess calls when quiet=true - Add example demonstrating quiet packaging functionality - Update documentation and apply pre-commit formatting fixes Fixes issue where quiet_archive_local_exec only affected Terraform's local-exec output but not the actual Poetry/pip/npm subprocess calls within package.py. Resolves #706
1 parent 1c3b16a commit 7d997b5

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

examples/build-package/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
Configuration in this directory creates deployment packages in a variety of combinations.
44

5+
This example demonstrates various packaging scenarios including:
6+
- Python packages with pip requirements
7+
- Poetry-based Python packages
8+
- Node.js packages with npm
9+
- Docker-based builds
10+
- **Quiet packaging** - suppressing Poetry/pip/npm output during builds using `quiet_archive_local_exec = true`
11+
512
Look into [Runtimes Examples](https://github.com/terraform-aws-modules/terraform-aws-lambda/tree/master/examples/runtimes) for more ways to build and deploy AWS Lambda Functions using supported runtimes (Rust, Go, Java).
613

714
## Usage

examples/build-package/main.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,24 @@ module "package_dir_poetry_no_docker" {
119119
artifacts_dir = "${path.root}/builds/package_dir_poetry/"
120120
}
121121

122+
# Create zip-archive with Poetry dependencies and demonstrate quiet packaging output
123+
module "package_dir_poetry_quiet" {
124+
source = "../../"
125+
126+
create_function = false
127+
128+
runtime = "python3.12"
129+
130+
source_path = [
131+
{
132+
path = "${path.module}/../fixtures/python-app-poetry"
133+
poetry_install = true
134+
}
135+
]
136+
artifacts_dir = "${path.root}/builds/package_dir_poetry_quiet/"
137+
quiet_archive_local_exec = true # Suppress Poetry/pip output during packaging
138+
}
139+
122140
# Create zip-archive of a single directory without running "pip install" (which is default for python runtime)
123141
module "package_dir_without_pip_install" {
124142
source = "../../"

package.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,11 @@ def install_pip_requirements(query, requirements_file, tmp_dir):
11701170
cmd_log.info(shlex_join(pip_command))
11711171
log_handler and log_handler.flush()
11721172
try:
1173-
check_call(pip_command, env=subproc_env)
1173+
if query.quiet:
1174+
check_call(pip_command, env=subproc_env,
1175+
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
1176+
else:
1177+
check_call(pip_command, env=subproc_env)
11741178
except FileNotFoundError as e:
11751179
raise RuntimeError(
11761180
"Python interpreter version equal "
@@ -1346,7 +1350,11 @@ def copy_file_to_target(file, temp_dir):
13461350
cmd_log.info(poetry_commands)
13471351
log_handler and log_handler.flush()
13481352
for poetry_command in poetry_commands:
1349-
check_call(poetry_command, env=subproc_env)
1353+
if query.quiet:
1354+
check_call(poetry_command, env=subproc_env,
1355+
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
1356+
else:
1357+
check_call(poetry_command, env=subproc_env)
13501358

13511359
os.remove(pyproject_target_file)
13521360
if poetry_lock_target_file:
@@ -1443,7 +1451,11 @@ def install_npm_requirements(query, requirements_file, tmp_dir):
14431451
cmd_log.info(shlex_join(npm_command))
14441452
log_handler and log_handler.flush()
14451453
try:
1446-
check_call(npm_command, env=subproc_env)
1454+
if query.quiet:
1455+
check_call(npm_command, env=subproc_env,
1456+
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
1457+
else:
1458+
check_call(npm_command, env=subproc_env)
14471459
except FileNotFoundError as e:
14481460
raise RuntimeError(
14491461
"Nodejs interpreter version equal "

package.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ data "external" "archive_prepare" {
4040
)
4141

4242
recreate_missing_package = var.recreate_missing_package
43+
quiet = var.quiet_archive_local_exec
4344
}
4445
}
4546

0 commit comments

Comments
 (0)