Commented ngrok.

This commit is contained in:
Alexander Artemenko 2021-02-06 21:08:18 +03:00
parent 5df131f7e1
commit d903b9a2d1

View file

@ -7,19 +7,19 @@ inputs:
qlfile-template: qlfile-template:
description: "Djula template for qlfile. All environment variables are available in it's context" description: "Djula template for qlfile. All environment variables are available in it's context"
required: false required: false
SSH_PASS: # SSH_PASS:
description: 'Password for SSH session' # description: 'Password for SSH session'
required: true # required: true
NGROK_AUTH_TOKEN: # NGROK_AUTH_TOKEN:
description: 'Authentification token for ngrok' # description: 'Authentification token for ngrok'
required: true # required: true
NGROK_REGION: # NGROK_REGION:
description: 'Region for ngrok session' # description: 'Region for ngrok session'
required: false # required: false
default: 'us' # default: 'us'
NGROK_TIMEOUT: # NGROK_TIMEOUT:
description: 'Timeout in seconds for ngrok session' # description: 'Timeout in seconds for ngrok session'
default: 21500 # default: 21500
runs: runs:
using: composite using: composite
@ -36,130 +36,130 @@ runs:
qlot exec ros install docs-builder qlot exec ros install docs-builder
echo ::endgroup:: echo ::endgroup::
- name: Check inputs # - name: Check inputs
run: | # run: |
if [ -z "${{ inputs.SSH_PASS }}" ] # if [ -z "${{ inputs.SSH_PASS }}" ]
then # then
echo "SSH_PASS needs to be passed in the 'with' field." # echo "SSH_PASS needs to be passed in the 'with' field."
exit 1 # exit 1
fi # fi
if [ -z "${{ inputs.NGROK_AUTH_TOKEN }}" ] # if [ -z "${{ inputs.NGROK_AUTH_TOKEN }}" ]
then # then
echo "NGROK_AUTH_TOKEN needs to be passed in the 'with' field." # echo "NGROK_AUTH_TOKEN needs to be passed in the 'with' field."
exit 1 # exit 1
fi # fi
shell: bash # shell: bash
- name: Meet OS specific prerequisites # - name: Meet OS specific prerequisites
run: | # run: |
if('${{ runner.os }}' -eq 'Linux') # if('${{ runner.os }}' -eq 'Linux')
{ # {
printf "# Preparing environment..." # printf "# Preparing environment..."
echo "ngrok-stable-linux-386.zip" > ngrok_zip_name # echo "ngrok-stable-linux-386.zip" > ngrok_zip_name
whoami > ssh_user # whoami > ssh_user
printf " [DONE]\n\n" # printf " [DONE]\n\n"
echo "# Change the SSH user password" # echo "# Change the SSH user password"
echo "${{ inputs.SSH_PASS }}`n${{ inputs.SSH_PASS }}" | sudo passwd $(cat ssh_user) # echo "${{ inputs.SSH_PASS }}`n${{ inputs.SSH_PASS }}" | sudo passwd $(cat ssh_user)
} # }
elseif('${{ runner.os }}' -eq 'macOS') # elseif('${{ runner.os }}' -eq 'macOS')
{ # {
printf "# Preparing environment..." # printf "# Preparing environment..."
echo "ngrok-stable-darwin-amd64.zip" > ngrok_zip_name # echo "ngrok-stable-darwin-amd64.zip" > ngrok_zip_name
echo "root" > ssh_user # echo "root" > ssh_user
printf " [DONE]\n\n" # printf " [DONE]\n\n"
echo "# Change the SSH user password" # echo "# Change the SSH user password"
echo 'PermitRootLogin yes' | sudo tee -a /etc/ssh/sshd_config >/dev/null # echo 'PermitRootLogin yes' | sudo tee -a /etc/ssh/sshd_config >/dev/null
sudo launchctl unload /System/Library/LaunchDaemons/ssh.plist # sudo launchctl unload /System/Library/LaunchDaemons/ssh.plist
sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist # sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist
echo "${{ inputs.SSH_PASS }}`n${{ inputs.SSH_PASS }}" | sudo passwd "root" # echo "${{ inputs.SSH_PASS }}`n${{ inputs.SSH_PASS }}" | sudo passwd "root"
} # }
elseif('${{ runner.os }}' -eq 'Windows') # elseif('${{ runner.os }}' -eq 'Windows')
{ # {
printf "# Preparing environment..." # printf "# Preparing environment..."
echo "ngrok-stable-windows-amd64.zip" > ngrok_zip_name # echo "ngrok-stable-windows-amd64.zip" > ngrok_zip_name
echo $env:UserName > ssh_user # echo $env:UserName > ssh_user
printf " [DONE]\n\n" # printf " [DONE]\n\n"
echo "# Install SSH server" # echo "# Install SSH server"
curl https://dl.bitvise.com/BvSshServer-Inst.exe --output BvSshServer-Inst.exe # curl https://dl.bitvise.com/BvSshServer-Inst.exe --output BvSshServer-Inst.exe
.\BvSshServer-Inst.exe -acceptEULA -defaultInstance # .\BvSshServer-Inst.exe -acceptEULA -defaultInstance
printf "# Setting up the SSH server to allow access..." # printf "# Setting up the SSH server to allow access..."
$cfg = new-object -com "BssCfg815.BssCfg815" # $cfg = new-object -com "BssCfg815.BssCfg815"
$cfg.settings.SetDefaults() # $cfg.settings.SetDefaults()
$cfg.settings.access.SetDefaults() # $cfg.settings.access.SetDefaults()
$cfg.settings.access.winGroups.Clear() # $cfg.settings.access.winGroups.Clear()
$cfg.settings.access.winGroups.new.SetDefaults() # $cfg.settings.access.winGroups.new.SetDefaults()
$cfg.settings.access.winGroups.new.loginAllowed = $true # $cfg.settings.access.winGroups.new.loginAllowed = $true
$cfg.settings.access.winGroups.NewCommit() # $cfg.settings.access.winGroups.NewCommit()
$cfg.settings.Save() # $cfg.settings.Save()
printf " [DONE]\n\n" # printf " [DONE]\n\n"
echo "# Add Firewall rule to allow inbound TCP connection on local port 22" # echo "# Add Firewall rule to allow inbound TCP connection on local port 22"
New-NetFirewallRule -Name ngrok -DisplayName 'ngrok' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 # New-NetFirewallRule -Name ngrok -DisplayName 'ngrok' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
echo "# Start the SSH server" # echo "# Start the SSH server"
net start BvSshServer # net start BvSshServer
echo "# Change the SSH user password" # echo "# Change the SSH user password"
net user $env:UserName ${{ inputs.SSH_PASS }} # net user $env:UserName ${{ inputs.SSH_PASS }}
} # }
shell: pwsh # shell: pwsh
- name: Install and setup ngrok # - name: Install and setup ngrok
run: | # run: |
echo "# Install ngrok" # echo "# Install ngrok"
curl https://bin.equinox.io/c/4VmDzA7iaHb/$(cat ngrok_zip_name) --output ngrok.zip # curl https://bin.equinox.io/c/4VmDzA7iaHb/$(cat ngrok_zip_name) --output ngrok.zip
unzip ngrok.zip # unzip ngrok.zip
chmod +x ./ngrok # chmod +x ./ngrok
echo "# Set ngrok with the given authentification token" # echo "# Set ngrok with the given authentification token"
./ngrok authtoken ${{ inputs.NGROK_AUTH_TOKEN }} # ./ngrok authtoken ${{ inputs.NGROK_AUTH_TOKEN }}
shell: bash # shell: bash
- name: Start ngrok # - name: Start ngrok
run: | # run: |
set -Eeuo pipefail # set -Eeuo pipefail
printf "# Starting ngrok..." # printf "# Starting ngrok..."
./ngrok tcp 22 --log ".ngrok.log" --region "${{ inputs.NGROK_REGION }}" & # ./ngrok tcp 22 --log ".ngrok.log" --region "${{ inputs.NGROK_REGION }}" &
printf " [DONE]\n\n" # printf " [DONE]\n\n"
printf "# Waiting for '.ngrok.log' file to be properly generated..." # printf "# Waiting for '.ngrok.log' file to be properly generated..."
while ! grep -osqE "tcp://(.+)" .ngrok.log;do # while ! grep -osqE "tcp://(.+)" .ngrok.log;do
sleep 1 # sleep 1
if grep -sq "command failed" .ngrok.log # if grep -sq "command failed" .ngrok.log
then # then
exit 1 # exit 1
fi # fi
done # done
printf " [DONE]\n\n" # printf " [DONE]\n\n"
ssh_string=$(grep -oE "tcp://(.+)" .ngrok.log | sed "s/tcp:\/\//ssh $(cat ssh_user)@/" | sed "s/:/ -p /") # ssh_string=$(grep -oE "tcp://(.+)" .ngrok.log | sed "s/tcp:\/\//ssh $(cat ssh_user)@/" | sed "s/:/ -p /")
continue_path=$(eval echo ~$(cat ssh_user)/continue) # continue_path=$(eval echo ~$(cat ssh_user)/continue)
time=${{ inputs.NGROK_TIMEOUT }} # time=${{ inputs.NGROK_TIMEOUT }}
while [ ! -e $continue_path ] && [ $time -gt 1 ] # while [ ! -e $continue_path ] && [ $time -gt 1 ]
do # do
echo "" # echo ""
echo "#################" # echo "#################"
echo "# Connect to this runner using:" # echo "# Connect to this runner using:"
echo "#########################################" # echo "#########################################"
echo $ssh_string # echo $ssh_string
echo "#########################################" # echo "#########################################"
echo "#" # echo "#"
echo "# Allow workflow to continue using:" # echo "# Allow workflow to continue using:"
echo "#########################################" # echo "#########################################"
echo "bash -c \"touch $continue_path\"" # echo "bash -c \"touch $continue_path\""
echo "#########################################" # echo "#########################################"
echo "#" # echo "#"
echo "# SSH session time left:" # echo "# SSH session time left:"
echo "########################################" # echo "########################################"
printf '#%-14s%dh:%02dm:%02ds%-14s#\n' '' $(($time/3600)) $(($time%3600/60)) $(($time%60)) '' # printf '#%-14s%dh:%02dm:%02ds%-14s#\n' '' $(($time/3600)) $(($time%3600/60)) $(($time%60)) ''
echo "########################################" # echo "########################################"
echo "" # echo ""
sleep 10 # sleep 10
time=$((time-10)) # time=$((time-10))
done # done
echo "# SSH session terminated. Allowing workflow to continue..." # echo "# SSH session terminated. Allowing workflow to continue..."
shell: bash # shell: bash
- name: Build Docs - name: Build Docs
@ -175,6 +175,7 @@ runs:
- name: Upload Docs - name: Upload Docs
shell: bash shell: bash
run: | run: |
set -Eeuo pipefail
echo ::group::Upload Docs echo ::group::Upload Docs
BUILD_DIR=${{ steps.build-docs.outputs.build-dir }} BUILD_DIR=${{ steps.build-docs.outputs.build-dir }}