Skip to content

Commit 5ce931c

Browse files
committed
feat: Support installing dependencies with poetry
1 parent c3a1c38 commit 5ce931c

File tree

10 files changed

+322
-15
lines changed

10 files changed

+322
-15
lines changed

examples/build-package/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ Note that this example may create resources which cost money. Run `terraform des
3636
| <a name="module_lambda_function_from_package"></a> [lambda\_function\_from\_package](#module\_lambda\_function\_from\_package) | ../../ | n/a |
3737
| <a name="module_lambda_layer"></a> [lambda\_layer](#module\_lambda\_layer) | ../../ | n/a |
3838
| <a name="module_lambda_layer_pip_requirements"></a> [lambda\_layer\_pip\_requirements](#module\_lambda\_layer\_pip\_requirements) | ../.. | n/a |
39+
| <a name="module_lambda_layer_poetry"></a> [lambda\_layer\_poetry](#module\_lambda\_layer\_poetry) | ../../ | n/a |
3940
| <a name="module_package_dir"></a> [package\_dir](#module\_package\_dir) | ../../ | n/a |
4041
| <a name="module_package_dir_pip_dir"></a> [package\_dir\_pip\_dir](#module\_package\_dir\_pip\_dir) | ../../ | n/a |
42+
| <a name="module_package_dir_poetry"></a> [package\_dir\_poetry](#module\_package\_dir\_poetry) | ../../ | n/a |
4143
| <a name="module_package_dir_without_pip_install"></a> [package\_dir\_without\_pip\_install](#module\_package\_dir\_without\_pip\_install) | ../../ | n/a |
4244
| <a name="module_package_file"></a> [package\_file](#module\_package\_file) | ../../ | n/a |
4345
| <a name="module_package_file_with_pip_requirements"></a> [package\_file\_with\_pip\_requirements](#module\_package\_file\_with\_pip\_requirements) | ../../ | n/a |

examples/build-package/main.tf

Lines changed: 78 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,63 @@ resource "random_pet" "this" {
1717
# Build packages
1818
#################
1919

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

2424
create_function = false
2525

26-
runtime = "python3.8"
27-
source_path = "${path.module}/../fixtures/python3.8-app1"
26+
build_in_docker = true
27+
runtime = "python3.8"
28+
source_path = "${path.module}/../fixtures/python3.8-app1"
29+
artifacts_dir = "${path.root}/builds/package_dir/"
2830
}
2931

30-
# 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
32+
# 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
3133
module "package_dir_pip_dir" {
3234
source = "../../"
3335

3436
create_function = false
3537

36-
runtime = "python3.8"
38+
build_in_docker = true
39+
runtime = "python3.8"
3740
source_path = [{
3841
path = "${path.module}/../fixtures/python3.8-app1"
3942
pip_tmp_dir = "${path.cwd}/../fixtures"
4043
pip_requirements = "${path.module}/../fixtures/python3.8-app1/requirements.txt"
4144
}]
45+
artifacts_dir = "${path.root}/builds/package_dir_pip_dir/"
46+
}
47+
48+
# Create zip-archive of a single directory where "poetry install" will also be executed
49+
module "package_dir_poetry" {
50+
source = "../../"
51+
52+
create_function = false
53+
54+
build_in_docker = true
55+
runtime = "python3.8"
56+
source_path = [
57+
{
58+
path = "${path.module}/../fixtures/python3.8-app-poetry"
59+
patterns = [
60+
"!(.*/)*__pycache__/.*",
61+
"!_distutils_hack/.*",
62+
"!.pytest_cache/.*",
63+
"!.venv/.*",
64+
"!_virtualenv.pth",
65+
"!_virtualenv.py",
66+
"!distutils-precedence.pth",
67+
"!easy_install.py",
68+
"!(pip|pip-.*)(\\.virtualenv|/.*)",
69+
"!(pkg_resources|pkg_resources-.*)(\\.virtualenv|/.*)",
70+
"!(setuptools|setuptools-.*)(\\.virtualenv|/.*)",
71+
"!(wheel|wheel-.*)(\\.virtualenv|/.*)",
72+
]
73+
poetry_install = true
74+
}
75+
]
76+
artifacts_dir = "${path.root}/builds/package_dir_poetry/"
4277
}
4378

4479
# Create zip-archive of a single directory without running "pip install" (which is default for python runtime)
@@ -241,6 +276,44 @@ module "lambda_layer" {
241276
build_in_docker = true
242277
runtime = "python3.8"
243278
docker_file = "${path.module}/../fixtures/python3.8-app1/docker/Dockerfile"
279+
docker_image = "lambci/lambda:build-python3.8"
280+
artifacts_dir = "${path.root}/builds/lambda_layer/"
281+
}
282+
283+
module "lambda_layer_poetry" {
284+
source = "../../"
285+
286+
create_layer = true
287+
layer_name = "${random_pet.this.id}-layer-poetry-dockerfile"
288+
compatible_runtimes = ["python3.8"]
289+
290+
source_path = [
291+
{
292+
path = "${path.module}/../fixtures/python3.8-app-poetry"
293+
patterns = [
294+
"!(.*/)*__pycache__/.*",
295+
"!_distutils_hack/.*",
296+
"!.pytest_cache/.*",
297+
"!.venv/.*",
298+
"!_virtualenv.pth",
299+
"!_virtualenv.py",
300+
"!distutils-precedence.pth",
301+
"!easy_install.py",
302+
"!(pip|pip-.*)(\\.virtualenv|/.*)",
303+
"!(pkg_resources|pkg_resources-.*)(\\.virtualenv|/.*)",
304+
"!(setuptools|setuptools-.*)(\\.virtualenv|/.*)",
305+
"!(wheel|wheel-.*)(\\.virtualenv|/.*)",
306+
]
307+
poetry_install = true
308+
}
309+
]
310+
hash_extra = "extra-hash-to-prevent-conflicts-with-module.package_dir"
311+
312+
build_in_docker = true
313+
runtime = "python3.8"
314+
docker_file = "${path.module}/../fixtures/python3.8-poetry/docker/Dockerfile"
315+
docker_image = "lambci/lambda:build-python3.8"
316+
artifacts_dir = "${path.root}/builds/lambda_layer_poetry/"
244317
}
245318

246319
#######################
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This file should not be included in archive.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
def lambda_handler(event, context):
2+
print("Hello from app1!")
3+
4+
return event

examples/fixtures/python3.8-app-poetry/poetry.lock

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[tool.poetry]
2+
name = "python3.8-app-poetry"
3+
version = "0.1.0"
4+
description = ""
5+
authors = ["Your Name <you@example.com>"]
6+
7+
[tool.poetry.dependencies]
8+
python = "^3.6"
9+
colorful = "^0.5.4"
10+
11+
[tool.poetry.dev-dependencies]
12+
13+
[build-system]
14+
requires = ["poetry-core>=1.0.0"]
15+
build-backend = "poetry.core.masonry.api"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[build-system]
2+
build-backend = "dummy"

0 commit comments

Comments
 (0)