Skip to content

Conversation

Copy link

Copilot AI commented Sep 29, 2025

This PR adds two new environment variables to enhance Preevy's service discovery capabilities, addressing specific user needs while maintaining full backward compatibility.

New Environment Variables

  • PREEVY_ENV_ID - Contains the environment ID (e.g., my-app-main)
  • PREEVY_HOST_{SERVICE}_{PORT} - Contains just the hostname without protocol or trailing slash (e.g., frontend-3000-envid-clientid.livecycle.run)

Problem Solved

Users reported limitations with the existing PREEVY_BASE_URI_{SERVICE}_{PORT} variables:

  1. PHP applications needed just the domain name without URL parsing
  2. Minio S3 services required URLs without trailing slashes and with correct schemes
  3. Custom URL building needed access to the environment ID

Example Usage

Before:

services:
  frontend:
    environment:
      - API_URL=${PREEVY_BASE_URI_API_8080:-http://localhost:8080/}
      # Required manual parsing to extract hostname

After:

services:
  frontend:
    environment:
      - API_URL=${PREEVY_BASE_URI_API_8080:-http://localhost:8080/}  # Still works!
      - API_HOST=${PREEVY_HOST_API_8080:-localhost}                  # New: just hostname
      - ENV_ID=${PREEVY_ENV_ID:-local}                               # New: environment ID

Implementation Details

  • Extended serviceLinkEnvVars() function to generate additional environment variables
  • Added hostname extraction using URL constructor with graceful fallback for invalid URLs
  • Environment ID is only included when available (optional parameter)
  • Service name normalization follows existing patterns (non-alphanumeric characters → underscores)

Backward Compatibility

✅ All existing PREEVY_BASE_URI_{SERVICE}_{PORT} variables work exactly as before
✅ No breaking changes to existing functionality
✅ New variables are additive only

Testing

  • Added comprehensive unit test suite covering all scenarios
  • Tests verify backward compatibility, edge cases, and error handling
  • Integration tests confirm real-world usage patterns
  • All existing tests continue to pass

Documentation

Updated service discovery documentation with examples showing how to use all three types of environment variables together.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Feat]: Adding more preevy environment variables</issue_title>
<issue_description>### What feature?

Hi,
We're setting up preevy and we've run into some minor annoyances.

From what I understand, the only preevy-related environment variable we can use is PREEVY_BASE_URI_{SERVICE}, however this is not sufficient for our needs for multiple reasons;

  • Our application (PHP) needs to know the domain it is running on. Just the domain so now we would have to do some parsing in the application to get that.
  • We use minio as an S3 development alternative, and for that we need the url to the service. However the one in the preevy environment variable is http instead of https, and it has a trailing slash, which we don't need.

Describe the solution you'd like

All our cases would be solved if we could get more preevy environment variables, like:

  • the environment id (with this we could build the url ourselves)
  • just the host name, without the scheme and no trailing slashes

Describe alternatives you've considered

No response

Additional context

No response

Add screenshots

No response

Record

  • I agree to follow this project's Code of Conduct</issue_description>

<agent_instructions>Should be similar to PREEVY_BASE_URI_{SERVICE} behavior</agent_instructions>

Comments on the Issue (you are @copilot in this section)

Fixes #501

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] [Feat]: Adding more preevy environment variables feat: Add PREEVY_HOST and PREEVY_ENV_ID environment variables Sep 29, 2025
Copilot AI requested a review from Yshayy September 29, 2025 05:03
Copilot finished work on behalf of Yshayy September 29, 2025 05:03
Copy link
Contributor

@Yshayy Yshayy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small change

): Record<string, string> => {
const baseUriVars = Object.fromEntries(
expectedServiceUrls
.map(({ name, port, url }) => [`PREEVY_BASE_URI_${name.replace(/[^a-zA-Z0-9_]/g, '_')}_${port}`.toUpperCase(), url])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the regex replace can be extracted to format service name for url function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feat]: Adding more preevy environment variables

2 participants