How do I set up environment-specific .qgtunnel files?

    Table of contents

    There are three options to make this work. Each works perfectly fine and either can be adjusted to fit your needs.

    A) We’ve added the ability to store the configuration file in an environment variable “QGTUNNEL_CONFIG”.

    Note: The QGTUNNEL_CONFIG option will only work if you have the April 2021 (or later) version of qgtunnel installed.

    If you aren’t sure if you have the most recent version of qgtunnel, you can grab it using:

    curl https://s3.amazonaws.com/quotaguard/qgtunnel-latest.tar.gz | tar xz

    You will want to set the environment variable to the content of the .qgtunnel file. (You don’t need to put the qgtunnel file in your repo). ​ So if you are on Heroku you would set it like this:

    heroku config:set -a $APPNAME QGTUNNEL_CONFIG='[qgtunnel.mysql]
    accept = "localhost:3306"
    connect = "tcp://abcdef1234567890.us-east-1.rds.amazonaws.com:3306"
    transparent = true'
    

    B) You can also handle this with a launch script by making a .qgtunnel.staging and a .qgtunnel.production file.

    Then in the launch script do something like this:

    #!/bin/bash
    
    if [ "$ENVIRONMENT" == "staging" ]; then
      cp .qgtunnel.staging .qgtunnel
    else
      cp .qgtunnel.production .qgtunnel
    fi
    
    bin/qgtunnel $@
    

    Save that as something like bin/qglaunch.

    Then change your startup code to call bin/qglaunch with all your program arguments instead of bin/qgtunnel.

    C) We’ve seen some customers save the full .qgtunnel file into an environment variable and in the launch script they create the .qgtunnel file from the environment variable.

    Note: If you are using transparent mode, be sure that vendor/nss_wrapper/libnss_wrapper.so is also added to your repository.

    You can use this variable to help in situations where you have multiple environments and want to make sure they’re starting up with the right configuration file.

    Pretty easy, huh?

    Happy tunneling!


    Ready to Get Started?

    Get in touch or create a free trial account