Skip to content

datawire/telepresence-actions

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

telepresence-actions

Telepresence combined with GitHub Actions allows you to run integration tests in your CI pipeline without having to run any dependant service. By connecting to the target Kubernetes cluster, intercepting traffic to the remote service and sending it to an instance of the service running in CI you will be able to test bugfixes, updates and features very easily.

v1.1.0

The v1.1.0 release contains the following changes

  1. Fix issues with Ambassador Cloud access needed during run.
  2. Move namespace option from intercept action to connect action (Telepresence 2.16)
  3. Remove the (undocumented) configure action.
  4. Add integration tests.

v1.0.0

The v1.0.0 of Telepresence GitHub Actions contains individual actions to:

  1. Install the Telepresence binary in the Github runner.
  2. Helm install the telepresence traffic manager in the cluster.
  3. Connect to a remote Kubernetes cluster.
  4. Log into Ambassador and create a personal intercept.
  5. Intercept traffic of service running in the K8s cluster and redirect it a service instance running in CI.

See the Telepresence GitHub actions documentation page for information about how to use these actions and build an integration tests workflow for your repository. Note: The version v1.0.0 only supports Ubuntu runners at moment.

Usage

Prerequisites

Get a free Ambassador Cloud account. Register here to get a free account. No credit card required.

Steps

The following is an example of a workflow that:

  1. Checks out the repository code.
  2. Has a placeholder step to run a service during CI.
  3. Creates the /opt/kubeconfig file with the contents of the secrets.KUBECONFIG_FILE to make it available for Telepresence.
  4. Installs Telepresence.
  5. Runs Telepresence Connect.
  6. Logs into Ambassador Telepresence.
  7. Intercepts traffic to the service running in the remote cluster.
  8. A placeholder for an action that would run integration tests, like making HTTP requests to your running service and verify it works while dependant services run in the remote cluster.
  name: Run Integration Tests
  on:
    push:
      branches-ignore:
      - 'main'
  jobs:
    my-job:
      name: Run Integration Test using Remote Cluster
      runs-on: ubuntu-latest
      env:
        TELEPRESENCE_API_KEY: ${{ secrets.TELEPRESENCE_API_KEY }}
        KUBECONFIG_FILE: ${{ secrets.KUBECONFIG_FILE }}
        KUBECONFIG: /opt/kubeconfig
      steps:
      - name : Checkout
        uses: actions/checkout@v3
        with:
          ref: ${{ github.event.pull_request.head.sha }}
      #---- here run your custom command to run your service
      #- name: Run your service to test
      #  shell: bash
      #  run: ./run_local_service
      #----
      # First you need to log in to Telepresence, with your api key
      - name: Create kubeconfig file
        run: |
          cat <<EOF > /opt/kubeconfig
          ${{ env.KUBECONFIG_FILE }}
          EOF
      - name: Install Telepresence
        uses: datawire/telepresence-actions/install@v1.1
        with:
          version: 2.19.0 # Change the version number here according to the version of Telepresence in your cluster or omit this parameter to install the latest version
      - name: Install Traffic Manager
        uses: datawire/telepresence-actions/helm@v1.1
      - name: Telepresence connect
        uses: datawire/telepresence-actions/connect@v1.1
      - name: Login
        uses: datawire/telepresence-actions/login@v1.1
        with:
          telepresence_api_key: ${{ secrets.TELEPRESENCE_API_KEY }}
      - name: Intercept the service
        uses: datawire/telepresence-actions/intercept@v1.1
        with:
          service_name: service-name
          service_port: 8081:8080
          http_header: "x-telepresence-intercept-test=service-intercepted" # Custom HTTP header name and value that will identify traffic desired to go to the local service instace.
          print_logs: true # Flag to instruct the action to print out Telepresence logs and export an artifact with them
      #---- Run a custom command to run integration tests.
      #- name: Run integrations test
      #  shell: bash
      #  run: ./run_integration_test
      #----