Page MenuHomePhabricator

[builds-builder] Golang buildpack does not allow using Procfiles so can't use custom scripts/entrypoints
Closed, ResolvedPublicBUG REPORT

Description

Steps to replicate the issue (include links if applicable):
So, I tried to deploy a sample golang server using toolforge build. I followed the rust tutorial here and ran the following commands

  • become campwiz-bot
  • toolforge build start https://github.com/nokibsarkar/campwiz-test.git
  • toolforge webservice --mount=all buildservice start
  • toolforge webservice buildservice logs -f

ProcFile
Lates

web:sh -c 'GIN_MODE=release ./campwiz-test'

Also tried with

web:GIN_MODE=release ./campwiz-test

What happens?:
I get the following outputs:

(venv) tools.campwiz-bot@tools-bastion-13:~$ toolforge webservice buildservice logs -f
2025-04-02T10:39:02+00:00 [campwiz-bot-7676ff486b-9cvqp] Current Directory: /workspace
2025-04-02T10:39:02+00:00 [campwiz-bot-7676ff486b-9cvqp] [GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.
2025-04-02T10:39:02+00:00 [campwiz-bot-7676ff486b-9cvqp] 
2025-04-02T10:39:02+00:00 [campwiz-bot-7676ff486b-9cvqp] [GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
2025-04-02T10:39:02+00:00 [campwiz-bot-7676ff486b-9cvqp]  - using env:  export GIN_MODE=release
2025-04-02T10:39:02+00:00 [campwiz-bot-7676ff486b-9cvqp]  - using code: gin.SetMode(gin.ReleaseMode)
2025-04-02T10:39:02+00:00 [campwiz-bot-7676ff486b-9cvqp] 
2025-04-02T10:39:02+00:00 [campwiz-bot-7676ff486b-9cvqp] [GIN-debug] GET    /                         --> main.main.func1 (3 handlers)
2025-04-02T10:39:02+00:00 [campwiz-bot-7676ff486b-9cvqp] [GIN-debug] [WARNING] You trusted all proxies, this is NOT safe. We recommend you to set a value.
2025-04-02T10:39:02+00:00 [campwiz-bot-7676ff486b-9cvqp] Please check https://pkg.go.dev/github.com/gin-gonic/gin#readme-don-t-trust-all-proxies for details.
2025-04-02T10:39:02+00:00 [campwiz-bot-7676ff486b-9cvqp] [GIN-debug] Listening and serving HTTP on 0.0.0.0:8000

Which says that it is running in debug mode
What should have happened instead?:

I expected the sofware be running on release mode since I specified GIN_MODE=release as hardcoded environment variable in ProcFile above.
N.B: I tried using toolforge envvars create GIN_MODE and specify release as value. Then it works. So, this is not an issue with my code.
Software version (on Special:Version page; skip for WMF-hosted wikis like Wikipedia):

Other information (browser name/version, screenshots, etc.):

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

the procfile may not support setting envvars like that. If that's true, I see two options:

  • use the toolforge envvars, they work fine as you discovered
  • wrap the call to your code in a shell script, then call the shell script from the procfile. The shell script can contain whatever logic to set env vars.

Our Rust tutorial suggests variable in Procfile should be working. I'm not sure why they are not working for you.

wrap the call to your code in a shell script

This is a sensible workaround if you want to have the variable stored in Git, as opposed to toolforge envvars that are separate from your codebase.

Some notes from a quick check:

The envvar is there when executing inside the container, and it's kept even after running the launcher wrapper:

(venv) tools.campwiz-bot@tools-bastion-13:~$ kubectl exec -ti campwiz-bot-54f749fc5f-jrvx2 bash
...
I have no name!@campwiz-bot-54f749fc5f-jrvx2:/workspace$ echo $GIN_MODE
release
...
I have no name!@campwiz-bot-54f749fc5f-jrvx2:/workspace$ launcher bash
...
I have no name!@campwiz-bot-54f749fc5f-jrvx2:/workspace$ echo $GIN_MODE
release

It is also in the environment of the golang process: update it was not the golang process, but the shell

I have no name!@campwiz-bot-54f749fc5f-jrvx2:/workspace$ strings /proc/34/environ 
...
GIN_MODE=release
...

I think I found something, the command that the webservice runs is actually set by the golang buildpack, not the procfile one it seems, might be an ordering issue, looking

dcaro@devforge:~$ docker inspect 192.168.5.15/tool-tf-test2/tool-tf-test2:latest | jq '.[].Config.Labels."io.buildpacks.build.metadata"' -r | jq '.processes'
[
  {
    "type": "campwiz-test",
    "command": "campwiz-test",
    "args": [],
    "direct": true,
    "buildpackID": "heroku/go"
  },
  {
    "type": "web",
    "command": "campwiz-test",
    "args": [],
    "direct": true,
    "buildpackID": "heroku/go"
  }
]

@Nokib_Sarkar I created https://github.com/nokibsarkar/campwiz-test/pull/1 , that should fix the issue :)

Tested it on my local dev environment (lima-kilo):

...
[step-detect] 2025-04-23T09:17:02.300407364Z 2 of 4 buildpacks participating
[step-detect] 2025-04-23T09:17:02.300464477Z heroku/go       0.1.13                                                                            
[step-detect] 2025-04-23T09:17:02.300468953Z heroku/procfile 2.0.2  
...

There are two issues:

  • The name of the procfile should be Procfile, it's case sensitive :/
  • There seems to be a weird behavior of the procfile buildpack, where if you only declare the web entry it will not override the golang buildpack (looking), adding a silly new entry works and overwrites the web one too as a workaround

There seems to be a weird behavior of the procfile buildpack, where if you only declare the web entry it will not override the golang buildpack (looking), adding a silly new entry works and overwrites the web one too as a workaround

This is fixed on the next version of the buildpacks (coming soon!):

dcaro@devforge:/home/dcaro/Work/wikimedia/lima-kilo$ docker inspect 192.168.5.15/tool-tf-test2/tool-tf-test2:latest | jq '.[].Config.Labels."io.buildpacks.build.metadata"' -r | jq '.processes'
[
  {
    "type": "web",
    "command": "bash",
    "args": [
      "-c",
      "sh -c 'GIN_MODE=release ./campwiz-test'"
    ],
    "direct": true,
    "buildpackID": "heroku/procfile"
  }
]
dcaro renamed this task from Environment variables are not being passed to [builds-builder] Golang buildpack does not allow using Procfiles so can't use custom scripts/entrypoints.May 7 2025, 5:11 PM

@Nokib_Sarkar Hi! can you try using toolforge build start --use-latest-versions <http://url>? That should pull now the latest buildpacks, including the procfile fix, and golang with support for newer versions

Tested also that it works now with golang 1.24:

local.tf-test@toolslocal:~$ toolforge build start https://github.com/david-caro/campwiz-test --use-latest-versions
...
[step-build] 2025-05-14T09:24:14.746698709Z [Installing Go distribution]
[step-build] 2025-05-14T09:24:14.746816044Z Installing go1.24.1 (linux-amd64) from https://go.dev/dl/go1.24.1.linux-amd64.tar.gz
[step-build] 2025-05-14T09:24:18.960023212Z 
[step-build] 2025-05-14T09:24:18.960516726Z [Building Go binaries]
[step-build] 2025-05-14T09:24:18.960528317Z Creating new Go modules cache
...
dcaro changed the task status from Open to In Progress.May 14 2025, 1:58 PM
dcaro claimed this task.
dcaro moved this task from Next Up to In Progress on the Toolforge (Toolforge iteration 19) board.

So, The Issue is fixed apparently.

So, The Issue is fixed apparently.

I'll close the task then :), feel free to create a new one if you find any more issues with the new builder.

dcaro moved this task from In Progress to Done on the Toolforge (Toolforge iteration 20) board.