Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: embed k6 binary #49

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added resources/linux/x86_64/k6
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we download the binary as a part the build&publish process instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I think so.

Should we keep using the local k6 for development 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably! Although I don't yet understand the implications of either choice

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bundling everything would have made it work out of the box.

Bundling only on release means that locally we need an alternative when developing, running the local k6 version is a good option with the only caveat is possibly running a different k6 version than the one you are going to bundle.

I can take more time to look into it 🙇

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we download the binary on npm start if it doesn't exist in the folder?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

smart

Binary file not shown.
Binary file added resources/mac/arm64/k6
Binary file not shown.
Binary file added resources/mac/x86_64/k6
Binary file not shown.
Binary file added resources/win/x86_64/k6.exe
Binary file not shown.
22 changes: 21 additions & 1 deletion src/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { readFile, writeFile } from 'fs/promises'
import path from 'path'
import readline from 'readline/promises'
import { K6Log } from './types'
import { getArch, getPlatform } from './utils/electron'

export type K6Process = ChildProcessWithoutNullStreams

Expand Down Expand Up @@ -35,8 +36,27 @@ export const runScript = async (
HTTPS_PROXY: 'http://localhost:8080',
}

let k6Path: string

// if we are in dev server we take resources directly, otherwise look in the app resources folder.
if (MAIN_WINDOW_VITE_DEV_SERVER_URL) {
k6Path = path.join(
app.getAppPath(),
'resources',
getPlatform(),
getArch(),
'k6'
)
} else {
// only the architecture directory will be in resources on the packaged app
k6Path = path.join(process.resourcesPath, getArch(), 'k6')
}

// add .exe on windows
k6Path += getPlatform() === 'win' ? '.exe' : ''

const k6 = spawn(
'k6',
k6Path,
[
'run',
modifiedScriptPath,
Expand Down
2 changes: 1 addition & 1 deletion src/views/Generator/RulePreview/RulePreview.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CorrelationPreview } from './CorrelationPreview'
import { exhaustive } from '@/utils/typescript'
import { TestRule } from '@/types/rules'
import { TestRule } from '@/schemas/rules'

export function RulePreview({ rule }: { rule: TestRule }) {
switch (rule.type) {
Expand Down