Skip to content

Commit

Permalink
fix query, fix cli cmds
Browse files Browse the repository at this point in the history
  • Loading branch information
gvkhna committed May 30, 2024
1 parent 7673932 commit 702faf8
Show file tree
Hide file tree
Showing 11 changed files with 169 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
golang 1.22.3
golangci-lint 1.58.1
nodejs 22.2.0
pnpm 9.1.2
pnpm 9.1.4
protoc 25.0
63 changes: 63 additions & 0 deletions cli/cmd/export.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package cmd

import (
"fmt"
"os"

"github.com/gvkhna/warpdive/dive"
"github.com/gvkhna/warpdive/runtime"
"github.com/spf13/cobra"
)

var exportCmd = &cobra.Command{
Use: "export [IMAGE ID]",
Short: "Exports a container image to a .warpdive file. For use with warpdive.xyz/viewer",
Run: doExportCmd,
}

// var outputFilePath string

func init() {
rootCmd.AddCommand(exportCmd)
}

// doExportCmd implements the steps taken for the export command
func doExportCmd(cmd *cobra.Command, args []string) {

userImage := args[0]
if userImage == "" {
fmt.Println("No image argument given")
os.Exit(1)
}

var sourceType dive.ImageSource
var imageStr string

sourceType, imageStr = dive.DeriveImageSource(userImage)

if sourceType == dive.SourceUnknown {
sourceType = dive.ParseImageSource(defaultSource)
if sourceType == dive.SourceUnknown {
fmt.Printf("unable to determine image source: %v\n", defaultSource)
os.Exit(1)
}

imageStr = userImage
}

// ignoreErrors, err := cmd.PersistentFlags().GetBool("ignore-errors")
// if err != nil {
// logrus.Error("unable to get 'ignore-errors' option:", err)
// }

runtime.Run(runtime.Options{
// Ci: isCi,
Image: imageStr,
Engine: defaultSource,
Source: dive.ParseImageSource(defaultSource),
// Source: dive.ParseImageSource(engine),
PushArgs: args,
ExportFile: exportFile,
// CiConfig: ciConfig,
})
}
28 changes: 3 additions & 25 deletions cli/cmd/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,46 +13,23 @@ var pushCmd = &cobra.Command{
Use: "push [IMAGE ID]",
Short: "Pushes a container image to to warpdive.xyz",
Args: cobra.ExactArgs(1), // Expect exactly one argument: the docker image/tag id
// DisableFlagParsing: true,
Run: doPushCmd,
Run: doPushCmd,
}

// var outputFilePath string

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

// exportCmd.Flags().StringVarP(&outputFilePath, "output", "o", "", "Optional: Specify the output file path or directory to place the .warpdive file")
}

// doExportCmd implements the steps taken for the export command
// doPushCmd implements the steps taken for the push command
func doPushCmd(cmd *cobra.Command, args []string) {
// initLogging()
// imageID := args[0]

// engine := viper.GetString("source")
// engine := viper.GetString("container-engine")
// fmt.Printf("Using engine %s to export image %s to file %s\n", engine, imageID, outputFilePath)

// fmt.Printf("Exporting image to file %s\n", outputFilePath)

userImage := args[0]
if userImage == "" {
fmt.Println("No image argument given")
os.Exit(1)
}

// initLogging()

// isCi, ciConfig, err := configureCi()

// if err != nil {
// fmt.Printf("ci configuration error: %v\n", err)
// os.Exit(1)
// }

var sourceType dive.ImageSource
var imageStr string

Expand Down Expand Up @@ -81,6 +58,7 @@ func doPushCmd(cmd *cobra.Command, args []string) {
Source: dive.ParseImageSource(defaultSource),
// Source: dive.ParseImageSource(engine),
PushArgs: args,
// ExportFile: exportFile,
// ExportFile: outputFilePath,
// CiConfig: ciConfig,
})
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,9 @@
"vite": "^5.2.11",
"vite-tsconfig-paths": "^4.3.2",
"wrangler": "^3.57.0"
},
"optionalDependencies": {
"playwright": "1.44.1",
"readline": "1.3.0"
}
}
41 changes: 41 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions scripts/screenshot-page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import {chromium} from 'playwright'
import * as readline from 'readline'

// run pnpx playwright install

async function main() {
// Launch the browser
const browser = await chromium.launch({
headless: false // Set to false to see the browser UI
})

// Create a new page with a specific viewport size
const page = await browser.newPage({
viewport: {
width: 1280,
height: 727
}
})

// Navigate to a URL
await page.goto('http://localhost:4321/viewer/')

// Create readline interface
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
})

console.log('Press ENTER to take a screenshot...')

// Wait for user input
rl.on('line', async () => {
// Take screenshot on user input
await page.screenshot({path: 'screenshot.tmp.png'})
console.log('Screenshot saved as screenshot.tmp.png')

// Cleanup
await browser.close()
rl.close()
})
}

main().catch((err) => {
console.error('Error:', err)
process.exit(1)
})
4 changes: 2 additions & 2 deletions src/partials/viewer/app-loader.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type {Meta, StoryObj} from '@storybook/react'
import {withRouter, reactRouterParameters} from 'storybook-addon-remix-react-router'

import AppLoader from './app-loader'
import AppLayout from '../app/app-layout'
import {AppLoader} from './app-loader'
import {AppLayout} from '../app/app-layout'
const meta = {
title: 'ContainerBrowser/Loader',
component: AppLoader,
Expand Down
2 changes: 1 addition & 1 deletion src/partials/viewer/file-system-viewer.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Import React and the necessary Storybook components
import React from 'react'
import {type Meta, type StoryObj} from '@storybook/react'
import FileSystemViewer from './file-system-viewer'
import {FileSystemViewer} from './file-system-viewer'
import {WarpDiveImage, WarpDiveImage_TreeNode, WarpDiveImage_TreeNode_Ref} from '@/generated/warpdive_pb'
// Define the metadata for the Storybook
const meta: Meta<typeof FileSystemViewer> = {
Expand Down
4 changes: 2 additions & 2 deletions src/partials/viewer/layers-list.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Importing necessary packages and components
import type {Meta, StoryObj} from '@storybook/react'
import LayerRow from './layer-row'
import {LayerRow} from './layer-row'
import {WarpDiveImage_Layer} from '@/generated/warpdive_pb'
import LayersList from './layers-list'
import {LayersList} from './layers-list'

const meta: Meta<typeof LayerRow> = {
title: 'ContainerBrowser/LayersList',
Expand Down
2 changes: 1 addition & 1 deletion src/server/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const dashboard = new Hono<HonoServer>().get('/', async (c) => {
// tracking bug: https://github.com/drizzle-team/drizzle-orm/issues/555
// const {id: buildId, userId: buildUserId, projectId: buildRepoId, ...buildCols} = getTableColumns(schema.builds)
const recentBuilds = await db
.selectDistinct({
.select({
builtBy: sql<string | null>`${schema.builds.builtBy}`.as('build_built_by'),
builtWith: sql<string | null>`${schema.builds.builtWith}`.as('build_built_with'),
commitSha: sql<string | null>`${schema.builds.commitSha}`.as('build_commit_sha'),
Expand Down
9 changes: 5 additions & 4 deletions src/server/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as schema from '@/db/schema'
import {getAuthenticatedUserDB} from './users'
import {z} from 'zod'
import {zValidator} from '@hono/zod-validator'
import {eq, desc, getTableColumns, sql} from 'drizzle-orm'
import {eq, desc, and, getTableColumns, sql} from 'drizzle-orm'

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

if (projects && projectBuilds) {
console.log(projectBuilds)
return c.json({projects: projectsRes, projectBuilds}, 200)
}
return c.json({message: 'User not found or incorrect authentication'}, 404)
Expand Down

0 comments on commit 702faf8

Please sign in to comment.