odo icon indicating copy to clipboard operation
odo copied to clipboard

Feature: Set port config while creating initial devfile `odo init nodejs frontend --port 8080`

Open ryanj opened this issue 4 years ago • 12 comments

/kind feature

Which functionality do you think we should add?

It would be really nice to have a --port option for odo create that would allow users to modify and/or extend the catalog devfile examples. This currently works for --s2i, but is not yet available for devfiles.

Why is this needed?

The default nodejs devfile example (from the registry catalog) binds to 3000 by default. This works well for the --starter repo, but binding to port 3000 is not used exclusively by all nodejs projects. Users can run odo config set Ports 8080 as a workaround, but this seems to append additional port info instead of replacing the older config.

Here is a clip from my resulting devfile.yaml using odo v2.0.5 (e8030b19a):

- container:
    endpoints:
    - name: http-3000
      targetPort: 3000
    - name: port-8080-tcp
      protocol: tcp
      targetPort: 8080

Currently, users who take this approach will end up with two routes after running odo push. Clicking on the "Open URL" decorator in the Topology view fails - unless the user cleans up the invalid port config using oc delete route http-3000-frontend

Ideally, users should be able to set the port config during the initial devfile creation step, via odo create nodejs component_name --port 8080

See the "frontend" component here for an example nodejs app that binds to 8080: https://learn.openshift.com/introduction/developing-with-odo/

ryanj avatar Feb 19 '21 01:02 ryanj

@girishramnani this is exactly what you were talking about yesterday.

dharmit avatar Feb 19 '21 06:02 dharmit

Issues go stale after 90d of inactivity.

Mark the issue as fresh by commenting /remove-lifecycle stale. Stale issues rot after an additional 30d of inactivity and eventually close. Exclude this issue from closing by commenting /lifecycle frozen.

If this issue is safe to close now please do so with /close.

/lifecycle stale

openshift-bot avatar May 20 '21 07:05 openshift-bot

Stale issues rot after 30d of inactivity.

Mark the issue as fresh by commenting /remove-lifecycle rotten. Rotten issues close after an additional 30d of inactivity. Exclude this issue from closing by commenting /lifecycle frozen.

If this issue is safe to close now please do so with /close.

/lifecycle rotten /remove-lifecycle stale

openshift-bot avatar Jun 19 '21 11:06 openshift-bot

/remove-lifecycle rotten

@kadel can you PTAL?

dharmit avatar Jun 22 '21 11:06 dharmit

Issues go stale after 90d of inactivity.

Mark the issue as fresh by commenting /remove-lifecycle stale. Stale issues rot after an additional 30d of inactivity and eventually close. Exclude this issue from closing by commenting /lifecycle frozen.

If this issue is safe to close now please do so with /close.

/lifecycle stale

openshift-bot avatar Sep 20 '21 14:09 openshift-bot

Stale issues rot after 30d of inactivity.

Mark the issue as fresh by commenting /remove-lifecycle rotten. Rotten issues close after an additional 30d of inactivity. Exclude this issue from closing by commenting /lifecycle frozen.

If this issue is safe to close now please do so with /close.

/lifecycle rotten /remove-lifecycle stale

openshift-bot avatar Oct 20 '21 15:10 openshift-bot

/remove-lifecycle rotten

@kadel can you PTAL?

/remove-lifecycle rotten

@kadel can you please help set priority on this one?

dharmit avatar Oct 25 '21 07:10 dharmit

Any updates on this? It's needed to support our default nodejs example app

ryanj avatar Aug 15 '22 17:08 ryanj

hey @dharmit @kadel will this work with odo v3?

serenamarie125 avatar Aug 15 '22 19:08 serenamarie125

I've tried using --port 8080, and I've tried the alternative, moving the app to :3000 via --env PORT=3000.

Both options (--port and --env) don't seem to get reflected in the devfile.yaml that is generated. I tried with odo version 2.5.0 and version 3.0.0beta2

Our example app runs on :8080 by default, and can be configured using the PORT env variable: https://github.com/sclorg/nodejs-ex

Let me know if you have any tips on how to set it up using odo and a local copy of the git repo:

  1. git clone https://github.com/sclorg/nodejs-ex
  2. cd nodejs-ex
  3. odo init nodejs frontend --port 8080

Or alternatively...

  1. odo init nodejs frontend --env PORT=3000

I'm able to successfully edit the resulting devfile.yaml to include my PORT=3000 environment setting. But, I'm not able figure out how to add these environment variables (or how to use the --port option) using odo's command line flags.

ryanj avatar Aug 15 '22 23:08 ryanj

With odo v3, there's yet no direct way of passing a flag to odo init command to get this done, but you could do it via interactive mode.

In the directory where your code resides, run odo init (make sure there's no devfile.yaml file in this directory) without any arguments. odo will ask you a bunch of questions. First, it will ask you if the language/framework it detected based on the code in your pwd is correct. If not, you can interactively change the framework.

Next, it will let you modify env vars for the "runtime" container. By default, port for this is 3000. You should delete the port and add 8080. All of this through interactive mode.

dharmit avatar Aug 16 '22 16:08 dharmit

Thanks @dharmit, @serenamarie125

This works for me in interactive mode with v3.0.0beta2

Looking forward to a non-interactive way to generate a devfile as well - which might also resolve #4435

ryanj avatar Aug 17 '22 15:08 ryanj