-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
working port forwarding via exec instance
Signed-off-by: Jonah Iden <jonah.iden@typefox.io>
- Loading branch information
1 parent
b4882b1
commit 54c5a43
Showing
5 changed files
with
87 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
packages/dev-container/src/dev-container-server/dev-container-server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// ***************************************************************************** | ||
// Copyright (C) 2024 Typefox and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0. | ||
// | ||
// This Source Code may also be made available under the following Secondary | ||
// Licenses when the conditions for such availability set forth in the Eclipse | ||
// Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
// with the GNU Classpath Exception which is available at | ||
// https://www.gnu.org/software/classpath/license.html. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 | ||
// ***************************************************************************** | ||
|
||
import { createConnection } from 'net'; | ||
import { stdin, argv, stdout } from 'process'; | ||
|
||
/** | ||
* this node.js Program is supposed to be executed by an docker exec session inside a docker container. | ||
* It uses a tty session to listen on stdin and send on stdout all communication with the theia backend running inside the container. | ||
*/ | ||
|
||
let backendPort: number | undefined = undefined; | ||
argv.slice(2).forEach(arg => { | ||
if (arg.startsWith('-target-port')) { | ||
backendPort = parseInt(arg.split('=')[1]); | ||
} | ||
}); | ||
|
||
if (!backendPort) { | ||
throw new Error('please start with -target-port={port number}'); | ||
} | ||
if (stdin.isTTY) { | ||
stdin.setRawMode(true); | ||
} | ||
const connection = createConnection(backendPort, '0.0.0.0'); | ||
|
||
connection.pipe(stdout); | ||
stdin.pipe(connection); | ||
|
||
connection.on('error', error => { | ||
console.error('connection error', error); | ||
}); | ||
|
||
connection.on('close', () => { | ||
console.log('connection closed'); | ||
process.exit(0); | ||
}); | ||
|
||
// keep the process running | ||
setInterval(() => { }, 1 << 30); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters