devcontainers / devcontainers/cli

Packaging and distribution of devcontainer as standalone executable

Open
#614 8 comments 0 reactions 0 assignees View on GitHub
feature-request
Dominant language
TypeScript
Stars
3k
Forks
457
Avg merge
13h 17m
Merged PRs (30d)
6

Description

I'm trying to build and distribute `devcontainer` as standalone executable. Currently I'm on:

```
$ git log -1
commit 413c5f790f3a4972bf6f05b71d71ac946c87bc7c (HEAD -> main, origin/main, origin/HEAD)
Merge: ac349ef 4cb96b7
Author: Samruddhi Khandale
Date: Mon Jul 31 08:42:00 2023 -0700

Merge pull request #570 from yokonao/add-buildx-cache-to

Add `--cache-to` option to `devcontainer build` command
```

I'm packaging it with:

```bash
pkg devcontainer.js
```

Which generates couple warnings:

```
> pkg@5.8.1
> Targets not specified. Assuming:
node18-linux-x64, node18-macos-x64, node18-win-x64
> Warning Cannot resolve 'config.extends'
$PWD/cli/dist/spec-node/devContainersSpecCLI.js
Dynamic require may fail at run time, because the requested file
is unknown at compilation time and not included into executable.
Use a string literal as an argument for 'require', or leave it
as is and specify the resolved file name in 'scripts' option.
> Warning Cannot resolve 'path32'
$PWD/cli/dist/spec-node/devContainersSpecCLI.js
Dynamic require may fail at run time, because the requested file
is unknown at compilation time and not included into executable.
Use a string literal as an argument for 'require', or leave it
as is and specify the resolved file name in 'scripts' option.
```

But it does produce executable:

```
$ file devcontainer-linux
devcontainer-linux: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=e8e9fc449943f935d469333b1101f224a4c0164f, for GNU/Linux 2.6.32, stripped
```

It seems to work locally:

```
$ ./devcontainer-linux --version
0.50.2
```

But once I deploy it to server where I want to actually use it:

```
+ /opt/devcontainer-linux --workspace-folder . build
+ jq .
23:51:08 @devcontainers/cli 0.50.2. Node.js v18.5.0. linux 5.15.0-71-generic x64.
```

It fails:

> Error: File or directory '/**/cli/dist/node_modules/vscode-dev-containers/container-features' was not included into executable at compilation stage. Please recompile adding it as asset or script.

I tried the following patch, but it did not help:

```diff
diff --git a/package.json b/package.json
index 1275861..e317b78 100644
--- a/package.json
+++ b/package.json
@@ -109,5 +109,13 @@
"vscode-dev-containers": "https://github.com/microsoft/vscode-dev-containers/releases/download/v0.245.2/vscode-dev-containers-0.245.2.tgz",
"vscode-uri": "^3.0.7",
"yargs": "~17.7.1"
+ },
+ "pkg": {
+ "scripts": [
+ "dist/**/*.js"
+ ],
+ "assets": [
+ "dist/node_modules/vscode-dev-containers/container-features/**"
+ ]
}
}
```

Any suggestions are welcome.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.