Skip to content

Instantly share code, notes, and snippets.

@viktorbenei
Last active July 18, 2018 14:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viktorbenei/afccc1a777de027daf64f9331c6892fc to your computer and use it in GitHub Desktop.
Save viktorbenei/afccc1a777de027daf64f9331c6892fc to your computer and use it in GitHub Desktop.
Remote access via docker (bitrise GCE / Linux / Docker env)

Set the following Env Vars:

  • REMOTE_ACCESS_SSH_PUB_KEY: an SSH Public Key - you'll be able to SSH into the container with the private key of this public key. You can find your default public key on your Mac/Linux with: cat $HOME/.ssh/id_rsa.pub
  • NGROK_CONFIG: a full ngrok config

ngrok config example:

authtoken: NgrokAuthToken1234
tunnels:
  ssh:
    addr: 2222
    proto: tcp

You can get your Ngrok Auth Token at: https://dashboard.ngrok.com/auth

Once ngrok is started in the build you can find the SSH IP on ngrok at: https://dashboard.ngrok.com/status

To SSH into the Build VM / container: ssh root@0.tcp.ngrok.io -p PORT (you can find the PORT and the IP at https://dashboard.ngrok.com/status)

---
format_version: 3
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git
workflows:
allow-ssh-access:
steps:
- script@1.1.5:
title: mark myself for debug
inputs:
- content: |-
#!/usr/bin/env bash
set -ex
echo 'hi' > $HOME/test.txt
- script@1.1.5:
title: start ssh server as docker container on port 2222
inputs:
- content: |-
#!/usr/bin/env bash
set -ex
# --------------------------
# ORIGINAL solution
# docker run -d -p 2222:22 -v /var/run/docker.sock:/var/run/docker.sock -e FILTERS={\"name\":[\"^/bitrise-main-container$\"]} -e AUTH_MECHANISM=noAuth jeroenpeeters/docker-ssh
# --------------------------
# --------------------------
# New, better solution
# SSH config
mkdir -p /bitrise/remote-ssh
echo "command=\"docker exec -it bitrise-main-container bash\" $REMOTE_ACCESS_SSH_PUB_KEY" > /bitrise/remote-ssh/authorized_keys
# run bitrise-docker-ssh server with our special authorized_keys mounted in
docker run -d -p 2222:22 -v /var/run/docker.sock:/var/run/docker.sock -v /bitrise/remote-ssh:/root/.ssh bitriseio/bitrise-docker-ssh:latest
- script@1.1.5:
title: ngrok
inputs:
- content: |-
#!/usr/bin/env bash
set -ex
mkdir -p /tmp/ngrok
cd /tmp/ngrok
wget -O ngrok.zip https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip
unzip ./ngrok.zip
# write ngrok config into file
echo "$NGROK_CONFIG" > ./ngrok-config.yml
./ngrok start --all --config ./ngrok-config.yml
@sophiataskova
Copy link

Hello @viktorbenei, I ran through the steps and got asked for a password when I attempted to ssh into the ngrok port. Should I be able to ask Bitrise for that ssh password?

@viktorbenei
Copy link
Author

@sophiataskova there's no password. If SSH asks for password that means that no SSH key matched. That means that you forgot to activate the right SSH key.

To ensure the right SSH key is activated on your Mac/PC on Unix systems you should run:

# deactivate all SSH keys currently activated
ssh-add -D
# activate the SSH key you want to use
ssh-add $HOME/.ssh/id_rsa

Of course if you want to use a different SSH key you should change the path for ssh-add $HOME/.ssh/id_rsa.

If you'd have any questions just let me know! :)

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