Skip to content

Commit

Permalink
fix: Fix package.py commands after :zip not being executed (#606)
Browse files Browse the repository at this point in the history
Co-authored-by: Anton Babenko <[email protected]>
  • Loading branch information
mleziva and antonbabenko authored Aug 23, 2024
1 parent a84d8af commit 801e69c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/build-package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Note that this example may create resources which cost money. Run `terraform des
| <a name="module_lambda_layer"></a> [lambda\_layer](#module\_lambda\_layer) | ../../ | n/a |
| <a name="module_lambda_layer_pip_requirements"></a> [lambda\_layer\_pip\_requirements](#module\_lambda\_layer\_pip\_requirements) | ../.. | n/a |
| <a name="module_lambda_layer_poetry"></a> [lambda\_layer\_poetry](#module\_lambda\_layer\_poetry) | ../../ | n/a |
| <a name="module_npm_package_with_commands_and_patterns"></a> [npm\_package\_with\_commands\_and\_patterns](#module\_npm\_package\_with\_commands\_and\_patterns) | ../../ | n/a |
| <a name="module_package_dir"></a> [package\_dir](#module\_package\_dir) | ../../ | n/a |
| <a name="module_package_dir_pip_dir"></a> [package\_dir\_pip\_dir](#module\_package\_dir\_pip\_dir) | ../../ | n/a |
| <a name="module_package_dir_poetry"></a> [package\_dir\_poetry](#module\_package\_dir\_poetry) | ../../ | n/a |
Expand Down
25 changes: 25 additions & 0 deletions examples/build-package/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,31 @@ module "package_with_commands_and_patterns" {
]
}

# Some use cases might require the production packages are deployed while maintaining local node_modules folder
# This example saves the node_modules folder by moving it to an ignored directory
# After the zip file is created with production node_modules, the dev node_modules folder is restored
module "npm_package_with_commands_and_patterns" {
source = "../../"

create_function = false

runtime = "nodejs18.x"
source_path = [
{
path = "${path.module}/../fixtures/node-app"
commands = [
"[ ! -d node_modules ] || mv node_modules node_modules_temp",
"npm install --production",
":zip",
"rm -rf node_modules",
"[ ! -d node_modules_temp ] || mv node_modules_temp node_modules",
]
patterns = [
"!node_modules_temp/.*"
]
}
]
}
# Create zip-archive with various sources and patterns.
# Note, that it is possible to write comments in patterns.
module "package_with_patterns" {
Expand Down
3 changes: 3 additions & 0 deletions package.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,9 @@ def commands_step(path, commands):
)
else:
batch.append(c)
if batch:
step("sh", path, "\n".join(batch))
batch.clear()

for claim in claims:
if isinstance(claim, str):
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/node-app/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// test
16 changes: 16 additions & 0 deletions tests/fixtures/node-app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
},
"devDependencies": {
"axios": "^1.7.3"
}
}

0 comments on commit 801e69c

Please sign in to comment.