Skip to content

Commit 702faf8

Browse files
committedMay 30, 2024··
fix query, fix cli cmds
1 parent 7673932 commit 702faf8

11 files changed

+169
-36
lines changed
 

‎.tool-versions

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
golang 1.22.3
22
golangci-lint 1.58.1
33
nodejs 22.2.0
4-
pnpm 9.1.2
4+
pnpm 9.1.4
55
protoc 25.0

‎cli/cmd/export.go

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/gvkhna/warpdive/dive"
8+
"github.com/gvkhna/warpdive/runtime"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
var exportCmd = &cobra.Command{
13+
Use: "export [IMAGE ID]",
14+
Short: "Exports a container image to a .warpdive file. For use with warpdive.xyz/viewer",
15+
Run: doExportCmd,
16+
}
17+
18+
// var outputFilePath string
19+
20+
func init() {
21+
rootCmd.AddCommand(exportCmd)
22+
}
23+
24+
// doExportCmd implements the steps taken for the export command
25+
func doExportCmd(cmd *cobra.Command, args []string) {
26+
27+
userImage := args[0]
28+
if userImage == "" {
29+
fmt.Println("No image argument given")
30+
os.Exit(1)
31+
}
32+
33+
var sourceType dive.ImageSource
34+
var imageStr string
35+
36+
sourceType, imageStr = dive.DeriveImageSource(userImage)
37+
38+
if sourceType == dive.SourceUnknown {
39+
sourceType = dive.ParseImageSource(defaultSource)
40+
if sourceType == dive.SourceUnknown {
41+
fmt.Printf("unable to determine image source: %v\n", defaultSource)
42+
os.Exit(1)
43+
}
44+
45+
imageStr = userImage
46+
}
47+
48+
// ignoreErrors, err := cmd.PersistentFlags().GetBool("ignore-errors")
49+
// if err != nil {
50+
// logrus.Error("unable to get 'ignore-errors' option:", err)
51+
// }
52+
53+
runtime.Run(runtime.Options{
54+
// Ci: isCi,
55+
Image: imageStr,
56+
Engine: defaultSource,
57+
Source: dive.ParseImageSource(defaultSource),
58+
// Source: dive.ParseImageSource(engine),
59+
PushArgs: args,
60+
ExportFile: exportFile,
61+
// CiConfig: ciConfig,
62+
})
63+
}

‎cli/cmd/push.go

+3-25
Original file line numberDiff line numberDiff line change
@@ -13,46 +13,23 @@ var pushCmd = &cobra.Command{
1313
Use: "push [IMAGE ID]",
1414
Short: "Pushes a container image to to warpdive.xyz",
1515
Args: cobra.ExactArgs(1), // Expect exactly one argument: the docker image/tag id
16-
// DisableFlagParsing: true,
17-
Run: doPushCmd,
16+
Run: doPushCmd,
1817
}
1918

2019
// var outputFilePath string
2120

2221
func init() {
2322
rootCmd.AddCommand(pushCmd)
24-
// exportCmd.Flags().StringVarP(&outputFilePath, "output", "o", "", "Optional: Specify the output file path or directory to place the .warpdive file")
25-
// rootCmd.PersistentFlags().String("source", "docker", "The container engine to fetch the image from. Allowed values: "+strings.Join(dive.ImageSources, ", "))
26-
27-
// exportCmd.Flags().StringVarP(&outputFilePath, "output", "o", "", "Optional: Specify the output file path or directory to place the .warpdive file")
2823
}
2924

30-
// doExportCmd implements the steps taken for the export command
25+
// doPushCmd implements the steps taken for the push command
3126
func doPushCmd(cmd *cobra.Command, args []string) {
32-
// initLogging()
33-
// imageID := args[0]
34-
35-
// engine := viper.GetString("source")
36-
// engine := viper.GetString("container-engine")
37-
// fmt.Printf("Using engine %s to export image %s to file %s\n", engine, imageID, outputFilePath)
38-
39-
// fmt.Printf("Exporting image to file %s\n", outputFilePath)
40-
4127
userImage := args[0]
4228
if userImage == "" {
4329
fmt.Println("No image argument given")
4430
os.Exit(1)
4531
}
4632

47-
// initLogging()
48-
49-
// isCi, ciConfig, err := configureCi()
50-
51-
// if err != nil {
52-
// fmt.Printf("ci configuration error: %v\n", err)
53-
// os.Exit(1)
54-
// }
55-
5633
var sourceType dive.ImageSource
5734
var imageStr string
5835

@@ -81,6 +58,7 @@ func doPushCmd(cmd *cobra.Command, args []string) {
8158
Source: dive.ParseImageSource(defaultSource),
8259
// Source: dive.ParseImageSource(engine),
8360
PushArgs: args,
61+
// ExportFile: exportFile,
8462
// ExportFile: outputFilePath,
8563
// CiConfig: ciConfig,
8664
})

‎package.json

+4
Original file line numberDiff line numberDiff line change
@@ -170,5 +170,9 @@
170170
"vite": "^5.2.11",
171171
"vite-tsconfig-paths": "^4.3.2",
172172
"wrangler": "^3.57.0"
173+
},
174+
"optionalDependencies": {
175+
"playwright": "1.44.1",
176+
"readline": "1.3.0"
173177
}
174178
}

‎pnpm-lock.yaml

+41
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎scripts/screenshot-page.ts

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import {chromium} from 'playwright'
2+
import * as readline from 'readline'
3+
4+
// run pnpx playwright install
5+
6+
async function main() {
7+
// Launch the browser
8+
const browser = await chromium.launch({
9+
headless: false // Set to false to see the browser UI
10+
})
11+
12+
// Create a new page with a specific viewport size
13+
const page = await browser.newPage({
14+
viewport: {
15+
width: 1280,
16+
height: 727
17+
}
18+
})
19+
20+
// Navigate to a URL
21+
await page.goto('http://localhost:4321/viewer/')
22+
23+
// Create readline interface
24+
const rl = readline.createInterface({
25+
input: process.stdin,
26+
output: process.stdout
27+
})
28+
29+
console.log('Press ENTER to take a screenshot...')
30+
31+
// Wait for user input
32+
rl.on('line', async () => {
33+
// Take screenshot on user input
34+
await page.screenshot({path: 'screenshot.tmp.png'})
35+
console.log('Screenshot saved as screenshot.tmp.png')
36+
37+
// Cleanup
38+
await browser.close()
39+
rl.close()
40+
})
41+
}
42+
43+
main().catch((err) => {
44+
console.error('Error:', err)
45+
process.exit(1)
46+
})

‎src/partials/viewer/app-loader.stories.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type {Meta, StoryObj} from '@storybook/react'
22
import {withRouter, reactRouterParameters} from 'storybook-addon-remix-react-router'
33

4-
import AppLoader from './app-loader'
5-
import AppLayout from '../app/app-layout'
4+
import {AppLoader} from './app-loader'
5+
import {AppLayout} from '../app/app-layout'
66
const meta = {
77
title: 'ContainerBrowser/Loader',
88
component: AppLoader,

‎src/partials/viewer/file-system-viewer.stories.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Import React and the necessary Storybook components
22
import React from 'react'
33
import {type Meta, type StoryObj} from '@storybook/react'
4-
import FileSystemViewer from './file-system-viewer'
4+
import {FileSystemViewer} from './file-system-viewer'
55
import {WarpDiveImage, WarpDiveImage_TreeNode, WarpDiveImage_TreeNode_Ref} from '@/generated/warpdive_pb'
66
// Define the metadata for the Storybook
77
const meta: Meta<typeof FileSystemViewer> = {

‎src/partials/viewer/layers-list.stories.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Importing necessary packages and components
22
import type {Meta, StoryObj} from '@storybook/react'
3-
import LayerRow from './layer-row'
3+
import {LayerRow} from './layer-row'
44
import {WarpDiveImage_Layer} from '@/generated/warpdive_pb'
5-
import LayersList from './layers-list'
5+
import {LayersList} from './layers-list'
66

77
const meta: Meta<typeof LayerRow> = {
88
title: 'ContainerBrowser/LayersList',

‎src/server/dashboard.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const dashboard = new Hono<HonoServer>().get('/', async (c) => {
2323
// tracking bug: https://github.com/drizzle-team/drizzle-orm/issues/555
2424
// const {id: buildId, userId: buildUserId, projectId: buildRepoId, ...buildCols} = getTableColumns(schema.builds)
2525
const recentBuilds = await db
26-
.selectDistinct({
26+
.select({
2727
builtBy: sql<string | null>`${schema.builds.builtBy}`.as('build_built_by'),
2828
builtWith: sql<string | null>`${schema.builds.builtWith}`.as('build_built_with'),
2929
commitSha: sql<string | null>`${schema.builds.commitSha}`.as('build_commit_sha'),

‎src/server/projects.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as schema from '@/db/schema'
44
import {getAuthenticatedUserDB} from './users'
55
import {z} from 'zod'
66
import {zValidator} from '@hono/zod-validator'
7-
import {eq, desc, getTableColumns, sql} from 'drizzle-orm'
7+
import {eq, desc, and, getTableColumns, sql} from 'drizzle-orm'
88

99
const projects = new Hono<HonoServer>()
1010
.get('/:pid', zValidator('param', z.object({pid: z.string()})), async (c) => {
@@ -28,7 +28,7 @@ const projects = new Hono<HonoServer>()
2828
// tracking bug: https://github.com/drizzle-team/drizzle-orm/issues/555
2929
// const {id: buildId, userId: buildUserId, projectId: buildRepoId, ...buildCols} = getTableColumns(schema.builds)
3030
const projectBuilds = await db
31-
.selectDistinct({
31+
.select({
3232
builtBy: sql<string | null>`${schema.builds.builtBy}`.as('build_built_by'),
3333
builtWith: sql<string | null>`${schema.builds.builtWith}`.as('build_built_with'),
3434
commitSha: sql<string | null>`${schema.builds.commitSha}`.as('build_commit_sha'),
@@ -49,12 +49,13 @@ const projects = new Hono<HonoServer>()
4949
tag: sql<string | null>`${schema.builds.tag}`.as('build_tag')
5050
})
5151
.from(schema.projects)
52-
.innerJoin(schema.builds, eq(schema.builds.projectPid, pid))
53-
.where(eq(schema.projects.userId, userId))
52+
.innerJoin(schema.builds, eq(schema.builds.projectId, schema.projects.id))
53+
.where(and(eq(schema.projects.userId, userId), eq(schema.builds.projectPid, pid)))
5454
.limit(50)
5555
.orderBy(desc(schema.builds.createdAt))
5656

5757
if (projects && projectBuilds) {
58+
console.log(projectBuilds)
5859
return c.json({projects: projectsRes, projectBuilds}, 200)
5960
}
6061
return c.json({message: 'User not found or incorrect authentication'}, 404)

0 commit comments

Comments
 (0)
Please sign in to comment.