Run Sauce Connect Proxy as a Background Step
Background steps are useful for running services that need to run for the entire lifetime of a Build stage. This tutorial shows how to run Sauce Connect Proxy as a Background step in a Harness CI pipeline.
Sauce Labs is a web and mobile application automated testing platform. Sauce Connect Proxy can run as a Background step in your Harness CI pipeline, and act as a proxy server between a Sauce Labs' infrastructure and your CI pipeline.
If you don't have a Harness account yet, you can create one for free at app.harness.io.
Create your pipeline
Docker Hub connector
You need a Docker Hub connector. In this example, the connector is used to authenticate to pull Docker images from Docker Hub.
If you have not created a Docker Hub connector yet, follow these steps.
Create connector
- From the left pane, expand the Project Setup, and then select Connectors.
- Select + New Connector, and then select Docker Registry.
- In the Name field, enter Docker Hub, and then select Continue.
- In the Docker Registry URL field, enter
https://index.docker.io/v2/
. - For Provider Type, select Docker Hub.
- In the Username field, enter your Docker Hub username.
- In the Password field, select Create or Select a Secret. Follow the prompts to add your Docker Hub access token, and then click Continue.
- At the next screen, select Connect through Harness Platform, and then select Save and Continue.
- After Harness performs a validation test, select Finish.
- In your list of connectors, note the ID of the connector that you just created. If you named the connector
Docker Hub
, the ID should beDocker_Hub
.
This connector needs an access token with Read-only permissions.
Create secret
- From the left pane, expand the Project Setup menu, and then select Secrets.
- Select + New Secret, then select Text.
- In the Secret Name field, enter Sauce Access Key.
- In the Secret Value field, enter your Sauce Labs access key, then click Save.
Modify the pipeline
- From the left pane, select Pipelines, then select + Create a Pipeline.
- In the Name field, enter a name for your pipeline, then select Start.
- Switch from the Visual view to the YAML view, and then select Edit YAML.
Append the following configuration:
- Cloud
- Kubernetes
Cloud pipelines run in managed infrastructure provided by Harness.
variables:
- name: SAUCELABS_USERNAME
type: String
description: Your Sauce Labs username
value: <+input>
stages:
- stage:
name: Sauce Connect
identifier: Sauce_Connect
description: ""
type: CI
spec:
cloneCodebase: false
platform:
os: Linux
arch: Amd64
runtime:
type: Cloud
spec: {}
execution:
steps:
- step:
type: Background
name: Sauce Connect
identifier: Sauce_Connect
spec:
connectorRef: Docker_Hub
image: saucelabs/sauce-connect
shell: Sh
envVariables:
SAUCE_USERNAME: <+pipeline.variables.SAUCELABS_USERNAME>
SAUCE_ACCESS_KEY: <+secrets.getValue('Sauce_Access_Key')>
portBindings:
"8032": "8032"
- step:
type: Run
name: Wait for SC
identifier: Wait_for_SC
spec:
shell: Bash
command: |-
until [ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:8032/readiness)" == "200" ]
do
sleep 2
done
echo "SC ready"
Kubernetes pipelines run in a Kubernetes cluster that you manage. Kubernetes pipelines are an enterprise feature.
variables:
- name: KUBERNETES_NAMESPACE
type: String
description: Kubernetes namespace where steps will run
value: <+input>
- name: SAUCELABS_USERNAME
type: String
description: Your Sauce Labs username
value: <+input>
stages:
- stage:
name: Sauce Connect
identifier: Sauce_Connect
description: ""
type: CI
spec:
cloneCodebase: false
infrastructure:
type: KubernetesDirect
spec:
connectorRef: Kubernetes_Connector
namespace: <+pipeline.variables.KUBERNETES_NAMESPACE>
automountServiceAccountToken: true
nodeSelector: {}
os: Linux
execution:
steps:
- step:
type: Background
name: Sauce Connect
identifier: Sauce_Connect
spec:
connectorRef: Docker_Hub
image: saucelabs/sauce-connect
shell: Sh
envVariables:
SAUCE_USERNAME: <+pipeline.variables.SAUCELABS_USERNAME>
SAUCE_ACCESS_KEY: <+secrets.getValue('Sauce_Access_Key')>
- step:
type: Run
name: Wait for SC
identifier: Wait_for_SC
spec:
connectorRef: Docker_Hub
image: curlimages/curl:7.83.1
shell: Sh
command: |-
until [ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:8032/readiness)" == "200" ]
do
sleep 2
done
echo "SC ready"
Replace Kubernetes_Connector
with your Kubernetes cluster connector ID.
This configuration requires the Docker Hub connector ID to be Docker_Hub
. If your connector ID is different, replace Docker_Hub
with the correct ID.
Select Save in the YAML editor.
Run your pipeline
- In the Pipeline Studio, select Run.
- Enter your Sauce Labs username in the
SAUCELABS_USERNAME
field. If you created a Kubernetes pipeline, enter the namespace in theKUBERNETES_NAMESPACE
field. - Select Run Pipeline.
- Observe each step of the pipeline execution. When Sauce Connect is ready, the Wait for SC step will print
SC ready
.