@joystick.js/cli-canary 0.0.0-canary.1651 → 0.0.0-canary.1652
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.
- package/.build/index.js +1 -0
- package/dist/commands/push_v2/Dockerfile +68 -0
- package/dist/commands/push_v2/build_docker_image.js +1 -0
- package/dist/commands/push_v2/index.js +6 -6
- package/package.json +2 -2
- package/src/commands/push_v2/Dockerfile +68 -0
- package/src/commands/push_v2/build_docker_image.js +73 -0
- package/src/commands/push_v2/index.js +7 -1
package/.build/index.js
CHANGED
|
@@ -45,6 +45,7 @@ const files = filesToBuild.map((path) => {
|
|
|
45
45
|
|
|
46
46
|
const copyPaths = [
|
|
47
47
|
getPlatformSafePath("commands/create/template"),
|
|
48
|
+
getPlatformSafePath("commands/push_v2/Dockerfile"), // TODO: Convert to just push/Dockerfile.
|
|
48
49
|
];
|
|
49
50
|
|
|
50
51
|
const isCopyPath = copyPaths.some((copyPath) => {
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Use Ubuntu 24.04 as the base image
|
|
2
|
+
FROM ubuntu:24.04
|
|
3
|
+
|
|
4
|
+
# Avoid prompts from apt
|
|
5
|
+
ENV DEBIAN_FRONTEND=noninteractive
|
|
6
|
+
|
|
7
|
+
# Set up environment variables
|
|
8
|
+
ENV NODE_VERSION=20.x
|
|
9
|
+
|
|
10
|
+
# Install Node.js 20, common dependencies, and snapd
|
|
11
|
+
RUN apt-get update && apt-get install -y \
|
|
12
|
+
curl \
|
|
13
|
+
zip \
|
|
14
|
+
unzip \
|
|
15
|
+
git \
|
|
16
|
+
build-essential \
|
|
17
|
+
snapd \
|
|
18
|
+
&& curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
|
|
19
|
+
&& apt-get install -y nodejs \
|
|
20
|
+
&& apt-get clean \
|
|
21
|
+
&& rm -rf /var/lib/apt/lists/*
|
|
22
|
+
|
|
23
|
+
# Verify Node.js version
|
|
24
|
+
RUN node --version
|
|
25
|
+
|
|
26
|
+
# Initialize snap
|
|
27
|
+
RUN snap install core
|
|
28
|
+
|
|
29
|
+
# Allow custom apt dependencies to be passed as build argument
|
|
30
|
+
ARG CUSTOM_APT_DEPS=""
|
|
31
|
+
|
|
32
|
+
# Install custom apt dependencies if provided
|
|
33
|
+
RUN if [ ! -z "$CUSTOM_APT_DEPS" ]; then \
|
|
34
|
+
apt-get update && apt-get install -y $CUSTOM_APT_DEPS \
|
|
35
|
+
&& apt-get clean \
|
|
36
|
+
&& rm -rf /var/lib/apt/lists/*; \
|
|
37
|
+
fi
|
|
38
|
+
|
|
39
|
+
# Allow custom snap dependencies to be passed as build argument
|
|
40
|
+
ARG CUSTOM_SNAP_DEPS=""
|
|
41
|
+
|
|
42
|
+
# Install custom snap dependencies if provided
|
|
43
|
+
RUN if [ ! -z "$CUSTOM_SNAP_DEPS" ]; then \
|
|
44
|
+
snap install $CUSTOM_SNAP_DEPS; \
|
|
45
|
+
fi
|
|
46
|
+
|
|
47
|
+
# Allow custom global npm packages to be passed as build argument
|
|
48
|
+
ARG GLOBAL_NPM_PACKAGES=""
|
|
49
|
+
|
|
50
|
+
# Install custom global npm packages if provided
|
|
51
|
+
RUN if [ ! -z "$GLOBAL_NPM_PACKAGES" ]; then \
|
|
52
|
+
npm install -g $GLOBAL_NPM_PACKAGES; \
|
|
53
|
+
fi
|
|
54
|
+
|
|
55
|
+
# Set the working directory in the container
|
|
56
|
+
WORKDIR .
|
|
57
|
+
|
|
58
|
+
# Copy the pre-built application
|
|
59
|
+
COPY ./.build .
|
|
60
|
+
|
|
61
|
+
# Expose the port the app runs on
|
|
62
|
+
EXPOSE 2600
|
|
63
|
+
|
|
64
|
+
# Note: Environment variables (JOYSTICK_SETTINGS, PUSH_INSTANCE_TOKEN)
|
|
65
|
+
# will be passed at runtime via the container.env file
|
|
66
|
+
|
|
67
|
+
# Command to run the application
|
|
68
|
+
CMD ["node", "index.server.js"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{exec as u}from"child_process";import i from"path";import{fileURLToPath as $}from"url";import"https";import g from"fs";import h from"os";import"tar";import"adm-zip";const y=$(import.meta.url),c=i.dirname(y),O=i.join(h.homedir(),".joystick","docker"),D=(t="",a="",{apt_deps:s=[],snap_deps:d=[],npm_deps:l=[]}={})=>new Promise(async(m,r)=>{if(!check_docker_installation()){process.loader.print("Push requires Docker to be installed on your machine. Downloading...");try{await get_docker_binary(),process.loader.print("Docker installed!")}catch(o){r(new Error(`Failed to download Docker binary: ${o.message}`));return}}process.loader.print("Building Docker image for deployment...");const p=get_docker_binary_path(),e=i.join(c,"Dockerfile");if(!g.existsSync(e)){r(new Error(`Dockerfile not found at ${e}`));return}const f=[`CUSTOM_APT_DEPS=${s.join(" ")}`,`CUSTOM_SNAP_DEPS=${d.join(" ")}`,`GLOBAL_NPM_PACKAGES=${l.join(" ")}`].map(o=>`--build-arg ${o}`).join(" "),_=`"${p}" build ${f} -t ${t} -f "${e}" "${a||c}"`;u(_,(o,k,n)=>{if(o){console.error(`Error building Docker image: ${o.message}`),r(o);return}n&&console.error(`Docker build stderr: ${n}`),process.loader.print(k),process.loader.print(`Successfully built Docker image: ${t}`),m()})});var U=D;export{U as default};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
`),e+=`${
|
|
3
|
-
${n+1===
|
|
4
|
-
`}`}
|
|
1
|
+
import m from"chalk";import"inquirer";import p from"../../lib/build/index.js";import c from"../../lib/cli_log.js";import"./prompts/confirm_deployment.js";import"./create_version.js";import"./get_deployment.js";import d from"./get_push_domain.js";import a from"./get_settings_file.js";import l from"./get_session_token.js";import"./handle_initial_deployment.js";import"./handle_version_deployment.js";import _ from"../../lib/loader.js";import"./upload_build_to_cdn.js";import"./validate_deployment.js";import"./validate_push_config.js";import f from"./build_docker_image.js";const R=(o="",t="",r={})=>{let e="";for(let n=0;n<r?.errors?.length;n+=1){const s=r?.errors[n];o==="push_config"&&(e+=`${m.yellowBright(`> ${s.field}`)}
|
|
2
|
+
`),e+=`${s?.error}
|
|
3
|
+
${n+1===r?.errors?.length?"":`
|
|
4
|
+
`}`}c(`${t?`${m.yellowBright(t)}
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
`:""}${e}`,{level:"danger",docs:{push_config:"https://cheatcode.co/docs/push/config",deployment:"https://cheatcode.co/docs/push/subscription"}[o]}),process.exit(0)},u=async()=>{const o=await
|
|
8
|
-
`);const
|
|
7
|
+
`:""}${e}`,{level:"danger",docs:{push_config:"https://cheatcode.co/docs/push/config",deployment:"https://cheatcode.co/docs/push/subscription"}[o]}),process.exit(0)},u=async()=>{const o=await l();return o||(c(data?.error?.message,{level:"danger",docs:"https://cheatcode.co/docs/push/cli#authentication"}),process.exit(0))},T=(o="")=>(c(`settings.${o}.json must contain a push config object. Add this following the docs link below and try again.`,{level:"danger",docs:"https://cheatcode.co/docs/push/config"}),process.exit(0)),g=async(o={},t={})=>{process.loader=new _,process.loader.print("Starting deployment...");const r=await u(),e=t?.environment||"production",s=(await a({environment:e}))?.config?.push||{},h=d(t?.push_server),i={domain:"example.com",status:"undeployed",deployment_secret:"abc123"};if(!0){i?.status==="undeployed"&&console.log(`
|
|
8
|
+
`);const w=new Date().toISOString();await p({type:"directory",environment:e,encrypt_build:!0,encryption_key:i?.deployment_secret,silence_confirmation:!0}),await f(i?.domain,process.cwd())}};var U=g;export{U 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.1652",
|
|
5
|
+
"canary_version": "0.0.0-canary.1651",
|
|
6
6
|
"description": "The CLI for Joystick.",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"bin": {
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Use Ubuntu 24.04 as the base image
|
|
2
|
+
FROM ubuntu:24.04
|
|
3
|
+
|
|
4
|
+
# Avoid prompts from apt
|
|
5
|
+
ENV DEBIAN_FRONTEND=noninteractive
|
|
6
|
+
|
|
7
|
+
# Set up environment variables
|
|
8
|
+
ENV NODE_VERSION=20.x
|
|
9
|
+
|
|
10
|
+
# Install Node.js 20, common dependencies, and snapd
|
|
11
|
+
RUN apt-get update && apt-get install -y \
|
|
12
|
+
curl \
|
|
13
|
+
zip \
|
|
14
|
+
unzip \
|
|
15
|
+
git \
|
|
16
|
+
build-essential \
|
|
17
|
+
snapd \
|
|
18
|
+
&& curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
|
|
19
|
+
&& apt-get install -y nodejs \
|
|
20
|
+
&& apt-get clean \
|
|
21
|
+
&& rm -rf /var/lib/apt/lists/*
|
|
22
|
+
|
|
23
|
+
# Verify Node.js version
|
|
24
|
+
RUN node --version
|
|
25
|
+
|
|
26
|
+
# Initialize snap
|
|
27
|
+
RUN snap install core
|
|
28
|
+
|
|
29
|
+
# Allow custom apt dependencies to be passed as build argument
|
|
30
|
+
ARG CUSTOM_APT_DEPS=""
|
|
31
|
+
|
|
32
|
+
# Install custom apt dependencies if provided
|
|
33
|
+
RUN if [ ! -z "$CUSTOM_APT_DEPS" ]; then \
|
|
34
|
+
apt-get update && apt-get install -y $CUSTOM_APT_DEPS \
|
|
35
|
+
&& apt-get clean \
|
|
36
|
+
&& rm -rf /var/lib/apt/lists/*; \
|
|
37
|
+
fi
|
|
38
|
+
|
|
39
|
+
# Allow custom snap dependencies to be passed as build argument
|
|
40
|
+
ARG CUSTOM_SNAP_DEPS=""
|
|
41
|
+
|
|
42
|
+
# Install custom snap dependencies if provided
|
|
43
|
+
RUN if [ ! -z "$CUSTOM_SNAP_DEPS" ]; then \
|
|
44
|
+
snap install $CUSTOM_SNAP_DEPS; \
|
|
45
|
+
fi
|
|
46
|
+
|
|
47
|
+
# Allow custom global npm packages to be passed as build argument
|
|
48
|
+
ARG GLOBAL_NPM_PACKAGES=""
|
|
49
|
+
|
|
50
|
+
# Install custom global npm packages if provided
|
|
51
|
+
RUN if [ ! -z "$GLOBAL_NPM_PACKAGES" ]; then \
|
|
52
|
+
npm install -g $GLOBAL_NPM_PACKAGES; \
|
|
53
|
+
fi
|
|
54
|
+
|
|
55
|
+
# Set the working directory in the container
|
|
56
|
+
WORKDIR .
|
|
57
|
+
|
|
58
|
+
# Copy the pre-built application
|
|
59
|
+
COPY ./.build .
|
|
60
|
+
|
|
61
|
+
# Expose the port the app runs on
|
|
62
|
+
EXPOSE 2600
|
|
63
|
+
|
|
64
|
+
# Note: Environment variables (JOYSTICK_SETTINGS, PUSH_INSTANCE_TOKEN)
|
|
65
|
+
# will be passed at runtime via the container.env file
|
|
66
|
+
|
|
67
|
+
# Command to run the application
|
|
68
|
+
CMD ["node", "index.server.js"]
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { exec, execSync } from 'child_process';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
import https from 'https';
|
|
5
|
+
import fs from 'fs';
|
|
6
|
+
import os from 'os';
|
|
7
|
+
import tar from 'tar';
|
|
8
|
+
import AdmZip from 'adm-zip';
|
|
9
|
+
|
|
10
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
11
|
+
const __dirname = path.dirname(__filename);
|
|
12
|
+
|
|
13
|
+
const joystick_docker_path = path.join(os.homedir(), '.joystick', 'docker');
|
|
14
|
+
|
|
15
|
+
// ... (previous functions remain the same)
|
|
16
|
+
|
|
17
|
+
const build_docker_image = (
|
|
18
|
+
image_name = '',
|
|
19
|
+
context_path = '',
|
|
20
|
+
{
|
|
21
|
+
apt_deps = [],
|
|
22
|
+
snap_deps = [],
|
|
23
|
+
npm_deps = []
|
|
24
|
+
} = {}
|
|
25
|
+
) => {
|
|
26
|
+
return new Promise(async (resolve, reject) => {
|
|
27
|
+
if (!check_docker_installation()) {
|
|
28
|
+
process.loader.print('Push requires Docker to be installed on your machine. Downloading...');
|
|
29
|
+
try {
|
|
30
|
+
await get_docker_binary();
|
|
31
|
+
process.loader.print('Docker installed!');
|
|
32
|
+
} catch (error) {
|
|
33
|
+
reject(new Error(`Failed to download Docker binary: ${error.message}`));
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
process.loader.print('Building Docker image for deployment...');
|
|
39
|
+
|
|
40
|
+
const docker_path = get_docker_binary_path();
|
|
41
|
+
const dockerfile_path = path.join(__dirname, 'Dockerfile');
|
|
42
|
+
|
|
43
|
+
if (!fs.existsSync(dockerfile_path)) {
|
|
44
|
+
reject(new Error(`Dockerfile not found at ${dockerfile_path}`));
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Prepare build arguments for dependencies
|
|
49
|
+
const build_args = [
|
|
50
|
+
`CUSTOM_APT_DEPS=${apt_deps.join(' ')}`,
|
|
51
|
+
`CUSTOM_SNAP_DEPS=${snap_deps.join(' ')}`,
|
|
52
|
+
`GLOBAL_NPM_PACKAGES=${npm_deps.join(' ')}`
|
|
53
|
+
].map(arg => `--build-arg ${arg}`).join(' ');
|
|
54
|
+
|
|
55
|
+
const command = `"${docker_path}" build ${build_args} -t ${image_name} -f "${dockerfile_path}" "${context_path || __dirname}"`;
|
|
56
|
+
|
|
57
|
+
exec(command, (error, stdout, stderr) => {
|
|
58
|
+
if (error) {
|
|
59
|
+
console.error(`Error building Docker image: ${error.message}`);
|
|
60
|
+
reject(error);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (stderr) {
|
|
64
|
+
console.error(`Docker build stderr: ${stderr}`);
|
|
65
|
+
}
|
|
66
|
+
process.loader.print(stdout);
|
|
67
|
+
process.loader.print(`Successfully built Docker image: ${image_name}`);
|
|
68
|
+
resolve();
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export default build_docker_image;
|
|
@@ -14,6 +14,7 @@ import Loader from '../../lib/loader.js';
|
|
|
14
14
|
import upload_build_to_cdn from './upload_build_to_cdn.js';
|
|
15
15
|
import validate_deployment from './validate_deployment.js';
|
|
16
16
|
import validate_push_config from './validate_push_config.js';
|
|
17
|
+
import build_docker_image from './build_docker_image.js';
|
|
17
18
|
|
|
18
19
|
const log_validation_error_response = (validation_type = '', root_error = '', validation_response = {}) => {
|
|
19
20
|
let errors_list = ``;
|
|
@@ -83,6 +84,7 @@ const push = async (args = {}, options = {}) => {
|
|
|
83
84
|
const push_domain = get_push_domain(options?.push_server);
|
|
84
85
|
|
|
85
86
|
const deployment = {
|
|
87
|
+
domain: 'example.com',
|
|
86
88
|
status: 'undeployed',
|
|
87
89
|
deployment_secret: 'abc123',
|
|
88
90
|
} || await get_deployment({
|
|
@@ -107,13 +109,17 @@ const push = async (args = {}, options = {}) => {
|
|
|
107
109
|
const build_timestamp = new Date().toISOString();
|
|
108
110
|
|
|
109
111
|
await build({
|
|
112
|
+
type: 'directory', // NOTE: Use this so we can copy it into the Docker image.
|
|
110
113
|
environment,
|
|
111
114
|
encrypt_build: true,
|
|
112
115
|
encryption_key: deployment?.deployment_secret,
|
|
113
116
|
silence_confirmation: true,
|
|
114
117
|
});
|
|
115
118
|
|
|
116
|
-
|
|
119
|
+
await build_docker_image(
|
|
120
|
+
deployment?.domain,
|
|
121
|
+
process.cwd(), // NOTE: Dockerfile targets the .build directory.
|
|
122
|
+
);
|
|
117
123
|
|
|
118
124
|
// process.loader.print('Uploading version...');
|
|
119
125
|
|