Skip to content

Commit

Permalink
fix: lambda zip shuold be created from code ci
Browse files Browse the repository at this point in the history
  • Loading branch information
notdodo committed Oct 13, 2024
1 parent 78d561d commit 664359d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 38 deletions.
4 changes: 2 additions & 2 deletions app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ build-layer-zip:
poetry install --only main --sync
cd ..; mkdir -p ./dist/lambda-layer/python
cd ..; cp -r -p ./app/.venv/lib ./dist/lambda-layer/python/
cd ../dist/lambda-layer/python; rm -rf .venv .mypy_cache .ruff_cache .env Makefile poetry.lock pyproject.toml standalone.py r
cd ../dist/lambda-layer/python; rm -rf .venv .mypy_cache .ruff_cache .env Makefile poetry.lock pyproject.toml standalone.py fetcher
cd ../dist/lambda-layer/python; zip -q -r -D -X -9 -A ../../lambda-layer.zip ../

build-lambda-zip: build-layer-zip
cd ..; mkdir -p ./dist/lambda-package/
cd ..; cp -r -p ./app/ ./dist/lambda-package/
cd ../dist/lambda-package/; rm -rf .venv .mypy_cache .ruff_cache .env Makefile poetry.lock pyproject.toml standalone.py r
cd ../dist/lambda-package/; rm -rf .venv .mypy_cache .ruff_cache .env Makefile poetry.lock pyproject.toml standalone.py fetcher
cd ../dist/lambda-package/; zip -q -r -D -X -9 -A ../lambda.zip .

format: ## Format repository code
Expand Down
38 changes: 2 additions & 36 deletions pulumi/lambda_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,6 @@ class LambdaZip:
zip_sha256: pulumi.Output[str]


def create_lambda_zip(resource_prefix: str) -> LambdaZip:
"""
Check changes on application folder to update the ZIP file for the lambda deployment
"""
dist_folder = "lambda-package"
output_file = "lambda.zip"
local.run(
dir="../",
command=f"""
mkdir -p ./dist/{dist_folder}; \
cp -r -p ./app/ ./dist/{dist_folder}/""",
)

local.run(
dir=f"../dist/{dist_folder}",
command=f"""rm -rf .venv .mypy_cache .ruff_cache .env Makefile poetry.lock pyproject.toml standalone.py r; \
zip -q -r -D -X -9 -A ../{output_file} .""",
)

sha256_zip = local.Command(
f"{resource_prefix}-sha256-lambda-zip",
dir="../dist/",
create=f"sha256sum {output_file} | cut -d ' ' -f1",
update=f"sha256sum {output_file} | cut -d ' ' -f1",
triggers=[
pulumi.FileArchive(f"../dist/{output_file}"),
],
)

return LambdaZip(
zip_path=pulumi.FileArchive("../dist/lambda.zip"), zip_sha256=sha256_zip.stdout
)


def create_lambda_layer(resource_prefix: str) -> aws.lambda_.LayerVersion:
"""
Check changes on application folder to update the ZIP file for the lambda deployment
Expand Down Expand Up @@ -91,9 +57,9 @@ def create_lambda_layer(resource_prefix: str) -> aws.lambda_.LayerVersion:
f"{resource_prefix}-cleanup-layer",
dir=f"../dist/{dist_folder}",
create=(
"rm -rf .venv .mypy_cache .ruff_cache .env Makefile poetry.lock pyproject.toml standalone.py r"
"rm -rf .venv .mypy_cache .ruff_cache .env Makefile poetry.lock pyproject.toml standalone.py fetcher"
),
update="rm -rf .venv .mypy_cache .ruff_cache .env Makefile poetry.lock pyproject.toml standalone.py r",
update="rm -rf .venv .mypy_cache .ruff_cache .env Makefile poetry.lock pyproject.toml standalone.py fetcher",
triggers=[
pulumi.FileAsset("../app/poetry.lock"),
copy_libs.stdout,
Expand Down

0 comments on commit 664359d

Please sign in to comment.