diff --git a/.circleci/config.yml b/.circleci/config.yml index f96189a..332acf2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -29,7 +29,7 @@ jobs: - run: name: Build lambdas command: - bin/build_lambdas.sh + deployment/build-lambdas.sh - run: name: Deploy infrastructure diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index edefbb3..9e1afa4 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -62,7 +62,7 @@ jobs: - name: Build lambdas run: | - bin/build_lambdas.sh + deployment/build-lambdas.sh - name: Deploy infrastructure run: | @@ -136,7 +136,7 @@ jobs: - name: Build lambdas run: | - bin/build_lambdas.sh + deployment/build-lambdas.sh - name: Deploy infrastructure run: | diff --git a/.github/workflows/preview_create.yml b/.github/workflows/preview_create.yml index 5ba27fc..6c0d96c 100644 --- a/.github/workflows/preview_create.yml +++ b/.github/workflows/preview_create.yml @@ -41,4 +41,4 @@ jobs: preview-cmd: | # Add your custom deployment commands here. # Below is an example for the Image resizer application. - bin/build_lambdas.sh && deployment/awslocal/deploy.sh + deployment/build-lambdas.sh && deployment/awslocal/deploy.sh diff --git a/.github/workflows/test_cloudpods.yml b/.github/workflows/test_cloudpods.yml index 04e8b04..95689ee 100644 --- a/.github/workflows/test_cloudpods.yml +++ b/.github/workflows/test_cloudpods.yml @@ -48,7 +48,7 @@ jobs: - name: Deploy Infrastructure (Example) run: | - bin/build_lambdas.sh && deployment/awslocal/deploy.sh + deployment/build-lambdas.sh && deployment/awslocal/deploy.sh - name: Export LocalStack State File id: export_state diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5284e8c..b8dd57f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -57,7 +57,7 @@ deploy: - .github/* - when: always script: - - ./bin/build_lambdas.sh + - ./deployment/build-lambdas.sh - ./deployment/awslocal/deploy.sh - mkdir -p /usr/lib/localstack - localstack state export ls-state-pod.zip diff --git a/Makefile b/Makefile index 12c6636..73a8c2f 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ install: ## Build the Lambda functions build-lambdas: @echo "Building the Lambda functions..." - bash -c "source venv/bin/activate && bin/build_lambdas.sh" + bash -c "source venv/bin/activate && deployment/build-lambdas.sh" @echo "Lambda functions built successfully." ## Deploy the application locally using `awslocal`, a wrapper for the AWS CLI diff --git a/README.md b/README.md index 40048a0..15e0f97 100644 --- a/README.md +++ b/README.md @@ -71,10 +71,16 @@ localstack auth set-token localstack start ``` +Before deploying the sample application, you need to build the Lambda functions. Run the following command: + +```shell +deployment/build-lambdas.sh +``` + To deploy the sample application, run the following command: ```shell -bin/deploy.sh +deployment/awslocal/deploy.sh ``` The output will show the Lambda function URLs that you can use in the web application: diff --git a/buildspec.yml b/buildspec.yml index 8b1471f..44b3de2 100644 --- a/buildspec.yml +++ b/buildspec.yml @@ -25,7 +25,7 @@ phases: - localstack start -d pre_build: commands: - - bin/build_lambdas.sh + - deployment/build-lambdas.sh - deployment/awslocal/deploy.sh build: commands: diff --git a/deployment/build-lambdas.sh b/deployment/build-lambdas.sh old mode 100644 new mode 100755 index 55e5f11..4b1810d --- a/deployment/build-lambdas.sh +++ b/deployment/build-lambdas.sh @@ -1,15 +1,28 @@ #!/bin/bash -BASE_DIR="lambdas" -LAMBDA_DIRS=("presign" "list" "resize") - -for dir in "${LAMBDA_DIRS[@]}"; do - LAMBDA_PATH="$BASE_DIR/$dir" - echo "Zipping Lambda function in $LAMBDA_PATH..." - if [ -d "$LAMBDA_PATH" ]; then - zip -r "$LAMBDA_PATH/lambda.zip" "$LAMBDA_PATH"/* - else - echo "Directory $LAMBDA_PATH not found!" - exit 1 - fi -done +(cd lambdas/presign; rm -f lambda.zip; zip lambda.zip handler.py) + +(cd lambdas/list; rm -f lambda.zip; zip lambda.zip handler.py) + +os=$(uname -s) +if [ "$os" == "Darwin" ]; then + ( + cd lambdas/resize + rm -rf libs lambda.zip + docker run --platform linux/x86_64 --rm -v "$PWD":/var/task "public.ecr.aws/sam/build-python3.11" /bin/sh -c "pip3 install -r requirements.txt -t libs; exit" + + cd libs && zip -r ../lambda.zip . && cd .. + zip lambda.zip handler.py + rm -rf libs + ) +else + ( + cd lambdas/resize + rm -rf package lambda.zip + mkdir package + pip3 install -r requirements.txt --platform manylinux2014_x86_64 --only-binary=:all: -t package + zip lambda.zip handler.py + cd package + zip -r ../lambda.zip *; + ) +fi