how to i get the localhost url when i run a garden...
# 🤖|ask-kapa
g
@microscopic-river-74022 how to i get the localhost url when i run a garden deployment in sync mode to set it to an environment variable?
m
Please stand by @gentle-umbrella-55872 as I search the knowledge base. I normally take about 15 seconds or so. :wave:
---------------------- To get the localhost URL when running a Garden deployment in sync mode and set it to an environment variable, you can use Garden's proxy configuration. Here's how you can do it: 1. By default, Garden uses "localhost" as the hostname for port forwards. You can confirm or change this in your project configuration file (
project.garden.yml
):
Copy code
yaml
proxy:
  hostname: localhost
2. When you run
garden deploy --sync
, Garden will create port forwards for your services. The exact URL will depend on how you've configured your services and ingresses. 3. To access this URL programmatically, you can use Garden's template strings in your configuration. For example, in your service's
garden.yml
file, you could set an environment variable like this:
Copy code
yaml
kind: Deploy
name: your-service
type: container
# ...
spec:
  env:
    SERVICE_URL: <http://${var.base-hostname}>
Here,
${var.base-hostname}
will resolve to the hostname you've configured (default is "localhost"). 4. If you need a specific port, you can reference it from the service configuration, for example:
Copy code
yaml
SERVICE_URL: <http://${var.base-hostname}:${this.ports.main.localPort}>
This assumes you have a port named "main" defined in your service configuration. Remember that the exact configuration might vary depending on your specific setup and requirements. The
local.demo.garden
domain is often used in Garden examples and resolves to 127.0.0.1, as mentioned in the [FAQ](). If you need more specific guidance, you might want to check the [Garden documentation on code synchronization]() for detailed examples and best practices. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
message has been deleted
g
and how to i set it to the enf only if snyc mode enabled else how a hard coded url
m
Let me check the knowledge base for you again. One moment! :books:
g
@microscopic-river-74022 ist this correct?
Copy code
yaml
          env:
            - name: NEXTAUTH_URL
              value:
                $if: ${actions.deploy.admin.mode == "sync"}
                $then: http://localhost:${actions.deploy.admin.outputs.forwardablePorts[0].preferredLocalPort}
                $else: https://admin.${var.hostname}
m
Sorry @gentle-umbrella-55872, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
4 Views