Repository: humanmade/tachyon Branch: master Commit: 52ac4f70f2da Files: 31 Total size: 50.2 KB Directory structure: gitextract_5_ahotyn/ ├── .github/ │ ├── dependabot.yml │ └── workflows/ │ ├── build-docker.yml │ ├── release.yml │ └── test.yml ├── .gitignore ├── CONTRIBUTING.md ├── Dockerfile ├── LICENSE ├── README.md ├── SECURITY.md ├── docs/ │ ├── plugin.md │ ├── tips.md │ └── using.md ├── global.d.ts ├── jest.config.js ├── package.json ├── src/ │ ├── lambda-handler.ts │ ├── lib.ts │ └── server.ts ├── template.yaml ├── tests/ │ ├── events/ │ │ ├── animated-gif.json │ │ ├── original.json │ │ └── signed-url.json │ ├── setup.ts │ ├── test-animated-files.ts │ ├── test-filesize/ │ │ ├── fixtures.json │ │ └── test-filesize.ts │ ├── test-lambda.ts │ └── test-private-upload.ts ├── tsconfig.json └── tsconfig.test.json ================================================ FILE CONTENTS ================================================ ================================================ FILE: .github/dependabot.yml ================================================ # To get started with Dependabot version updates, you'll need to specify which # package ecosystems to update and where the package manifests are located. # Please see the documentation for all configuration options: # https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file version: 2 updates: - package-ecosystem: "npm" # See documentation for possible values directory: "/" # Location of package manifests schedule: interval: "daily" ================================================ FILE: .github/workflows/build-docker.yml ================================================ name: Docker Build on: push: branches: - "**" tags: - "**" jobs: docker: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: node-version: 18.x - run: npm install - run: npx tsc - name: Docker meta id: meta uses: docker/metadata-action@v3 with: images: humanmade/tachyon tags: | type=edge,branch=master type=ref,event=tag - uses: docker/setup-qemu-action@v1 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 - name: Login to DockerHub uses: docker/login-action@v1 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Build and push latest if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/') uses: docker/build-push-action@v2 with: file: Dockerfile context: . platforms: linux/amd64,linux/arm64 push: true tags: ${{ steps.meta.outputs.tags }} ================================================ FILE: .github/workflows/release.yml ================================================ name: Release on: push: tags: - "**" branches: - '**' pull_request: branches: - '**' jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: 18.x - run: npm install - run: npx tsc - uses: aws-actions/setup-sam@v2 with: use-installer: true - run: npm run build - run: npm run build-zip - uses: softprops/action-gh-release@v1 if: startsWith(github.ref, 'refs/tags/') with: files: lambda.zip - uses: actions/upload-artifact@v4 if: github.event_name == 'pull_request' with: path: lambda.zip name: lambda ================================================ FILE: .github/workflows/test.yml ================================================ name: Test on: push: branches: - '**' jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: node-version: 18.x - run: npm install - run: npx jest env: AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} S3_BUCKET: ${{ vars.S3_BUCKET }} S3_REGION: ${{ vars.S3_REGION }} ================================================ FILE: .gitignore ================================================ node_modules/ .idea lambda.zip .aws-sam/ .DS_Store dist/ /tests/test-filesize/output/ ================================================ FILE: CONTRIBUTING.md ================================================ # Contributing ## Building for Lambda You'll need to [install the AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.html) as AWS SAM. ``` npm install npm run build // Builds the function for use in SAM ``` ### Building locally Tachyon is written in TypeScript. All TypeScript files are in `.src` and running `npx tsc` will build everything to `./dist`. You can run `npx tsc -w` to watch for file changes to update `./dist`. This is needed if you are running the server locally (see below) or running the Lambda environment via the SAM cli (see below.) ### Running a server locally Invoking the function via Lambda locally is somewhat slow (see below), in many cases you may want to start a local Node server which maps the Node request into a Lambda-like request. `./src/server.ts` exists for that reason. The local server will still connect to the S3 bucket (set with the `S3_BUCKET` env var) for files. ### Running Lambda Locally Before testing any of the Lambda function calls via the `sam` CLI, you must run `sam build -u` to build the NPM deps via the Lambda docker container. This will also build the `./dist/` into the SAM environment, so any subsequent changes to files in `./src` but be first built (which updates `./dist`), and then `sam build -u` must be run. To run Tachyon in a Lambda local environment via docker, use the `sam local invoke -e events/animated-gif.json` CLI command. This will call the function via the `src/lambda-handler.handler` function. ### Writing tests Tests should be written using Jest. Files matching `./tests/**/test-*.ts` will automatically be included in the Jest testsuite. For tests, you don't need to run `npx tsc` to compile TypeScript files to `./dist`, as this is integrated automatically via the `ts-jest` package. Run `npm test` to run the tests. ================================================ FILE: Dockerfile ================================================ FROM public.ecr.aws/lambda/nodejs:18 COPY package.json /var/task/ COPY package-lock.json /var/task/ RUN npm install --omit=dev COPY dist /var/task/dist # Set environment variables, backwards compat with Tachyon 2x. ARG S3_REGION ARG S3_BUCKET ARG S3_ENDPOINT ARG PORT # Start the reactor EXPOSE ${PORT:-8080} ENTRYPOINT /var/lang/bin/node dist/server.js ${PORT:-8080} ================================================ FILE: LICENSE ================================================ ISC License Copyright (c) 2023 Human Made Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ================================================ FILE: README.md ================================================
Tachyon
Faster than light image resizing service that runs on AWS. Super simple to set up, highly available and very performant.
A Human Made project. Maintained by @joehoyle.
Tachyon is a faster than light image resizing service that runs on AWS. Super simple to set up, highly available and very performant. ## Setup Tachyon comes in two parts: the server to serve images and the [plugin to use it](./docs/plugin.md). To use Tachyon, you need to run at least one server, as well as the plugin on all sites you want to use it. ## Installation on AWS Lambda We require using Tachyon on [AWS Lambda](https://aws.amazon.com/lambda/details/) to offload image processing task in a serverless configuration. This ensures you don't need lots of hardware to handle thousands of image resize requests, and can scale essentially infinitely. One Tachyon stack is required per S3 bucket, so we recommend using a common region bucket for all sites, which then only requires a single Tachyon stack per region. Tachyon requires the following Lambda Function spec: - Runtime: Node JS 18 - Function URL activated - Env vars: - S3_BUCKET=my-bucket - S3_REGION=my-bucket-region - S3_ENDPOINT=http://my-custom-endpoint (optional) - S3_FORCE_PATH_STYLE=1 (optional) Take the `lambda.zip` from the latest release and upload it to your function. For routing web traffic to the Lambda function, we recommend using [Lambda Function URLs](https://docs.aws.amazon.com/lambda/latest/dg/urls-configuration.html). These should be configured as: - Auth type: None - Invoke mode: `RESPONSE_STREAM` Alternatively, you can use API Gateway; this should be set to route all GET requests (i.e. `/{proxy+}`) to invoke your Tachyon Lambda function. We also recommend running an aggressive caching proxy/CDN in front of Tachyon, such as CloudFront. (An expiration time of 1 year is typical for a production configuration.) ## Documentation * [Plugin Setup](./docs/plugin.md) * [Using Tachyon](./docs/using.md) * [Hints and Tips](./docs/tips.md) ## Credits Created by Human Made for high volume and large-scale sites. We run Tachyon on sites with millions of monthly page views, and thousands of sites. Written and maintained by [Joe Hoyle](https://github.com/joehoyle). Tachyon is inspired by Photon by Automattic. As Tachyon is not an all-purpose image resizer, rather it uses a media library in Amazon S3, it has a different use case to [Photon](https://jetpack.com/support/photon/). Tachyon uses the [Sharp](https://github.com/lovell/sharp) (Used under the license Apache License 2.0) Node.js library for the resizing operations, which in turn uses the great libvips library. Interested in joining in on the fun? [Join us, and become human!](https://hmn.md/is/hiring/) ## Looking for a different Tachyon? Tachyon by Human Made provides image resizing services for the web, and is specifically designed for WordPress. "Tachyon" is named after the [hypothetical faster-than-light particle](https://en.wikipedia.org/wiki/Tachyon). Other software named Tachyon include: * [Tachyon by VYV](https://tachyon.video/) - Video playback and media server. * [Tachyon by Cinnafilm](https://cinnafilm.com/product/tachyon/) - Video processing for the cinema industry. * [TACHYONS](https://tachyons.io/) - CSS framework. ================================================ FILE: SECURITY.md ================================================ # Security Policy ## Reporting a Vulnerability Email security [at] humanmade.com ================================================ FILE: docs/plugin.md ================================================ # Plugin Setup The Tachyon plugin is responsible for replacing WordPress' default thumbnail handling with dynamic Tachyon URLs. [Download from GitHub →](https://github.com/humanmade/tachyon-plugin) ## Installation Install the Tachyon plugin as a regular plugin in your WordPress install (mu-plugins also supported). You also need to point the plugin to your [Tachyon server](server.md). Add the following to your `wp-config-local.php`: ```php define( 'TACHYON_URL', 'http://localhost:8080//uploads' ); ``` ## Credits The Tachyon plugin is based on the Photon plugin code by Automattic, part of [Jetpack](https://github.com/Automattic/jetpack/blob/master/class.photon.php). Used under the GPL. ================================================ FILE: docs/tips.md ================================================ # Hints and Tips ## Regions When running Tachyon in production, we recommend running one Tachyon instance per region. This instance should connect to the S3 bucket for the region, which can then be shared across all stacks in that region. While S3 buckets can be accessed from any region, running Lambda from the same region as the bucket is recommended. This reduces latency and improves image serving speed. ================================================ FILE: docs/using.md ================================================ # Using Tachyon provides a simple HTTP interface in the form of: `https://{tachyon-domain}/my/image/path/on/s3.png?w=100&h=80` It's really that simple! ## Args Reference | URL Arg | Type | Description | |---|----|---| |`w`|Number|Max width of the image.| |`h`|Number|Max height of the image.| |`quality`|Number, 0-100|Image quality.| |`resize`|String, "w,h"|A comma separated string of the target width and height in pixels. Crops the image.| |`crop_strategy`|String, "smart", "entropy", "attention"|There are 3 automatic cropping strategies for use with `resize`: