This repository contains the resources to deploy an image search app using the Koyeb serverless platform.
You can check out the complete documentation to run this example here.
This GitHub repository contains:
-
A
koyeb.yaml
file: used to configure and deploy the functionimage-search.js
on Koyeb. Thekoyeb.yaml
file contains environment variables required by the function to run properly, the Koyeb Store the function must access to retrieve and process the image, and the event triggering the function. -
A
image-search.js
file: The function to detect image labels and index them on Algolia. This function is triggered each time a new image is uploaded to the Koyeb Store.
- Log-in to the Koyeb Control Panel
- Create a Store
- Create secrets name with the associated value:
aws-reko-access-key
,aws-reko-secret-key
,algolia-app-id
,algolia-api-key
,algolia-index
. - Edit the
koyeb.yaml
file and replace theREPLACE_ME_WITH_YOUR_KOYEB_STORE_NAME
value with your Koyeb Store name.
functions:
- name: image-search
runtime: nodejs14
handler: koyeb-functions/image-search.handler
env:
AWS_ACCESS_KEY:
value_from_secret: aws-reko-access-key
AWS_SECRET_KEY:
value_from_secret: aws-reko-secret-key
ALGOLIA_APP_ID:
value_from_secret: algolia-app-id
ALGOLIA_API_KEY:
value_from_secret: algolia-api-key
ALGOLIA_INDEX:
value_from_secret: algolia-index
volumes:
- store: REPLACE_ME_WITH_YOUR_KOYEB_STORE_NAME
events:
- cloudevent:
expression: |
event.source == "koyeb.com/gateway" &&
event.subject == "REPLACE_ME_WITH_YOUR_KOYEB_STORE_NAME" &&
event.type.matches("s3:ObjectCreated:.*") &&
data.object.key.matches("([^\\s]+(\\.(?i)(jpe?g|png))$)")
- Fork this repository
- Create a new Koyeb Stack using GitHub and select the repository your just forked.
The processing function is deploying on Koyeb and will be ready in a few seconds.
To run this application you need to:
- Generate Koyeb S3 credentials
- In the repository you previously forked, copy the
env.example
to.env.local
, and edit the variable values with your own:
NEXT_PUBLIC_ALGOLIA_APP_ID=REPLACE_ME
NEXT_PUBLIC_ALGOLIA_SEARCH_API_KEY=REPLACE_ME
NEXT_PUBLIC_ALGOLIA_INDEX=REPLACE_ME
KOYEB_S3_ACCESS_KEY=REPLACE_ME
KOYEB_S3_SECRET_KEY=REPLACE_ME
KOYEB_STORE=REPLACE_ME
- Run the app
yarn install
to install the project dependenciesyarn start
to start the application