Skip to content

Draft: feat: Do not wrap CNB container with EXPOSE 5000

Hordur Freyr Yngvason requested to merge do-we-need-expose-5000 into master

It seems like we do not actually need port 5000 explicitly exposed. Ports can also be exposed at runtime. This is what the containerPort directive does in Kubernetes.

So why was it there? I think I added it originally because the Herokuish build uses it, and because the services-based test structure demands an exposed port.

Getting rid of the intermediate cnb.Dockerfile should speed up the build and paves the way for improved layer caching.

Manual QA

Tested in https://gitlab.com/hfyngvason/example-rails-project/-/commit/7e459d3c331d6660e2c60a54ccc88f712d3f36a7:

  • the build used CNB and succeeded
  • the deployment succeeded
  • the application responds to requests (edit: I've deleted the cluster now to save money)
  • docker inspect registry.gitlab.com/hfyngvason/example-rails-project/master:latest shows that no port is exposed on the image

Update: setting the default PORT to 5000 is required

Turns out that the rails buildpack is a special case in having PORT set to 5000 by default. Luckily, the new pack version includes the ability to inject runtime variables through a .profile script, which I've implemented and think is a reasonable compromise.

Edited by Hordur Freyr Yngvason

Merge request reports