Question

Hitting issues with deploying govips image compression with DO Functions

Deploying '/Users/**/Projects/**/**'
  to namespace 'fn-**'
  on host 'https://**.doserverless.co'
Submitted function 'sample/hello' for remote building and deployment in runtime go:default (id: 6385b32b4639433585b32b4639b3359a)
Transcript of remote build session for action 'sample/hello':
Output of failed build in %s
/tmp/slices/builds/fn-**/sample_hello/2024-01-29T13-22-28.710Z/packages/sample/hello
downloading modules
building
# pkg-config --cflags  -- vips
Package vips was not found in the pkg-config search path.
Perhaps you should add the directory containing `vips.pc'
to the PKG_CONFIG_PATH environment variable
No package 'vips' found
pkg-config: exit status 1

with the following code

package main

import (
  "fmt"
  "io"
  "net/http"
  "os"

  "github.com/davidbyttow/govips/v2/vips"
)

func checkError(err error) {
  if err != nil {
    fmt.Println("error:", err)
    os.Exit(1)
  }
}

func Main() {
  vips.Startup(nil)

  _// fetch image_
  url := "https://images.pexels.com/photos/45201/kitty-cat-kitten-pet-45201.jpeg"
  response, _ := http.Get(url)

  image1bytes, err := io.ReadAll(response.Body)
  checkError(err)
  image1, err := vips.NewThumbnailFromBuffer(image1bytes, 200, 200, vips.InterestingCentre)

  checkError(err)

  _// Rotate the picture upright and reset EXIF orientation tag_
  err = image1.AutoRotate()
  checkError(err)

  ep := vips.NewDefaultJPEGExportParams()
  image1bytes, _, err = image1.Export(ep)
  checkError(err)
  err = os.WriteFile("output.jpg", image1bytes, 0644)
  checkError(err)
  vips.Shutdown()
}

would love some insight on what to do. I tried finding this in the docs somewhere but I had no luck.

Thanks!


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
February 9, 2024

Hey!

The error message:

Package vips was not found in the pkg-config search path.
Perhaps you should add the directory containing `vips.pc'
to the PKG_CONFIG_PATH environment variable
No package 'vips' found

indicates that the pkg-config tool can’t find the libvips development files. This is because DigitalOcean Functions, being a serverless environment, doesn’t have libvips installed by default.

As of the time being I don’t think that there is a way to install custom dependencies with the serverless functions, the best thing to do to get your voice heard regarding this would be to head over to our Product Ideas board and post a new idea, including as much information as possible for what you’d like to see implemented.

https://ideas.digitalocean.com/

An alternative option would be to switch to the App Platform and use a Dockerfile for your function deployment. This way, you can ensure that the libvips library is available during both build and runtime:

https://docs.digitalocean.com/products/app-platform/reference/dockerfile/

Hope that helps!

- Bobby.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel