-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dev-Container support #13372
Merged
Merged
Dev-Container support #13372
Changes from 14 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
17ec00f
basics for dev-container support
jonah-iden 5568344
basic creating and connecting to container working
jonah-iden ec63903
open workspace when opening container
jonah-iden c4883b7
save and reuse last USed container per workspace
jonah-iden b45fbc3
restart container if running
jonah-iden 2735888
better container creation extension features
jonah-iden ad3d133
added dockerfile support
jonah-iden 8b977e4
rebuild container if devcontainer.json has been changed since last use
jonah-iden 5fcf759
fix build
jonah-iden 14c0f1f
fixed checking if container needs rebuild
jonah-iden d670f49
working port forwarding via exec instance
jonah-iden c05bd30
review changes
jonah-iden b45fb37
fix import
jonah-iden 4a18a6f
smaller fixes and added support for multiple devcontainer configurati…
jonah-iden f984ca2
basic output window for devcontainer build
jonah-iden 1e6dab5
smaller review changes and nicer dockerfile.json detection code
jonah-iden c70d6f1
fixed build and docuemented implemented devcontainer.json properties
jonah-iden File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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,10 @@ | ||
/** @type {import('eslint').Linter.Config} */ | ||
module.exports = { | ||
extends: [ | ||
'../../configs/build.eslintrc.json' | ||
], | ||
parserOptions: { | ||
tsconfigRootDir: __dirname, | ||
project: 'tsconfig.json' | ||
} | ||
}; |
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,30 @@ | ||
<div align='center'> | ||
|
||
<br /> | ||
|
||
<img src='https://raw.githubusercontent.com/eclipse-theia/theia/master/logo/theia.svg?sanitize=true' alt='theia-ext-logo' width='100px' /> | ||
|
||
<h2>ECLIPSE THEIA - DEV-CONTAINER EXTENSION</h2> | ||
|
||
<hr /> | ||
|
||
</div> | ||
|
||
## Description | ||
|
||
The `@theia/dev-container` extension provides functionality to create, start and connect to development containers similiar to the | ||
[vscode Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers). | ||
|
||
## Additional Information | ||
|
||
- [Theia - GitHub](https://github.com/eclipse-theia/theia) | ||
- [Theia - Website](https://theia-ide.org/) | ||
|
||
## License | ||
|
||
- [Eclipse Public License 2.0](http://www.eclipse.org/legal/epl-2.0/) | ||
- [一 (Secondary) GNU General Public License, version 2 with the GNU Classpath Exception](https://projects.eclipse.org/license/secondary-gpl-2.0-cp) | ||
|
||
## Trademark | ||
"Theia" is a trademark of the Eclipse Foundation | ||
https://www.eclipse.org/theia |
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 @@ | ||
{ | ||
"name": "@theia/dev-container", | ||
"version": "1.47.0", | ||
"description": "Theia - Editor Preview Extension", | ||
"dependencies": { | ||
"@theia/core": "1.47.0", | ||
"@theia/remote": "1.47.0", | ||
"@theia/workspace": "1.47.0", | ||
"dockerode": "^4.0.2", | ||
"uuid": "^8.0.0", | ||
"jsonc-parser": "^2.2.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"theiaExtensions": [ | ||
{ | ||
"frontendElectron": "lib/electron-browser/dev-container-frontend-module", | ||
"backendElectron": "lib/electron-node/dev-container-backend-module" | ||
} | ||
], | ||
"keywords": [ | ||
"theia-extension" | ||
], | ||
"license": "EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/eclipse-theia/theia.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/eclipse-theia/theia/issues" | ||
}, | ||
"homepage": "https://github.com/eclipse-theia/theia", | ||
"files": [ | ||
"lib", | ||
"src" | ||
], | ||
"scripts": { | ||
"build": "theiaext build", | ||
"clean": "theiaext clean", | ||
"compile": "theiaext compile", | ||
"lint": "theiaext lint", | ||
"test": "theiaext test", | ||
"watch": "theiaext watch" | ||
}, | ||
"devDependencies": { | ||
"@theia/ext-scripts": "1.47.0", | ||
"@types/dockerode": "^3.3.23" | ||
}, | ||
"nyc": { | ||
"extends": "../../configs/nyc.json" | ||
} | ||
} |
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}'); | ||
} | ||
jonah-iden marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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); |
97 changes: 97 additions & 0 deletions
97
packages/dev-container/src/electron-browser/container-connection-contribution.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,97 @@ | ||
// ***************************************************************************** | ||
// 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 { inject, injectable } from '@theia/core/shared/inversify'; | ||
import { AbstractRemoteRegistryContribution, RemoteRegistry } from '@theia/remote/lib/electron-browser/remote-registry-contribution'; | ||
import { LastContainerInfo, RemoteContainerConnectionProvider } from '../electron-common/remote-container-connection-provider'; | ||
import { RemotePreferences } from '@theia/remote/lib/electron-browser/remote-preferences'; | ||
import { WorkspaceStorageService } from '@theia/workspace/lib/browser/workspace-storage-service'; | ||
import { Command, QuickInputService } from '@theia/core'; | ||
import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service'; | ||
|
||
export namespace RemoteContainerCommands { | ||
export const REOPEN_IN_CONTAINER = Command.toLocalizedCommand({ | ||
id: 'dev-container:reopen-in-container', | ||
label: 'Reopen in Container', | ||
category: 'Dev Container' | ||
}, 'theia/dev-container/connect'); | ||
} | ||
|
||
const LAST_USED_CONTAINER = 'lastUsedContainer'; | ||
@injectable() | ||
export class ContainerConnectionContribution extends AbstractRemoteRegistryContribution { | ||
|
||
@inject(RemoteContainerConnectionProvider) | ||
protected readonly connectionProvider: RemoteContainerConnectionProvider; | ||
|
||
@inject(RemotePreferences) | ||
protected readonly remotePreferences: RemotePreferences; | ||
|
||
@inject(WorkspaceStorageService) | ||
protected readonly workspaceStorageService: WorkspaceStorageService; | ||
|
||
@inject(WorkspaceService) | ||
protected readonly workspaceService: WorkspaceService; | ||
|
||
@inject(QuickInputService) | ||
protected readonly quickInputService: QuickInputService; | ||
|
||
registerRemoteCommands(registry: RemoteRegistry): void { | ||
registry.registerCommand(RemoteContainerCommands.REOPEN_IN_CONTAINER, { | ||
execute: () => this.openInContainer() | ||
}); | ||
|
||
jonah-iden marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
async openInContainer(): Promise<void> { | ||
const devcontainerFile = await this.getOrSelectDevcontainerFile(); | ||
if (!devcontainerFile) { | ||
return; | ||
} | ||
const lastContainerInfoKey = `${LAST_USED_CONTAINER}:${devcontainerFile}`; | ||
const lastContainerInfo = await this.workspaceStorageService.getData<LastContainerInfo | undefined>(lastContainerInfoKey); | ||
|
||
const connectionResult = await this.connectionProvider.connectToContainer({ | ||
nodeDownloadTemplate: this.remotePreferences['remote.nodeDownloadTemplate'], | ||
lastContainerInfo, | ||
devcontainerFile | ||
}); | ||
|
||
this.workspaceStorageService.setData<LastContainerInfo>(lastContainerInfoKey, { | ||
id: connectionResult.containerId, | ||
lastUsed: Date.now() | ||
}); | ||
|
||
this.openRemote(connectionResult.port, false, connectionResult.workspacePath); | ||
} | ||
|
||
async getOrSelectDevcontainerFile(): Promise<string | undefined> { | ||
const devcontainerFiles = await this.connectionProvider.getDevContainerFiles(); | ||
|
||
if (devcontainerFiles.length === 1) { | ||
return devcontainerFiles[0].path; | ||
} | ||
|
||
return (await this.quickInputService.pick(devcontainerFiles.map(file => ({ | ||
type: 'item', | ||
label: file.name, | ||
description: file.path, | ||
file: file.path, | ||
})), { | ||
title: 'Select a devcontainer.json file' | ||
}))?.file; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
packages/dev-container/src/electron-browser/dev-container-frontend-module.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,30 @@ | ||
// ***************************************************************************** | ||
// 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 { ContainerModule } from '@theia/core/shared/inversify'; | ||
import { RemoteRegistryContribution } from '@theia/remote/lib/electron-browser/remote-registry-contribution'; | ||
import { RemoteContainerConnectionProvider, RemoteContainerConnectionProviderPath } from '../electron-common/remote-container-connection-provider'; | ||
import { ContainerConnectionContribution } from './container-connection-contribution'; | ||
import { ServiceConnectionProvider } from '@theia/core/lib/browser/messaging/service-connection-provider'; | ||
|
||
export default new ContainerModule((bind, unbind, isBound, rebind) => { | ||
bind(ContainerConnectionContribution).toSelf().inSingletonScope(); | ||
bind(RemoteRegistryContribution).toService(ContainerConnectionContribution); | ||
|
||
bind(RemoteContainerConnectionProvider).toDynamicValue(ctx => | ||
ServiceConnectionProvider.createLocalProxy<RemoteContainerConnectionProvider>(ctx.container, RemoteContainerConnectionProviderPath) | ||
).inSingletonScope(); | ||
|
||
jonah-iden marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be good to document which properties of the devcontainer format are supported at the moment or link to an issue that lists the unsupported ones.