Skip to content

Commit

Permalink
dockerHost feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Dyl committed Apr 14, 2020
1 parent a5f7685 commit d29f80c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/config/commandOptions.js
Expand Up @@ -72,4 +72,7 @@ export default {
useDocker: {
usage: 'Uses docker for node/python/ruby',
},
dockerHost: {
usage: 'The host name of Docker. Default: localhost',
},
}
1 change: 1 addition & 0 deletions src/config/defaultOptions.js
Expand Up @@ -22,4 +22,5 @@ export default {
useWorkerThreads: false,
websocketPort: 3001,
useDocker: false,
dockerHost: 'localhost',
}
2 changes: 1 addition & 1 deletion src/lambda/handler-runner/HandlerRunner.js
Expand Up @@ -34,7 +34,7 @@ export default class HandlerRunner {

if (useDocker) {
const { default: DockerRunner } = await import('./docker-runner/index.js')
return new DockerRunner(this.#funOptions, this.#env)
return new DockerRunner(this.#funOptions, this.#env, this.#options)
}

if (supportedNodejs.has(runtime)) {
Expand Down
8 changes: 5 additions & 3 deletions src/lambda/handler-runner/docker-runner/DockerContainer.js
Expand Up @@ -19,13 +19,15 @@ export default class DockerContainer {
#imageNameTag = null
#image = null
#port = null
#host = null

constructor(env, functionKey, handler, runtime) {
constructor(env, functionKey, handler, runtime, host) {
this.#env = env
this.#functionKey = functionKey
this.#handler = handler
this.#imageNameTag = this._baseImage(runtime)
this.#image = new DockerImage(this.#imageNameTag)
this.#host = host
}

_baseImage(runtime) {
Expand Down Expand Up @@ -118,7 +120,7 @@ export default class DockerContainer {
}

async _ping() {
const url = `http://localhost:${this.#port}/2018-06-01/ping`
const url = `http://${this.#host}:${this.#port}/2018-06-01/ping`
const res = await fetch(url)

if (!res.ok) {
Expand All @@ -129,7 +131,7 @@ export default class DockerContainer {
}

async request(event) {
const url = `http://localhost:${this.#port}/2015-03-31/functions/${
const url = `http://${this.#host}:${this.#port}/2015-03-31/functions/${
this.#functionKey
}/invocations`
const res = await fetch(url, {
Expand Down
5 changes: 3 additions & 2 deletions src/lambda/handler-runner/docker-runner/DockerRunner.js
Expand Up @@ -5,11 +5,12 @@ export default class DockerRunner {
#codeDir = null
#container = null

constructor(funOptions, env) {
constructor(funOptions, env, options) {
const { codeDir, functionKey, handler, runtime } = funOptions
const { dockerHost } = options

this.#codeDir = codeDir
this.#container = new DockerContainer(env, functionKey, handler, runtime)
this.#container = new DockerContainer(env, functionKey, handler, runtime, dockerHost)
}

cleanup() {
Expand Down

0 comments on commit d29f80c

Please sign in to comment.