pygmystack / pygmy

the pygmy stack is a container stack for local development
MIT License
25 stars 13 forks source link

Forward http requests from pygmy to lando (or reverse?)? #393

Open silverham opened 2 years ago

silverham commented 2 years ago

Hi, Is it possible to forward http requests from pygmy to lando's traefik proxy or a specific web service container inside .lando.yml?

I would like to expose on my local computer, all my websites whether lagoon (pygmy) or lando via one port number.

This ticket suggests it is possible but the "network" key doesn't work for recipe e.g. drupal? https://github.com/lando/docs/issues/2

Alternately, i suppose, one workaround is to create yet another docker-compose vanilla http proxy with lando's compose plugin. similar to this: https://github.com/drupal-graphql/drupal-decoupled-app/blob/master/docker-compose.yml#L24

Cross post for visibility https://github.com/lando/lagoon/issues/34

fubarhouse commented 2 years ago

The reverse proxy in pygmy is actually quite flexible.

Take a look at the haproxy container - it shows you how to connect a container to the reverse proxy.

You simply hook up the required environment variables and from there as long as the container is connected to the same network as pygmy it will start to work. The other consideration is that the domain suffix must match what pygmy is serving.

Pygmy does use its own docker network by default - containers would need to join that network to be discoverable - or alternatively you'd need to force pygmy to use another network.

Here's how the process would look:

silverham commented 2 years ago

Perfect! The hard part was figuring out which environmental variables to use and trying to get the lando container connected to the amazeeio-network network. Ideally I wanted it all in the one .lando.yml file but alas, I had to use a supplementary file to get the network to be defined, else i got the treaded `ERROR: Service "appserver" uses an undefined network "amazeeio-network".

So below is an example I got working with base file from the Lando Drupal recipe https://docs.lando.dev/drupal/getting-started.html which connects Pymgy directly to the http web server container, bypassing Traefik.

Note the compose, overrides keys and networks.yml file.

[project]/index.php

<p><?php print 'Drupal php code starts here.'; ?></p>

[project]/.lando.yml

name: my-first-drupal9-app
recipe: drupal9
config:
  webroot: .
compose:
  - lando-config/networks.yml
services:
  appserver:
    webroot: .
    xdebug: false
    # Pymgy / amazeeeio-haproxy intergration so we share the same port number, via both being accessible in pygmy.
    # `LAGOON_LOCALDEV_URL` & `LAGOON_LOCALDEV_HTTP_PORT` for proxy viewing.
    # `LAGOON_ROUTE` for proxy status via `pygmy status`
    # @see https://github.com/amazeeio/docker-haproxy/blob/master/haproxy.tmpl
    # @see https://github.com/pygmystack/pygmy/blob/main/service/library/status.go#L131
    overrides:
      environment:
        LAGOON_LOCALDEV_URL: http://lando-test.docker.amazee.io
        LAGOON_LOCALDEV_HTTP_PORT: 80
        LAGOON_ROUTE: http://lando-test.docker.amazee.io
      networks:
        - amazeeio-network

[project]/lando-config/networks.yml

networks:
  amazeeio-network:
    external: true

PS: Note sure if this integration should be documented? If no, then happy for ticket to be closed. :-)

fubarhouse commented 2 years ago

I'll leave this open for now - I love it and want to make a record of it somewhere :)