Skip to content

Commit

Permalink
fix: Checks for npm instead of runtime when building nodejs packa…
Browse files Browse the repository at this point in the history
…ges (#364)

Co-authored-by: Anton Babenko <anton@antonbabenko.com>
  • Loading branch information
lorengordon and antonbabenko committed Oct 31, 2022
1 parent eb4ca20 commit 682052c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
6 changes: 3 additions & 3 deletions examples/build-package/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ module "package_with_docker" {
docker_pip_cache = true
docker_with_ssh_agent = true
# docker_file = "${path.module}/../fixtures/python3.8-app1/docker/Dockerfile"
docker_build_root = "${path.module}/../../docker"
docker_image = "public.ecr.aws/sam/build-python3.8"
docker_build_root = "${path.module}/../fixtures/python3.8-app1/docker"
docker_image = "public.ecr.aws/sam/build-python3.8:latest"
}

# Create zip-archive of a single directory where "npm install" will also be executed (default for nodejs runtime)
Expand Down Expand Up @@ -278,7 +278,7 @@ module "lambda_layer" {

build_in_docker = true
runtime = "python3.8"
docker_image = "public.ecr.aws/sam/build-python3.8"
docker_image = "public.ecr.aws/sam/build-python3.8:latest"
docker_file = "${path.module}/../fixtures/python3.8-app1/docker/Dockerfile"
}

Expand Down
13 changes: 7 additions & 6 deletions package.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,7 @@ def plan(self, source_path, query):
hash = source_paths.append

def pip_requirements_step(path, prefix=None, required=False, tmp_dir=None):
command = runtime
requirements = path
if os.path.isdir(path):
requirements = os.path.join(path, 'requirements.txt')
Expand All @@ -657,16 +658,17 @@ def pip_requirements_step(path, prefix=None, required=False, tmp_dir=None):
raise RuntimeError(
'File not found: {}'.format(requirements))
else:
if not query.docker and not shutil.which(runtime):
if not query.docker and not shutil.which(command):
raise RuntimeError(
"Python interpreter version equal "
"to defined lambda runtime ({}) should be "
"available in system PATH".format(runtime))
"available in system PATH".format(command))

step('pip', runtime, requirements, prefix, tmp_dir)
hash(requirements)

def npm_requirements_step(path, prefix=None, required=False, tmp_dir=None):
command = "npm"
requirements = path
if os.path.isdir(path):
requirements = os.path.join(path, 'package.json')
Expand All @@ -675,11 +677,10 @@ def npm_requirements_step(path, prefix=None, required=False, tmp_dir=None):
raise RuntimeError(
'File not found: {}'.format(requirements))
else:
if not query.docker and not shutil.which(runtime):
if not query.docker and not shutil.which(command):
raise RuntimeError(
"Nodejs interpreter version equal "
"to defined lambda runtime ({}) should be "
"available in system PATH".format(runtime))
"Nodejs package manager ({}) should be "
"available in system PATH".format(command))

step('npm', runtime, requirements, prefix, tmp_dir)
hash(requirements)
Expand Down

0 comments on commit 682052c

Please sign in to comment.