@joystick.js/cli-canary 0.0.0-canary.1658 → 0.0.0-canary.1659
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
import{exec as
|
|
1
|
+
import{exec as f,execSync as k}from"child_process";import n from"path";import{fileURLToPath as _}from"url";import g from"fs";const $=_(import.meta.url),c=n.dirname($),D=()=>{try{return k("docker --version",{stdio:"ignore"}),!0}catch{return!1}},P=(o="",s="",{apt_deps:d=[],snap_deps:l=[],npm_deps:a=[]}={})=>new Promise((u,e)=>{if(!D()){process.loader.print("Push requires Docker to deploy your app. Visit https://docs.docker.com/get-started/get-docker/ to download docker for your OS."),e(new Error("Docker is not installed or not in the PATH"));return}process.loader.print("Building Docker image for deployment...");const i=n.join(c,"Dockerfile");if(!g.existsSync(i)){e(new Error(`Dockerfile not found at ${i}`));return}const m=`docker build ${[`CUSTOM_APT_DEPS=${d.join(" ")}`,`CUSTOM_SNAP_DEPS=${l.join(" ")}`,`GLOBAL_NPM_PACKAGES=${a.join(" ")}`].map(r=>`--build-arg ${r}`).join(" ")} -t ${o} -f "${i}" "${s||c}"`;f(m,(r,p,t)=>{if(r){console.error(`Error building Docker image: ${r.message}`),e(r);return}t&&console.error(`Docker build stderr: ${t}`),process.loader.print(p),process.loader.print(`Successfully built Docker image: ${o}`),u()})});var E=P;export{E as default};
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@joystick.js/cli-canary",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-canary.
|
|
5
|
-
"canary_version": "0.0.0-canary.
|
|
4
|
+
"version": "0.0.0-canary.1659",
|
|
5
|
+
"canary_version": "0.0.0-canary.1658",
|
|
6
6
|
"description": "The CLI for Joystick.",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"bin": {
|
|
@@ -19,7 +19,6 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@babel/code-frame": "^7.23.5",
|
|
21
21
|
"acorn": "^8.11.2",
|
|
22
|
-
"adm-zip": "^0.5.15",
|
|
23
22
|
"ascii-table": "^0.0.9",
|
|
24
23
|
"ava": "^6.0.1",
|
|
25
24
|
"chalk": "^5.3.0",
|
|
@@ -2,103 +2,19 @@ import { exec, execSync } from 'child_process';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { fileURLToPath } from 'url';
|
|
4
4
|
import fs from 'fs';
|
|
5
|
-
import os from 'os';
|
|
6
|
-
import tar from 'tar';
|
|
7
|
-
import AdmZip from 'adm-zip';
|
|
8
|
-
import { promisify } from 'util';
|
|
9
|
-
import { pipeline } from 'stream';
|
|
10
|
-
import fetch from 'node-fetch';
|
|
11
|
-
|
|
12
|
-
const streamPipeline = promisify(pipeline);
|
|
13
5
|
|
|
14
6
|
const __filename = fileURLToPath(import.meta.url);
|
|
15
7
|
const __dirname = path.dirname(__filename);
|
|
16
8
|
|
|
17
|
-
const joystick_docker_path = path.join(os.homedir(), '.joystick', 'docker');
|
|
18
|
-
|
|
19
|
-
const get_docker_binary_path = () => {
|
|
20
|
-
return path.join(joystick_docker_path, os.platform() === 'win32' ? 'docker.exe' : 'docker');
|
|
21
|
-
};
|
|
22
|
-
|
|
23
9
|
const check_docker_installation = () => {
|
|
24
|
-
const docker_path = get_docker_binary_path();
|
|
25
10
|
try {
|
|
26
|
-
execSync(
|
|
11
|
+
execSync('docker --version', { stdio: 'ignore' });
|
|
27
12
|
return true;
|
|
28
13
|
} catch (error) {
|
|
29
|
-
console.warn('Warning: Docker is not installed or the binary is not accessible.');
|
|
30
14
|
return false;
|
|
31
15
|
}
|
|
32
16
|
};
|
|
33
17
|
|
|
34
|
-
const get_docker_binary = async () => {
|
|
35
|
-
const platform = os.platform();
|
|
36
|
-
const arch = os.arch();
|
|
37
|
-
let url;
|
|
38
|
-
let archive_name;
|
|
39
|
-
|
|
40
|
-
const docker_version = '27.1.2';
|
|
41
|
-
|
|
42
|
-
if (platform === 'linux' && arch === 'x64') {
|
|
43
|
-
url = `https://download.docker.com/linux/static/stable/x86_64/docker-${docker_version}.tgz`;
|
|
44
|
-
archive_name = `docker-${docker_version}.tgz`;
|
|
45
|
-
} else if (platform === 'win32' && arch === 'x64') {
|
|
46
|
-
url = `https://download.docker.com/win/static/stable/x86_64/docker-${docker_version}.zip`;
|
|
47
|
-
archive_name = `docker-${docker_version}.zip`;
|
|
48
|
-
} else if (platform === 'darwin') {
|
|
49
|
-
if (arch === 'arm64') {
|
|
50
|
-
url = `https://download.docker.com/mac/static/stable/aarch64/docker-${docker_version}.tgz`;
|
|
51
|
-
} else if (arch === 'x64') {
|
|
52
|
-
url = `https://download.docker.com/mac/static/stable/x86_64/docker-${docker_version}.tgz`;
|
|
53
|
-
} else {
|
|
54
|
-
throw new Error(`Unsupported architecture for macOS: ${arch}`);
|
|
55
|
-
}
|
|
56
|
-
archive_name = `docker-${docker_version}.tgz`;
|
|
57
|
-
} else {
|
|
58
|
-
throw new Error(`Unsupported platform or architecture: ${platform} ${arch}`);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
fs.mkdirSync(joystick_docker_path, { recursive: true });
|
|
62
|
-
const archive_path = path.join(joystick_docker_path, archive_name);
|
|
63
|
-
|
|
64
|
-
try {
|
|
65
|
-
process.loader.print(`Downloading Docker binary from ${url}`);
|
|
66
|
-
const response = await fetch(url);
|
|
67
|
-
if (!response.ok) throw new Error(`Unexpected response ${response.statusText}`);
|
|
68
|
-
await streamPipeline(response.body, fs.createWriteStream(archive_path));
|
|
69
|
-
process.loader.print('Download completed');
|
|
70
|
-
|
|
71
|
-
if (platform === 'win32') {
|
|
72
|
-
process.loader.print('Extracting ZIP file');
|
|
73
|
-
const zip = new AdmZip(archive_path);
|
|
74
|
-
zip.extractAllTo(joystick_docker_path, true);
|
|
75
|
-
} else {
|
|
76
|
-
process.loader.print('Extracting TAR file');
|
|
77
|
-
await tar.x({
|
|
78
|
-
file: archive_path,
|
|
79
|
-
cwd: joystick_docker_path,
|
|
80
|
-
strip: 1
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
fs.unlinkSync(archive_path);
|
|
85
|
-
|
|
86
|
-
// Make the docker binary executable on Unix-like systems
|
|
87
|
-
if (platform !== 'win32') {
|
|
88
|
-
fs.chmodSync(get_docker_binary_path(), '755');
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
process.loader.print(`Docker binaries downloaded and extracted to ${joystick_docker_path}`);
|
|
92
|
-
} catch (error) {
|
|
93
|
-
process.loader.print(`Error: ${error.message}`);
|
|
94
|
-
if (fs.existsSync(archive_path)) {
|
|
95
|
-
process.loader.print('Cleaning up partial download');
|
|
96
|
-
fs.unlinkSync(archive_path);
|
|
97
|
-
}
|
|
98
|
-
throw new Error(`Failed to download or extract Docker binary: ${error.message}`);
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
|
|
102
18
|
const build_docker_image = (
|
|
103
19
|
image_name = '',
|
|
104
20
|
context_path = '',
|
|
@@ -108,21 +24,15 @@ const build_docker_image = (
|
|
|
108
24
|
npm_deps = []
|
|
109
25
|
} = {}
|
|
110
26
|
) => {
|
|
111
|
-
return new Promise(
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
112
28
|
if (!check_docker_installation()) {
|
|
113
|
-
process.loader.print(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
process.loader.print('Docker installed!');
|
|
117
|
-
} catch (error) {
|
|
118
|
-
reject(new Error(`Failed to download Docker binary: ${error.message}`));
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
29
|
+
process.loader.print("Push requires Docker to deploy your app. Visit https://docs.docker.com/get-started/get-docker/ to download docker for your OS.");
|
|
30
|
+
reject(new Error("Docker is not installed or not in the PATH"));
|
|
31
|
+
return;
|
|
121
32
|
}
|
|
122
33
|
|
|
123
34
|
process.loader.print('Building Docker image for deployment...');
|
|
124
35
|
|
|
125
|
-
const docker_path = get_docker_binary_path();
|
|
126
36
|
const dockerfile_path = path.join(__dirname, 'Dockerfile');
|
|
127
37
|
|
|
128
38
|
if (!fs.existsSync(dockerfile_path)) {
|
|
@@ -137,7 +47,7 @@ const build_docker_image = (
|
|
|
137
47
|
`GLOBAL_NPM_PACKAGES=${npm_deps.join(' ')}`
|
|
138
48
|
].map(arg => `--build-arg ${arg}`).join(' ');
|
|
139
49
|
|
|
140
|
-
const command = `
|
|
50
|
+
const command = `docker build ${build_args} -t ${image_name} -f "${dockerfile_path}" "${context_path || __dirname}"`;
|
|
141
51
|
|
|
142
52
|
exec(command, (error, stdout, stderr) => {
|
|
143
53
|
if (error) {
|