Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/build-package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ Note that this example may create resources which cost money. Run `terraform des
| <a name="module_lambda_function_from_package"></a> [lambda\_function\_from\_package](#module\_lambda\_function\_from\_package) | ../../ | n/a |
| <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_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 |
| <a name="module_package_dir_without_pip_install"></a> [package\_dir\_without\_pip\_install](#module\_package\_dir\_without\_pip\_install) | ../../ | n/a |
| <a name="module_package_file"></a> [package\_file](#module\_package\_file) | ../../ | n/a |
| <a name="module_package_file_with_pip_requirements"></a> [package\_file\_with\_pip\_requirements](#module\_package\_file\_with\_pip\_requirements) | ../../ | n/a |
Expand Down
83 changes: 78 additions & 5 deletions examples/build-package/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,63 @@ resource "random_pet" "this" {
# Build packages
#################

# Create zip-archive of a single directory where "pip install" will also be executed (default for python runtime)
# Create zip-archive of a single directory where "pip install" will also be executed (default for python runtime with requirements.txt present)
module "package_dir" {
source = "../../"

create_function = false

runtime = "python3.8"
source_path = "${path.module}/../fixtures/python3.8-app1"
build_in_docker = true
runtime = "python3.8"
source_path = "${path.module}/../fixtures/python3.8-app1"
artifacts_dir = "${path.root}/builds/package_dir/"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specifying different artifacts_dir for each module makes it easier to check lambda packages content.

}

# Create zip-archive of a single directory where "pip install" will also be executed (default for python runtime) and set temporary directory for pip install
# Create zip-archive of a single directory where "pip install" will also be executed (default for python runtime with requirements.txt present) and set temporary directory for pip install
module "package_dir_pip_dir" {
source = "../../"

create_function = false

runtime = "python3.8"
build_in_docker = true
runtime = "python3.8"
source_path = [{
path = "${path.module}/../fixtures/python3.8-app1"
pip_tmp_dir = "${path.cwd}/../fixtures"
pip_requirements = "${path.module}/../fixtures/python3.8-app1/requirements.txt"
}]
artifacts_dir = "${path.root}/builds/package_dir_pip_dir/"
}

# Create zip-archive of a single directory where "poetry install" will also be executed
module "package_dir_poetry" {
source = "../../"

create_function = false

build_in_docker = true
runtime = "python3.8"
source_path = [
{
path = "${path.module}/../fixtures/python3.8-app-poetry"
patterns = [
"!(.*/)*__pycache__/.*",
"!_distutils_hack/.*",
"!.pytest_cache/.*",
"!.venv/.*",
"!_virtualenv.pth",
"!_virtualenv.py",
"!distutils-precedence.pth",
"!easy_install.py",
"!(pip|pip-.*)(\\.virtualenv|/.*)",
"!(pkg_resources|pkg_resources-.*)(\\.virtualenv|/.*)",
"!(setuptools|setuptools-.*)(\\.virtualenv|/.*)",
"!(wheel|wheel-.*)(\\.virtualenv|/.*)",
Comment on lines +64 to +71
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is required as poetry does not support a --target parameter like pip so everything is put in the same directory of the created virtualenv.

]
poetry_install = true
}
]
artifacts_dir = "${path.root}/builds/package_dir_poetry/"
}

# Create zip-archive of a single directory without running "pip install" (which is default for python runtime)
Expand Down Expand Up @@ -241,6 +276,44 @@ module "lambda_layer" {
build_in_docker = true
runtime = "python3.8"
docker_file = "${path.module}/../fixtures/python3.8-app1/docker/Dockerfile"
docker_image = "lambci/lambda:build-python3.8"
artifacts_dir = "${path.root}/builds/lambda_layer/"
}

module "lambda_layer_poetry" {
source = "../../"

create_layer = true
layer_name = "${random_pet.this.id}-layer-poetry-dockerfile"
compatible_runtimes = ["python3.8"]

source_path = [
{
path = "${path.module}/../fixtures/python3.8-app-poetry"
patterns = [
"!(.*/)*__pycache__/.*",
"!_distutils_hack/.*",
"!.pytest_cache/.*",
"!.venv/.*",
"!_virtualenv.pth",
"!_virtualenv.py",
"!distutils-precedence.pth",
"!easy_install.py",
"!(pip|pip-.*)(\\.virtualenv|/.*)",
"!(pkg_resources|pkg_resources-.*)(\\.virtualenv|/.*)",
"!(setuptools|setuptools-.*)(\\.virtualenv|/.*)",
"!(wheel|wheel-.*)(\\.virtualenv|/.*)",
]
poetry_install = true
}
]
hash_extra = "extra-hash-to-prevent-conflicts-with-module.package_dir"

build_in_docker = true
runtime = "python3.8"
docker_file = "${path.module}/../fixtures/python3.8-poetry/docker/Dockerfile"
docker_image = "lambci/lambda:build-python3.8"
artifacts_dir = "${path.root}/builds/lambda_layer_poetry/"
}

#######################
Expand Down
1 change: 1 addition & 0 deletions examples/fixtures/python3.8-app-poetry/ignore_please.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file should not be included in archive.
4 changes: 4 additions & 0 deletions examples/fixtures/python3.8-app-poetry/index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def lambda_handler(event, context):
print("Hello from app1!")

return event
33 changes: 33 additions & 0 deletions examples/fixtures/python3.8-app-poetry/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions examples/fixtures/python3.8-app-poetry/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[tool.poetry]
name = "python3.8-app-poetry"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]

[tool.poetry.dependencies]
python = "^3.6"
colorful = "^0.5.4"

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
2 changes: 2 additions & 0 deletions examples/fixtures/unittests/pyproject-unknown.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build-system]
build-backend = "dummy"
Loading