Installing and running Tyk Sync

Last updated: 4 minutes read.

Pre-requisites

  • Access to a Git repository or local file system for storing configurations
  • Tyk Gateway or Tyk Dashboard

Gateway and Dashboard Version


Tyk Sync manages API definition and require an update whenever the API definition schema has changed in Gateway or Dashboard. Please check the “Compatibility Matrix For Tyk Components” section in Tyk Gateway and Dashboard’s release notes to select the correct version of Tyk Sync.

Gateway and Dashboard Configuration


Tyk Sync tries to be clever about what APIs and Policies to update and which to create, it will actually base all ID matching on the API ID and the masked Policy ID, so it can identify the same object across installations. Tyk has a tendency to generate fresh IDs for all new Objects, so Tyk Sync gets around this by using portable IDs and ensuring the necessary portable IDs are set when using the dump command.

In order for policy ID matching to work correctly, your Dashboard must have allow_explicit_policy_id and enable_duplicate_slugs set to true and your Gateway must have policies.allow_explicit_policy_id set to true.

Installation

Currently the application is available via Docker and Packagecloud.

Docker

To install Tyk Sync using Docker, follow these steps:

1. Pull the Docker image from the Tyk repository

Make sure to specify the version tag you need. For example, to pull version v1.5.0, use the following command:

SYNC_VERSION=v1.5.0
docker pull tykio/tyk-sync:$SYNC_VERSION

All docker images are available on the Tyk Sync Docker Hub page.

2. Run Tyk Sync
SYNC_VERSION=v1.5.0
docker run tykio/tyk-sync:$SYNC_VERSION [command] [flag]

If you want to dump your API configurations to the local file system or sync configurations saved locally to Tyk, use Docker bind mounts:

docker run -v /path/to/local/directory:/app/data tykio/tyk-sync:$SYNC_VERSION [command] [flag]

Replace [command] with the specific Tyk Sync command you want to execute.

Command usage

The following flags can be passed to tyk-sync commands to specify how to connect to the target Tyk installation and where the source API configurations are stored.

Check version

To check the version of Tyk Sync installed, use the version command. This command displays the current version of Tyk Sync that is installed on your system.

tyk-sync version

This will output the version information, helping you ensure that you have the correct version installed for your needs.

Getting help

To display usage options please do:

tyk-sync help

You can also get help with any commands with -h or --help flag.

tyk-sync [command] --help

Specifying target Tyk installation

Tyk Dashboard

For Dashboard users, you can provide the necessary connection details using the --dashboard and --secret options.

tyk-sync --dashboard <DASHBOARD_URL> --secret <SECRET> [command] [flags]

DASHBOARD_URL is the fully qualified dashboard target URL (e.g. http://localhost:3000) and SECRET refers to the API access key use to access your Dashboard API. For dashboard users, you can get it from the “Users” page under “Tyk Dashboard API Access Credentials”.

If you prefer not to provide the secret via the command line, you can set the environment variable TYKGIT_DB_SECRET instead. This method keeps your secret secure and avoids exposure in command history.

export TYKGIT_DB_SECRET=<SECRET>
tyk-sync --dashboard <DASHBOARD_URL> [command] [flags]

Open Source Gateway

For open source Gateway users, you can provide the necessary connection details using the --gateway and --secret options.

tyk-sync --gateway <GATEWAY_URL> --secret <SECRET> [command] [flags]

GATEWAY_URL is the fully qualified gateway target URL (e.g. http://localhost:8080) and SECRET refers to the API secret (secret parameter in your tyk.conf file) used to access your Gateway API.

If you prefer not to provide the secret via the command line, you can set the environment variable TYKGIT_GW_SECRET instead. This method keeps your secret secure and avoids exposure in command history.

export TYKGIT_GW_SECRET=<SECRET>
tyk-sync --gateway <GATEWAY_URL> [command] [flags]

Specifying source API configurations

For the sync, update, and publish commands, you need to specify where Tyk Sync can get the source API configurations to update the target Tyk installation. You can store the source files either in a Git repository or the local file system.

Working with Git

For any Tyk Sync command that requires Git repository access, specify the Git repository as the first argument after the command. By default, Tyk Sync reads from the master branch. To specify a different branch, use the --branch or -b flag. If the Git repository requires connection using Secure Shell Protocol (SSH), you can specify SSH keys with --key or -k flag.

tyk-sync [command] https://github.com/your-repo --branch develop

Working with the local file system

To update API configurations from the local file system, use the --path or -p flag to specify the source directory for your API configuration files.

tyk-sync [command] --path /path/to/local/directory

Index File Requirement

A .tyk.json index file is required at the root of the source Git repository or the specified path. This .tyk.json file lists all the files that should be processed by Tyk Sync.

Example .tyk.json:

{
  "type": "apidef",
  "files": [
    {
      "file": "api1/api1.json"
    },
    {
      "file": "api2/api2.json"
    },
    {
      "file": "api3.json"
    }
  ],
  "policies": [
    {
      "file": "policy1.json"
    }
  ],
  "assets": [
    {
      "file": "template1.json"
    }
  ]
}