Question

How to Configure A Service To Access Related Workers

Hi DO, I’m building a Node.js app which requires a Docker internal service, it needs to be able to access the Docker internal service (via env vars). Currently, I couldn’t find documentation anywhere talk about this. I couldn’t configure workers in deploy.template.yaml, either. My configuration: https://github.com/phuctm97/img-node/blob/master/.do/deploy.template.yaml

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hello, quickly looking at the linked repository it seems the API is trying to talk to the puppeteer worker via websockets. In App Platform workers are not exposed via HTTP. For this type of interaction you should use “internal services” rather than a worker. See internal_ports in app spec reference. Here is an example repo utilizing the concept (under the /multi route).

So in your case, I think the spec should look something like:

spec:
  name: img
  services:
    - name: api
      environment_slug: node-js
      git:
        branch: master
        repo_clone_url: https://github.com/phuctm97/img-node
      envs:
        - key: BROWSER_ENDPOINT
          scope: RUN_TIME
          value: "chrome:3000"
    - name: chrome
      environment_slug: docker
      image:
        repository: browserless/chrome
      internal_ports:
      - 3000

That should result in the api service exposed publicly, and the chrome service exposed internally on port 3000. Provided that browserless/chrome respects the PORT env parameter (quickly looking into the code on GitHub it looks like it should), that should make the puppeteer websocket service available to call from the api service.

Hope this helps!