Skip to content

Instantly share code, notes, and snippets.

@glinton
Created July 6, 2017 17:31
Show Gist options
  • Save glinton/6289674f79d55b29d319611611826ed7 to your computer and use it in GitHub Desktop.
Save glinton/6289674f79d55b29d319611611826ed7 to your computer and use it in GitHub Desktop.
Share app databases on nanobox (experimental, non-recommended, and non-supported)

Tunnel to your other app's shared database

This requires two apps that you own/have access to. For clarity, we'll refer to the app with the shared database as the "server" app, and the one wanting to connect, the "client" app. This is not recommended nor supported by nanobox.

Note: You'll need to ensure NANOBOX_USERNAME and NANOBOX_PASSWORD are set on your "client" app

Manual Walkthrough

Fetch the nanobox binary. Run from your client component(s) in your client app

curl -o /usr/local/bin/nanobox \
  https://s3.amazonaws.com/tools.nanobox.io/nanobox/v2/linux/amd64/nanobox

chmod 755 /usr/local/bin/nanobox

# configure nanobox a bit
nanobox config set ci-mode true
nanobox config set provider native

Next, fake docker. This must be done until nanobox doesn't check for docker on simple tunnel commands

cat > /bin/docker <<EOF
#!/bin/bash
echo this is the real docker
EOF

chmod 755 /bin/docker

Now, create a tunnel.

nanobox tunnel server-app data.db

Verify it works (from another terminal). (Connect to 127.0.0.1 and the output in the tunnel)

$ psql -U nanobox -W gonano -h 127.0.0.1
Password for user nanobox: 
psql (9.5.7)
Type "help" for help.

gonano=#

Complete example files (probably works*)

boxfile.yml (client)

...
deploy.config:
  transform:
    - sudo ./tunnel
    - nanobox config set ci-mode true
    - nanobox config set provider native

web.tunneltest:
  start:
    app: /app/run --pg_host=127.0.0.1 --pg_pass=FromDashboard1234 --pg_port=5432 --pg_user=gonano
    tunnel: nanobox tunnel pg-test data.db

tunnel (must be executable)

# install nanobox
curl -o /usr/local/bin/nanobox \
  https://s3.amazonaws.com/tools.nanobox.io/nanobox/v2/linux/amd64/nanobox

chmod 755 /usr/local/bin/nanobox

# fake docker
cat > /bin/docker <<EOF
#!/bin/bash
echo this is the real docker
EOF

chmod 755 /bin/docker

*Works fine running the tunnel manually, but I couldn't connect psql to the remote when the tunnel was running as a service. Possibly a bug with tunnel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment