@joystick.js/cli-canary 0.0.0-canary.1657 → 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,95 +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
|
-
if (platform === 'linux' && arch === 'x64') {
|
|
41
|
-
url = 'https://get.docker.com/builds/Linux/x86_64/docker-latest.tgz';
|
|
42
|
-
archive_name = 'docker-latest.tgz';
|
|
43
|
-
} else if (platform === 'darwin' && arch === 'x64') {
|
|
44
|
-
url = 'https://get.docker.com/builds/Darwin/x86_64/docker-latest.tgz';
|
|
45
|
-
archive_name = 'docker-latest.tgz';
|
|
46
|
-
} else if (platform === 'win32' && arch === 'x64') {
|
|
47
|
-
url = 'https://get.docker.com/builds/Windows/x86_64/docker-latest.zip';
|
|
48
|
-
archive_name = 'docker-latest.zip';
|
|
49
|
-
} else {
|
|
50
|
-
throw new Error(`Unsupported platform or architecture: ${platform} ${arch}`);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
fs.mkdirSync(joystick_docker_path, { recursive: true });
|
|
54
|
-
const archive_path = path.join(joystick_docker_path, archive_name);
|
|
55
|
-
|
|
56
|
-
try {
|
|
57
|
-
process.loader.print(`Downloading Docker binary from ${url}`);
|
|
58
|
-
const response = await fetch(url);
|
|
59
|
-
if (!response.ok) throw new Error(`Unexpected response ${response.statusText}`);
|
|
60
|
-
await streamPipeline(response.body, fs.createWriteStream(archive_path));
|
|
61
|
-
process.loader.print('Download completed');
|
|
62
|
-
|
|
63
|
-
if (platform === 'win32') {
|
|
64
|
-
process.loader.print('Extracting ZIP file');
|
|
65
|
-
const zip = new AdmZip(archive_path);
|
|
66
|
-
zip.extractAllTo(joystick_docker_path, true);
|
|
67
|
-
} else {
|
|
68
|
-
process.loader.print('Extracting TAR file');
|
|
69
|
-
await tar.x({
|
|
70
|
-
file: archive_path,
|
|
71
|
-
cwd: joystick_docker_path,
|
|
72
|
-
strip: 1
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
fs.unlinkSync(archive_path);
|
|
77
|
-
|
|
78
|
-
// Make the docker binary executable on Unix-like systems
|
|
79
|
-
if (platform !== 'win32') {
|
|
80
|
-
fs.chmodSync(get_docker_binary_path(), '755');
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
process.loader.print(`Docker binaries downloaded and extracted to ${joystick_docker_path}`);
|
|
84
|
-
} catch (error) {
|
|
85
|
-
process.loader.print(`Error: ${error.message}`);
|
|
86
|
-
if (fs.existsSync(archive_path)) {
|
|
87
|
-
process.loader.print('Cleaning up partial download');
|
|
88
|
-
fs.unlinkSync(archive_path);
|
|
89
|
-
}
|
|
90
|
-
throw new Error(`Failed to download or extract Docker binary: ${error.message}`);
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
|
|
94
18
|
const build_docker_image = (
|
|
95
19
|
image_name = '',
|
|
96
20
|
context_path = '',
|
|
@@ -100,21 +24,15 @@ const build_docker_image = (
|
|
|
100
24
|
npm_deps = []
|
|
101
25
|
} = {}
|
|
102
26
|
) => {
|
|
103
|
-
return new Promise(
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
104
28
|
if (!check_docker_installation()) {
|
|
105
|
-
process.loader.print(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
process.loader.print('Docker installed!');
|
|
109
|
-
} catch (error) {
|
|
110
|
-
reject(new Error(`Failed to download Docker binary: ${error.message}`));
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
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;
|
|
113
32
|
}
|
|
114
33
|
|
|
115
34
|
process.loader.print('Building Docker image for deployment...');
|
|
116
35
|
|
|
117
|
-
const docker_path = get_docker_binary_path();
|
|
118
36
|
const dockerfile_path = path.join(__dirname, 'Dockerfile');
|
|
119
37
|
|
|
120
38
|
if (!fs.existsSync(dockerfile_path)) {
|
|
@@ -129,7 +47,7 @@ const build_docker_image = (
|
|
|
129
47
|
`GLOBAL_NPM_PACKAGES=${npm_deps.join(' ')}`
|
|
130
48
|
].map(arg => `--build-arg ${arg}`).join(' ');
|
|
131
49
|
|
|
132
|
-
const command = `
|
|
50
|
+
const command = `docker build ${build_args} -t ${image_name} -f "${dockerfile_path}" "${context_path || __dirname}"`;
|
|
133
51
|
|
|
134
52
|
exec(command, (error, stdout, stderr) => {
|
|
135
53
|
if (error) {
|