Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The site is automatically deployed when commits are merged/pushed in `master`, h

### Preview documentation locally with Docker (Recommended)

1. Install [docker-compose](https://docs.docker.com/compose/)
1. Install [Docker Compose](https://docs.docker.com/compose/)
2. Run `docker-compose up`
3. Open `http://localhost:3131` in your browser, and voila!

Expand Down
3 changes: 1 addition & 2 deletions _data/home-content.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@



- title: Example catalog
icon: images/home-icons/tutorial.svg
url: ''
Expand All @@ -15,8 +16,6 @@





- title: Deployments
icon: images/home-icons/deployment.svg
url: ''
Expand Down
21 changes: 18 additions & 3 deletions _data/nav.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@




- title: Example catalog
url: "/example-catalog"
Expand Down Expand Up @@ -115,6 +113,7 @@
url: "/amazon-ecs"
- title: Elastic Beanstalk
url: "/elastic-beanstalk"

- title: Deployments
url: "/deployments"
pages:
Expand Down Expand Up @@ -257,7 +256,23 @@
- title: Sharing file systems
url: "/sharing-file-system"


- title: CI/CD testing
url: "/testing"
pages:
- title: Unit tests
url: "/unit-tests"
- title: Integration tests
url: "/integration-tests"
- title: Creating test reports
url: "/test-reports"
- title: Creating compositions
url: "/create-composition"
- title: Dynamic preview environments
url: "/automatic-preview-environments"
- title: Security scanning
url: "/security-scanning"
- title: SonarQube scanning
url: "/sonarqube-integration"

- title: Clients
url: "/clients"
Expand Down
65 changes: 65 additions & 0 deletions _docs/testing/automatic-preview-environments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
title: "Dynamic preview environments"
description: "Preview test environments"
group: testing
toc: true
---
If your service is one of many microservices, after running automated tests on your service, you would probably want to check the new service with your whole system. In this case, you can launch the composition of your system as part of your build, and at the end of the build, open the composition.

## Prerequisites

Complete the tutorials for:
* [Creating a basic pipeline]({{site.baseurl}}/docs/getting-started/create-a-basic-pipeline/)
* [Creating temporary environments]({{site.baseurl}}/docs/getting-started/on-demand-environments/)

## Launch the composition

{:start="1"}
1. Open your `codefresh.yml` file and add a new step:
```yaml
launch_composition_step:
title: "Launch full composition with latest images"
type: launch-composition
composition: your-composition-name
fail_fast: false
```
1. Commit and push the changes to Git repository.
1. Build your service with Codefresh.
1. In the Codefresh UI, from the Artifacts section on the sidebar, select **Compositions**, and then select the **Running Compositions** tab.
The new preview environment is displayed in the list of Running Compositions.

## Launch an environment on single branch

There is a limit to the number of environments you can run concurrently. That's why it's a good practice to launch the composition only on a certain condition. Usually the most relevant condition is the branch, since you probably want your environment to be updated on the main branch.

The following instructions describe how to launch the environment for only the `master` branch:

{:start="1"}
1. Open your `codefresh.yml` file and add to the `launch_composition_step` the following:
```yaml
when:
branch:
only:
- master
```
1. Commit and push changes to your Git repository's `master` branch.
1. Build your service with Codefresh on branch `master`.
1. Create a new branch and push it to your Git repository under a new branch.
1. Build your service with Codefresh on the new branch.
1. When the build completes execution, open its log.
You should see something similar to the example below.

{% include image.html
lightbox="true"
file="/images/testing/dynamic-preview-environment.png"
url="/images/testing/dynamic-preview-environment.png"
alt="Launch environment on single branch"
caption="Launch environment on single branch"
max-width="70%"
%}

## Related articles
[Codefresh YAML]({{site.baseurl}}/docs/pipelines/what-is-the-codefresh-yaml/)
[Creating compositions]({{site.baseurl}}/docs/testing/create-composition/)
[Integration tests]({{site.baseurl}}/docs/testing/integration-tests/)
[Service containers]({{site.baseurl}}/docs/pipelines/service-containers/)
98 changes: 98 additions & 0 deletions _docs/testing/composition-service-discovery.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
---
title: "Composition Service Discovery (Experimental)"
description: ""
group: testing
redirect_from:
- /docs/integration-tests/
- /docs/on-demand-test-environment/composition-service-discovery/
toc: true
---
Codefresh enables you to launch multiple instances of the same composition utilizing Docker.
This is possible, in part, because Docker can map ports from a container to a random port on a host. Following from this are some basic questions:
* If your container is mapped to a random port, how can you predict the URL of the application?
* How can you configure your web application's container with a "Base URL"?
* How can you reference other services without linking to them?

{{site.data.callout.callout_info}}
##### Availability

This feature is available for users with a Pro subscription. <br>
Already a Pro subscriber? Contact us to opt into this feature.
{{site.data.callout.end}}

Codefresh utilizes `Dynamic Composition Service Routing` to deliver seamless service discovery within a composition.

After you enable this feature for your account, Codefresh injects the URLs of every service in your composition as environment variables.

## What do these environment variables look like?

Every service URL environment variable is prefixed with `CF_URL_` and is uniquely identifiable using the service name:
`CF_URL_SERVICENAME=http://foo.cf-cd.com/unique-url`.

If your service exposes multiple ports, an environment variable will be injected for every port, and will be comprised of a combination of the service name and the service's port:
`CF_URL_SERVICENAME_PORTNUMBER=http://foo.cf-cd.com/unique-url-1`.

Also, every service would be having a domain that would direct to each service. The domains can be uniquely identifiable with environments variables:
`CF_DOMAIN_SERVICENAME=unique-prefix.foo.cf-cd.com`.

For services that exposes multiple ports the environment variable should have the port number as a suffix:
`CF_DOMAIN_SERVICENAME_PORTNUMBER=unique-prefix-1.foo.cf-cd.com`.

{{site.data.callout.callout_warning}}
##### Note:

The unique identifier is the service's name, not the name of the container that was produced for the service.
{{site.data.callout.end}}

## Example

Consider the following composition:

`Composition.yml`
{% highlight yaml %}
version: '3'
services:
db:
image: postgres
api:
image: myorg/api
ports:
- 9000
links
- db
web:
image: myorg/web
ports:
- 80
- 8080
{% endhighlight %}

The `db` service does not expose any ports. The `api` service exposes port `9000`, and the `web` service exposes port `80` and port `8080`.

So, every container produced by this composition will be injected with:

```
CF_URL_API=http://foo.cf-cd.com/someurl
CF_URL_WEB_80=http://foo.cf-cd.com/someurl2
CF_URL_WEB_8080=http://foo.cf-cd.com/someurl3

CF_DOMAIN_API=some-name.foo.cf-cd.com
CF_DOMAIN_WEB_80=some-name2.foo.cf-cd.com
CF_DOMAIN_WEB_8080=some-name3.foo.cf-cd.com
```

This means you can also discover these URLs within your application.
For example, within a Node.js application you can run the following routine:

`Find all service URLs`
{% highlight javascript %}
const allVars = process.env;
const allUrls = Object.keys(allVars)
.filter(envVarKey => envVarKey.startsWith('CF_URL_'))
.reduce((obj, envVarKey) => {
obj[envVarKey] = allVars[envVarKey];
return obj;
}, {});
{% endhighlight %}

The `allUrls` object will retain all the injected URL environment variables.
Loading