Skip to content

Image Embedded Environment Variables do not work with buildpacks #2717

Open
@andrin55

Description

@andrin55

According to the documentation if I wanted to have a environment variable embedded in the image, I could use buildEnvs and pass them to the buildpack:

My func.yaml

specVersion: 0.36.0
name: golang-buildpack-env
runtime: go
image: localhost/golang-test:pack
created: 2025-02-24T15:24:20.227225588+01:00
invoke: http
build:
  builder: pack
  buildEnvs:
  - name: BPE_COMMIT_SHA
    value: 'test123'

This is then dectected by the buildpack when buildung with func build -i localhost/golang-test:pack -v:

Provided Environment Variables
  BPE_COMMIT_SHA=test123

However the environment variable is not available (started with: podman run --rm -p 8080:8080 -it localhost/golang-test:pack):

Initializing HTTP function
listening on http port 8080
env test: ""
Received request
...

The test project is just a simple go function which prints the env var and returns the http request:

package function

import (
        "os"
        "strings"
        "fmt"
        "net/http"
        "net/http/httputil"
)

// Handle an HTTP Request.
func Handle(w http.ResponseWriter, r *http.Request) {
        envTest := strings.ToLower(os.Getenv("COMMIT_SHA"))
        fmt.Printf("env test: %q\n", envTest)

        dump, err := httputil.DumpRequest(r, true)
        if err != nil {
                http.Error(w, err.Error(), http.StatusInternalServerError)
                return
        }

        fmt.Println("Received request")
        fmt.Printf("%q\n", dump)
        fmt.Fprintf(w, "%q", dump)
}

Used func cli version is v1.17.0 (tough the CLI says "v0.44.0")

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions