Skip to content

Commit 5c95844

Browse files
committed
optionally allow list of additional CLI options to send to pip install
this is helpful for cross-platform builds such as packaging in an alpine context for an al2 runtime context
1 parent 84dfbfd commit 5c95844

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

examples/build-package/main.tf

+18
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,24 @@ module "package_file_with_pip_requirements" {
163163
]
164164
}
165165

166+
# Create zip-archive which contains:
167+
# 1. A single file - index.py
168+
# 2. Run "pip install" with specified requirements.txt with additional options CLI --only-binary=:all: --platform manylinux2014_x86_64
169+
module "package_file_with_pip_requirements_and_pip_additional_options" {
170+
source = "../../"
171+
172+
create_function = false
173+
174+
runtime = "python3.12"
175+
pip_additional_options = ["-only-binary=:all:", "--platform", "manylinux2014_x86_64"]
176+
source_path = [
177+
"${path.module}/../fixtures/python-app1/index.py",
178+
{
179+
pip_requirements = "${path.module}/../fixtures/python-app1/requirements.txt"
180+
}
181+
]
182+
}
183+
166184
# Create zip-archive which contains:
167185
# 1. A single file - index.py
168186
# 2. Content of directory "dir2"

package.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,7 @@ def install_pip_requirements(query, requirements_file, tmp_dir):
10601060
artifacts_dir = query.artifacts_dir
10611061
docker = query.docker
10621062
temp_dir = query.temp_dir
1063+
pip_additional_options = query.pip_additional_options
10631064
docker_image_tag_id = None
10641065

10651066
if docker:
@@ -1125,7 +1126,7 @@ def install_pip_requirements(query, requirements_file, tmp_dir):
11251126
"--prefix=",
11261127
"--target=.",
11271128
"--requirement={}".format(requirements_filename),
1128-
]
1129+
] + pip_additional_options
11291130
if docker:
11301131
with_ssh_agent = docker.with_ssh_agent
11311132
pip_cache_dir = docker.docker_pip_cache

package.tf

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ data "external" "archive_prepare" {
4040
)
4141

4242
recreate_missing_package = var.recreate_missing_package
43+
44+
pip_additional_options = jsonencode(var.pip_additional_options)
4345
}
4446
}
4547

variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,12 @@ variable "trigger_on_package_timestamp" {
806806
default = true
807807
}
808808

809+
variable "pip_additional_options" {
810+
description = "Additional options to pass to the pip install command (e.g. to platform, etc.)"
811+
type = list(string)
812+
default = []
813+
}
814+
809815
############################################
810816
# Lambda Advanced Logging Settings
811817
############################################

0 commit comments

Comments
 (0)