Exposing services or making them private
Ergomake will expose to the internet the first container port bound to alocalhost port on your docker-compose.yml.
For example, if you bind a container’s 3000 port to a port on localhost, Ergomake will expose port 3000 to the internet when deploying your that service in your preview environment.
Take the api and database services below, for example.
3001 port to localhost:8080. Consequently, Ergomake will expose the container’s 3001 port over the internet.
Similarly, Ergomake will also expose the database’s 27017 port over the internet when creating your environment.
Here’s what the URLs to reach api and database would look like in the above scenario, respectively:
api:https://api-yourOrg-yourRepo-prNumber.env.ergomake.linkdatabase:https://database-yourOrg-yourRepo-prNumber.env.ergomake.link
9001 for the api service is exposed within localhost, it won’t be exposed to the internet. That’s because only the first bound port will be exposed to the internet.
Please notice these addresses are only available over HTTP(S).
Inter-service routing
Containers within your preview environment will talk to each other using the same hostnames they would use on your machine when you run them with Docker Compose. That means a service namedapi can address a service named database by using database as the hostname.
Assume, for example, that you have a service named api containing a Node.js application. The api service connects to a MongoDB instance within a service named mongo.
mongo as the hostname within your Node.js application.
It may be that you’re exposing ports so that you can use
localhost to
connect to them. Exposing services so that you can connect to them via
localhost will not work because localhost does not exist for Ergomake.
Please make sure to always use your service’s names when connecting to them.Routing and front-end apps
When bundling a front-end app, many people use an environment variable to indicate the address of the API to which the front-end app will send requests. To configure that URL, many front-end apps must include the back-end’s URL during build-time. As an example, assume you have a React app and that app uses theREACT_APP_API_URL during build time, as shown below.
REACT_APP_API_URL build argument with the address we’ll generate for api. That build argument will be used to set the REACT_APP_API_URL environment variable that npm run build uses when bundling the React app.
To do that, you’ll use the dev.ergomake.env.replace-arg.YOUR_ENV_VAR label. Within that label, you can interpolate the address we’ll generate for the api service, as shown in the example below.
REACT_APP_API_URL when creating your image.
