diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..eabf2e2 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,67 @@ +name: Build + +on: + push: + branches: + - main + pull_request: + release: + types: [published] + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +env: + MUPDF_VERSION: 1.24.10 + +jobs: + test: + runs-on: ubuntu-latest + container: amazonlinux:2023 + steps: + - name: Install the necessary tools + run: | + yum update -y + yum groupinstall "Development Tools" -y + yum install -y tar wget dnf awscli + + - name: Build MuPDF + # https://mupdf.readthedocs.io/en/latest/quick-start-guide.html + run: | + wget https://mupdf.com/downloads/archive/mupdf-${{ env.MUPDF_VERSION }}-source.tar.gz + tar -xzf mupdf-${{ env.MUPDF_VERSION }}-source.tar.gz + cd mupdf-${{ env.MUPDF_VERSION }}-source + make HAVE_X11=no HAVE_GLUT=no prefix=/usr/local install + + - name: Create the layer + run: | + mkdir -p layer/bin + cp /usr/local/bin/mutool layer/bin/ + cp /usr/local/bin/muraster layer/bin/ + mkdir -p layer/lib + ldd /usr/local/bin/mutool | grep '=>' | awk '{print $3}' | xargs -I '{}' cp -v '{}' layer/lib + ldd /usr/local/bin/muraster | grep '=>' | awk '{print $3}' | xargs -I '{}' cp -v '{}' layer/lib + cd layer + zip -r9 ../mupdf-layer.zip . + cd .. + + - name: Login to AWS + if: github.event_name == 'release' + run: | + aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID }} + aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws configure set region ${{ secrets.AWS_REGION }} + + - name: Upload to S3 + if: github.event_name == 'release' + run: | + aws s3 cp mupdf-layer.zip s3://${{ secrets.S3_BUCKET }}/mupdf-layer.zip + + - name: Deploy the layer to the artifact registry + if: github.event_name == 'release' + run: | + aws lambda publish-layer-version \ + --layer-name mupdf \ + --content S3Bucket=${{ secrets.S3_BUCKET }},S3Key=mupdf-layer.zip \ + --description "MuPDF CLI tools v${{ env.MUPDF_VERSION }}" diff --git a/README.md b/README.md index c42f468..987c02b 100644 --- a/README.md +++ b/README.md @@ -1 +1,57 @@ # mupdf-aws-lambda-layer + +[![Build](https://github.com/rwv/mupdf-aws-lambda-layer/actions/workflows/build.yml/badge.svg)](https://github.com/rwv/mupdf-aws-lambda-layer/actions/workflows/build.yml) + +An AWS Lambda Layer containing MuPDF CLI tools (mutool and muraster) built for Amazon Linux 2023. + +## Overview + +This project provides a Lambda Layer that packages MuPDF command-line tools, making them available for use in AWS Lambda functions. The layer is built using Amazon Linux 2023 to ensure compatibility with Lambda's runtime environment. + +## Version + +Current MuPDF version: [1.24.10](https://mupdf.com/releases/history) + +## Contents + +The layer includes: +- `bin/mutool` - An all purpose tool for dealing with PDF files +- `bin/muraster` - Can be used to convert PDF pages to raster images +- `lib/*` - All required shared libraries + +## Usage + +### Manual Layer Usage + +1. Download the layer ZIP from the [latest release](https://github.com/rwv/mupdf-aws-lambda-layer/releases/latest) +2. Create a new Lambda Layer in your AWS account +3. Upload the ZIP file +4. Attach the layer to your Lambda function + +### Automated Layer Deployment + +The layer is automatically published to AWS Lambda's layer registry on each release. You can fork this repository and add the following repository secrets to enable automated deployments: + +- `AWS_ACCESS_KEY_ID`: Your AWS access key ID +- `AWS_SECRET_ACCESS_KEY`: Your AWS secret access key +- `AWS_REGION`: The AWS region to deploy to +- `S3_BUCKET`: The S3 bucket name for storing the layer ZIP file + +## Building + +The layer is automatically built using GitHub Actions. The workflow: +1. Sets up an Amazon Linux 2023 container +2. Builds MuPDF from source +3. Packages the binaries and dependencies +4. Creates a ZIP file +5. Publishes to S3 and Lambda Layer registry (on release only) + +To build locally, you can follow the steps in the GitHub Actions workflow file. + +## License + +This project is provided under the same license as MuPDF. See [MuPDF's license](https://mupdf.com/#licensing) for details. + +## Contributing + +Contributions are welcome! Please feel free to submit a Pull Request.