Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cro: How to define port for each services in .cro.yml?

Tags:

raku

cro

After creating stub services with cro stub http test test, I have defined TEST_PORT environment variable in .cro.yml:

---
id: test
cro: 1
name: "test"
endpoints: 
  - 
    id: http
    name: HTTP
    protocol: http
    host-env: TEST_HOST
    port-env: TEST_PORT
links:  []
entrypoint: service.p6
env:
  - name: TEST_PORT
    value: "3001"
...

Nevertheless, Cro still uses the default 20000 port. Alex Schroeder exports the environment variables to start Cro in a different port. The command "export TEST_PORT="3001" && cro run" still uses the default port.

What would be the right form of defining the service port in Cro?

like image 666
Mimosinnet Avatar asked Mar 23 '20 08:03

Mimosinnet


1 Answers

The cro run tool automatically assigns ports to all services that it starts. This is to ensure they get a free port that isn't in use for something else. Thus, it will inject environment variables with the ports it has chosen. You don't get to choose the port when using cro run.

To run the service on chosen ports, do it without cro run, that is, just export the environment variables and invoke the service like raku -Ilib service.p6 (or with perl6 -Ilib service.p6 if you have an older installation). That way, the service will see the environment variable containing your choice of port. The default Dockerfile is set up to do this also.

Note that the cro development tool is intended solely as a development time aid, and is not suitable for a production deployment (which is the primary case where picking the port would matter).

like image 86
Jonathan Worthington Avatar answered Nov 18 '22 09:11

Jonathan Worthington