Skip to content

Commit

Permalink
Merge pull request #15 from shaowenchen/dev
Browse files Browse the repository at this point in the history
feature: add tunnels for ngork
  • Loading branch information
shaowenchen authored Jan 19, 2021
2 parents 03f8393 + acec235 commit 9ff2db5
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ngrok.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ jobs:
continue-on-error: true
with:
ngrok_token: ${{ secrets.NGROK_TOKEN }}
ngrok_addr_1: 30000
ngrok_proto_1: tcp
ngrok_addr_2: 30001
ngrok_proto_2: tcp
ngrok_addr_3: 30002
ngrok_proto_3: tcp
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Two types of proxies are supported:
3. Run your workflow and login the runner
In the log of GitHub Actions, you can see that:
In the log of GitHub Actions, find **localhost:8000** and you can see that:
```txt
t=2021-01-19T03:57:10+0000 lvl=info msg="started tunnel" obj=tunnels name=command_line addr=//localhost:8000 url=tcp://2.tcp.ngrok.io:16400
Expand Down Expand Up @@ -61,6 +61,29 @@ work

**Required** Authenticate to ngrok agent.

#### `ngrok_proto_{x}` and `ngrok_proto_{x}`

x in [1, 2, 3] , e.g:

```yaml
- uses: shaowenchen/debugger-action@v2
name: debugger
timeout-minutes: 30
continue-on-error: true
with:
ngrok_token: ${{ secrets.NGROK_TOKEN }}
ngrok_addr_1: 30000
ngrok_proto_1: tcp
ngrok_addr_2: 30001
ngrok_proto_2: tcp
ngrok_addr_3: 30002
ngrok_proto_3: tcp
```
It will expose these services to Ngrok. The maximum number of tunnels is 3, and http will take up 2 .
####
## How to use by Frp Server
### Prerequisites
Expand Down
24 changes: 24 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,30 @@ inputs:
required: false
description: 'ngrok token'
default: ''
ngrok_addr_1:
required: false
description: 'ngrok addr 1 to tunnel'
default: ''
ngrok_proto_1:
required: false
description: 'ngrok proto 1 to tunnel'
default: ''
ngrok_addr_2:
required: false
description: 'ngrok addr 2 to tunnel'
default: ''
ngrok_proto_2:
required: false
description: 'ngrok proto 2 to tunnel'
default: ''
ngrok_addr_3:
required: false
description: 'ngrok addr 3 to tunnel'
default: ''
ngrok_proto_3:
required: false
description: 'ngrok proto 3 to tunnel'
default: ''
runs:
using: 'node12'
main: 'dist/index.js'
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"@actions/core": "^1.2.6",
"@actions/exec": "^1.0.4",
"@actions/tool-cache": "^1.6.1",
"ini": "^2.0.0"
"ini": "^2.0.0",
"yaml": "^1.10.0"
},
"devDependencies": {
"@types/ini": "^1.3.30",
Expand Down
52 changes: 49 additions & 3 deletions src/ngrok.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import * as util from 'util'
import * as exec from '@actions/exec'
import * as core from '@actions/core'
import * as toolCache from '@actions/tool-cache'
import {downloadCache, getOsType} from './utils'
import YAML from 'yaml'
import {writeFile} from 'fs'
import {promisify} from 'util'

const writeFileAsync = promisify(writeFile)

const name = 'ngrok'
const defaultVersion = '4VmDzA7iaHb'
Expand All @@ -12,6 +18,46 @@ function getFullName(): string {
return util.format('ngrok-stable-%s-amd64', getOsType())
}

async function writeTunnel(path: string, token: string): Promise<string> {
const config = Object()
config['authtoken'] = token
config['tunnels'] = {
'tcp-8000': {
addr: '8000',
proto: 'tcp'
}
}
const addr_1: string = core.getInput('ngrok_addr_1')
const proto_1: string = core.getInput('ngrok_proto_1')
const addr_2: string = core.getInput('ngrok_addr_2')
const proto_2: string = core.getInput('ngrok_proto_2')
const addr_3: string = core.getInput('ngrok_addr_3')
const proto_3: string = core.getInput('ngrok_proto_3')
if (addr_1 !== '' && proto_1 !== '') {
const key_1 = util.format('%s-%s', proto_1, addr_1)
config['tunnels'][key_1] = {
addr: addr_1,
proto: proto_1
}
}
if (addr_2 !== '' && proto_2 !== '') {
const key_2 = util.format('%s-%s', proto_2, addr_2)
config['tunnels'][key_2] = {
addr: addr_2,
proto: proto_2
}
}
if (addr_3 !== '' && proto_3 !== '') {
const key_3 = util.format('%s-%s', proto_3, addr_3)
config['tunnels'][key_3] = {
addr: addr_3,
proto: proto_3
}
}
await writeFileAsync(path, YAML.stringify(config))
return path
}

async function getExecPath(version: string): Promise<string> {
const downloadUrl = util.format(
downloadUrlScheme,
Expand All @@ -32,11 +78,11 @@ async function getExecPath(version: string): Promise<string> {
export async function ngrok(NGROK_TOKEN: string): Promise<string> {
const version = defaultVersion
const execPath = await getExecPath(version)
const cfgFile = util.format('%s/ngrok.cfg', execPath)
writeTunnel(cfgFile, NGROK_TOKEN)
const cmdList = [
util.format('rm -f %s/.ngrok.log', execPath),
util.format('%s/ngrok authtoken "%s"', execPath, NGROK_TOKEN),
util.format('chmod +x %s/ngrok', execPath),
util.format('%s/ngrok tcp 8000 --log=stdout --log-level=info', execPath)
util.format('%s/ngrok start --all --config %s --log "stdout"', execPath, cfgFile)
]
return new Promise(resolve => {
;(async function () {
Expand Down

0 comments on commit 9ff2db5

Please sign in to comment.