Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix package.py commands after :zip not being executed #606

Merged
merged 7 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
}