Skip to content

Commit 5b1a1cc

Browse files
authored
chore: parametrize app-playground deployment script (#46)
1 parent acf7a1d commit 5b1a1cc

File tree

3 files changed

+46
-13
lines changed

3 files changed

+46
-13
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ coverage
99
*.tsbuildinfo
1010
docs
1111

12-
.turbo
12+
.turbo

CONTRIBUTING.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,20 @@ will run all the builds and then start the app project. In order to make this wo
6767
```
6868
DATABRICKS_HOST=
6969
```
70+
71+
## Deploying the playground app
72+
73+
The playground app can be deployed to Databricks using the following command:
74+
75+
```bash
76+
pnpm pack:sdk
77+
pnpm deploy:playground
78+
```
79+
80+
You can set the following environment variables to the command to customize the deployment:
81+
82+
```bash
83+
export DATABRICKS_PROFILE=your-profile # Databricks profile name. Used as a Databricks CLI profile argument whenever a command is executed.
84+
export DATABRICKS_APP_NAME=your-app-name # The name of the app to deploy. If not provided, it will be prefixed with the username.
85+
export DATABRICKS_WORKSPACE_DIR=your-workspace-dir # The source workspace directory to deploy the app from. It will be used to construct the absolute path: /Workspace/Users/{your-username}/{workspace-dir}
86+
```

tools/playground/deploy-playground.ts

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ import ora from "ora";
77

88
const exec = promisify(execChildProcess);
99

10+
const config = {
11+
profile: process.env.DATABRICKS_PROFILE,
12+
appName: process.env.DATABRICKS_APP_NAME,
13+
workspaceDir: process.env.DATABRICKS_WORKSPACE_DIR,
14+
};
15+
1016
const __dirname = path.dirname(new URL(import.meta.url).pathname);
1117
const PLAYGROUND_FOLDER = path.join(process.cwd(), "apps", "dev-playground");
1218
const TMP_FOLDER = path.join(process.cwd(), "deployable");
@@ -121,41 +127,51 @@ async function deployPlayground() {
121127
process.chdir(TMP_FOLDER);
122128

123129
const username = os.userInfo().username;
124-
const scopedAppName = `${transformUsername(username)}-${appName}`;
130+
const scopedAppName =
131+
config.appName || `${transformUsername(username)}-${appName}`;
132+
const workspaceDir = config.workspaceDir || scopedAppName;
133+
const profileArgs = config.profile ? ["-p", config.profile] : [];
134+
const profileArgStr =
135+
profileArgs.length > 0 ? ` ${profileArgs.join(" ")}` : "";
125136

126137
try {
127-
await exec(`databricks apps get ${scopedAppName}`);
138+
await exec(`databricks apps get ${scopedAppName}${profileArgStr}`);
128139
} catch {
129-
spinner.info("Creating app...");
130-
await execWithOutput("databricks", ["apps", "create", scopedAppName]);
140+
spinner.info(`Creating app "${scopedAppName}"...`);
141+
await execWithOutput("databricks", [
142+
"apps",
143+
"create",
144+
scopedAppName,
145+
...profileArgs,
146+
]);
131147
console.log(
132-
"App created successfully, you will need to add the sql-warehouse resource to the app manually now.",
148+
`App "${scopedAppName}" created successfully, you will need to add the sql-warehouse resource to the app manually now.`,
133149
);
134150
}
135151

136-
spinner.info("Syncing playground to Databricks");
152+
spinner.info(`Syncing playground to Databricks`);
137153
const { stderr } = await exec(
138-
`databricks sync . /Workspace/Users/${username}@databricks.com/${scopedAppName}`,
154+
`databricks sync . /Workspace/Users/${username}@databricks.com/${workspaceDir}${profileArgStr}`,
139155
);
140156

141157
if (stderr) {
142-
spinner.fail("Failed to sync playground");
158+
spinner.fail(`Failed to sync playground`);
143159
console.error(stderr);
144160
return;
145161
}
146162

147-
spinner.info("Deploying playground to Databricks");
163+
spinner.info(`Deploying "${scopedAppName}" to Databricks`);
148164
const { stderr: stderr2 } = await exec(
149-
`databricks apps deploy ${scopedAppName} --source-code-path /Workspace/Users/${username}@databricks.com/${scopedAppName}`,
165+
`databricks apps deploy ${scopedAppName} --source-code-path /Workspace/Users/${username}@databricks.com/${workspaceDir}${profileArgStr}`,
150166
);
151167

152168
if (stderr2) {
153-
spinner.fail("Failed to deploy playground");
169+
spinner.fail(`Failed to deploy "${scopedAppName}"`);
154170
console.error(stderr2);
155171
return;
156172
}
157173

158-
spinner.succeed("Playground deployed successfully");
174+
spinner.succeed(`App "${scopedAppName}" deployed successfully`);
159175
}
160176

161177
function cleanup(folders: string[]) {

0 commit comments

Comments
 (0)