diff --git a/.github/workflows/release-lambda.yml b/.github/workflows/release-lambda.yml index 6621346..e11e6e9 100644 --- a/.github/workflows/release-lambda.yml +++ b/.github/workflows/release-lambda.yml @@ -21,11 +21,14 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 + - name: Install unzip + run: sudo apt-get update && sudo apt-get install -y unzip + - name: Build Docker Image and Create Lambda Layer run: | docker buildx build --platform linux/${{ matrix.architecture }} \ -t lambda-layer-builder:${{ matrix.architecture }} \ - --output type=docker \ + --load \ -f Dockerfile . docker create --name layer_builder lambda-layer-builder:${{ matrix.architecture }} docker cp layer_builder:/tmp/layer.zip layer-${{ matrix.architecture }}.zip diff --git a/Dockerfile b/Dockerfile index e9cfae8..62c6f3f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,52 +1,25 @@ -# Use the Amazon Linux 2023 image compatible with AWS Lambda FROM public.ecr.aws/lambda/python:3.9 -# Set up the work directory WORKDIR /var/task -# Install necessary build tools, Rust, and OpenSSL -RUN yum install -y zip gcc python3-devel libffi-devel tar gzip make && \ - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && \ - echo 'source $HOME/.cargo/env' >> $HOME/.bashrc && \ - source $HOME/.cargo/env && \ - yum install -y wget && \ - wget https://www.openssl.org/source/openssl-1.1.1k.tar.gz && \ - tar -xzvf openssl-1.1.1k.tar.gz && \ - cd openssl-1.1.1k && \ - ./config --prefix=/usr/local/ssl --openssldir=/usr/local/ssl shared zlib && \ - make && make install && \ - echo "/usr/local/ssl/lib" > /etc/ld.so.conf.d/openssl-1.1.1k.conf && \ - ldconfig && \ - cd .. && rm -rf openssl-1.1.1k* +COPY requirements.txt . -# Set OpenSSL environment variables -ENV LDFLAGS="-L/usr/local/ssl/lib" -ENV CPPFLAGS="-I/usr/local/ssl/include" -ENV LD_LIBRARY_PATH="/usr/local/ssl/lib" -ENV PATH="/usr/local/ssl/bin:${PATH}" +RUN pip install --upgrade pip && \ + pip install --no-cache-dir -r requirements.txt -# Copy your application code and requirements.txt into the Docker image COPY . . -# Install dependencies and create the layer -RUN source $HOME/.cargo/env && \ - pip install --upgrade pip setuptools wheel && \ - pip install -r requirements.txt && \ - pip install . && \ +RUN pip install . && \ mkdir -p /tmp/python && \ pip install \ - --platform manylinux2014_$(uname -m) \ + --platform manylinux2014_x86_64 \ --implementation cp \ --python-version 3.9 \ --only-binary=:all: --upgrade \ -r requirements.txt -t /tmp/python && \ - pip install cffi --no-binary cffi -t /tmp/python && \ - pip install cryptography --no-binary cryptography -t /tmp/python && \ pip install . -t /tmp/python && \ cd /tmp/python && \ find . -type d -name "__pycache__" -exec rm -rf {} + && \ - zip -r9 /tmp/layer.zip . && \ - cd /var/task + zip -r9 /tmp/layer.zip . -# Copy the layer.zip to a known location -CMD cp /tmp/layer.zip /asset-output/layer.zip \ No newline at end of file +CMD ["python3", "-m", "awslambdaric", "handler.lambda_handler"] \ No newline at end of file