Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 64c6e71

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 64c6e71

File tree

4 files changed

+54
-3
lines changed

4 files changed

+54
-3
lines changed

‎examples/build-package/README.md‎

Lines changed: 8 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
@@ -44,6 +51,7 @@ Note that this example may create resources which cost money. Run `terraform des
4451
| <a name="module_package_dir_pip_dir"></a> [package\_dir\_pip\_dir](#module\_package\_dir\_pip\_dir) | ../../ | n/a |
4552
| <a name="module_package_dir_poetry"></a> [package\_dir\_poetry](#module\_package\_dir\_poetry) | ../../ | n/a |
4653
| <a name="module_package_dir_poetry_no_docker"></a> [package\_dir\_poetry\_no\_docker](#module\_package\_dir\_poetry\_no\_docker) | ../../ | n/a |
54+
| <a name="module_package_dir_poetry_quiet"></a> [package\_dir\_poetry\_quiet](#module\_package\_dir\_poetry\_quiet) | ../../ | n/a |
4755
| <a name="module_package_dir_with_npm_install"></a> [package\_dir\_with\_npm\_install](#module\_package\_dir\_with\_npm\_install) | ../../ | n/a |
4856
| <a name="module_package_dir_with_npm_install_lock_file"></a> [package\_dir\_with\_npm\_install\_lock\_file](#module\_package\_dir\_with\_npm\_install\_lock\_file) | ../../ | n/a |
4957
| <a name="module_package_dir_without_npm_install"></a> [package\_dir\_without\_npm\_install](#module\_package\_dir\_without\_npm\_install) | ../../ | n/a |

‎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: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,15 @@ 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(
1175+
pip_command,
1176+
env=subproc_env,
1177+
stdout=subprocess.DEVNULL,
1178+
stderr=subprocess.DEVNULL,
1179+
)
1180+
else:
1181+
check_call(pip_command, env=subproc_env)
11741182
except FileNotFoundError as e:
11751183
raise RuntimeError(
11761184
"Python interpreter version equal "
@@ -1346,7 +1354,15 @@ def copy_file_to_target(file, temp_dir):
13461354
cmd_log.info(poetry_commands)
13471355
log_handler and log_handler.flush()
13481356
for poetry_command in poetry_commands:
1349-
check_call(poetry_command, env=subproc_env)
1357+
if query.quiet:
1358+
check_call(
1359+
poetry_command,
1360+
env=subproc_env,
1361+
stdout=subprocess.DEVNULL,
1362+
stderr=subprocess.DEVNULL,
1363+
)
1364+
else:
1365+
check_call(poetry_command, env=subproc_env)
13501366

13511367
os.remove(pyproject_target_file)
13521368
if poetry_lock_target_file:
@@ -1443,7 +1459,15 @@ def install_npm_requirements(query, requirements_file, tmp_dir):
14431459
cmd_log.info(shlex_join(npm_command))
14441460
log_handler and log_handler.flush()
14451461
try:
1446-
check_call(npm_command, env=subproc_env)
1462+
if query.quiet:
1463+
check_call(
1464+
npm_command,
1465+
env=subproc_env,
1466+
stdout=subprocess.DEVNULL,
1467+
stderr=subprocess.DEVNULL,
1468+
)
1469+
else:
1470+
check_call(npm_command, env=subproc_env)
14471471
except FileNotFoundError as e:
14481472
raise RuntimeError(
14491473
"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)

AltStyle によって変換されたページ (->オリジナル) /