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

kt-devnet: Adds fileserver package for serving cannon prestates #13666

Merged
merged 3 commits into from
Jan 9, 2025
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
2 changes: 1 addition & 1 deletion cannon/testdata/example/alloc/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require github.com/ethereum-optimism/optimism v0.0.0

require (
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/sys v0.29.0 // indirect
)

replace github.com/ethereum-optimism/optimism v0.0.0 => ../../../..
8 changes: 4 additions & 4 deletions cannon/testdata/example/alloc/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2 changes: 1 addition & 1 deletion cannon/testdata/example/claim/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require github.com/ethereum-optimism/optimism v0.0.0

require (
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/sys v0.29.0 // indirect
)

replace github.com/ethereum-optimism/optimism v0.0.0 => ../../../..
8 changes: 4 additions & 4 deletions cannon/testdata/example/claim/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
1 change: 1 addition & 0 deletions cannon/testdata/example/mt-atomic/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ go 1.22
toolchain go1.22.0

require utils v0.0.0

replace utils => ../../utils
1 change: 1 addition & 0 deletions cannon/testdata/example/mt-map/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ go 1.22
toolchain go1.22.0

require utils v0.0.0

replace utils => ../../utils
1 change: 1 addition & 0 deletions cannon/testdata/example/mt-mutex/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ go 1.22
toolchain go1.22.0

require utils v0.0.0

replace utils => ../../utils
1 change: 1 addition & 0 deletions cannon/testdata/example/mt-oncefunc/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ go 1.22
toolchain go1.22.0

require utils v0.0.0

replace utils => ../../utils
1 change: 1 addition & 0 deletions cannon/testdata/example/mt-pool/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ go 1.22
toolchain go1.22.0

require utils v0.0.0

replace utils => ../../utils
1 change: 1 addition & 0 deletions cannon/testdata/example/mt-value/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ go 1.22
toolchain go1.22.0

require utils v0.0.0

replace utils => ../../utils
1 change: 1 addition & 0 deletions cannon/testdata/example/mt-wg/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ go 1.22
toolchain go1.22.0

require utils v0.0.0

replace utils => ../../utils
1 change: 1 addition & 0 deletions cannon/testdata/example/utilscheck/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ go 1.22
toolchain go1.22.0

require utils v0.0.0

replace utils => ../../utils
1 change: 1 addition & 0 deletions cannon/testdata/example/utilscheck2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ go 1.22
toolchain go1.22.0

require utils v0.0.0

replace utils => ../../utils
1 change: 1 addition & 0 deletions cannon/testdata/example/utilscheck3/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ go 1.22
toolchain go1.22.0

require utils v0.0.0

replace utils => ../../utils
1 change: 1 addition & 0 deletions cannon/testdata/example/utilscheck4/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ go 1.22
toolchain go1.22.0

require utils v0.0.0

replace utils => ../../utils
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ require (
github.com/kurtosis-tech/kurtosis-portal/api/golang v0.0.0-20230818182330-1a86869414d2 // indirect
github.com/kurtosis-tech/kurtosis/contexts-config-store v0.0.0-20230818184218-f4e3e773463b // indirect
github.com/kurtosis-tech/kurtosis/grpc-file-transfer/golang v0.0.0-20230803130419-099ee7a4e3dc // indirect
github.com/kurtosis-tech/kurtosis/path-compression v0.0.0-20240307154559-64d2929cd265 // indirect
github.com/kurtosis-tech/kurtosis/path-compression v0.0.0-20250108161014-0819b8ca912f // indirect
github.com/kurtosis-tech/stacktrace v0.0.0-20211028211901-1c67a77b5409 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/libp2p/go-flow-metrics v0.1.0 // indirect
Expand Down Expand Up @@ -225,7 +225,7 @@ require (
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
github.com/ulikunitz/xz v0.5.12 // indirect
github.com/wlynxg/anet v0.0.4 // indirect
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
Expand All @@ -238,7 +238,7 @@ require (
go.uber.org/zap v1.27.0 // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/text v0.19.0 // indirect
golang.org/x/tools v0.26.0 // indirect
google.golang.org/genproto v0.0.0-20230726155614-23370e0ffb3e // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,8 @@ github.com/kurtosis-tech/kurtosis/contexts-config-store v0.0.0-20230818184218-f4
github.com/kurtosis-tech/kurtosis/contexts-config-store v0.0.0-20230818184218-f4e3e773463b/go.mod h1:4pFdrRwDz5R+Fov2ZuTaPhAVgjA2jhGh1Izf832sX7A=
github.com/kurtosis-tech/kurtosis/grpc-file-transfer/golang v0.0.0-20230803130419-099ee7a4e3dc h1:7IlEpSehmWcNXOFpNP24Cu5HQI3af7GCBQw//m+LnvQ=
github.com/kurtosis-tech/kurtosis/grpc-file-transfer/golang v0.0.0-20230803130419-099ee7a4e3dc/go.mod h1:TOWMQgvAJH/NiWWERGXg/plT9lS7aFcXFxCa0M5sfHo=
github.com/kurtosis-tech/kurtosis/path-compression v0.0.0-20240307154559-64d2929cd265 h1:uSDftcGStwuAjHv8fV2TleNCKSWPvUKe7EaplFG3yBI=
github.com/kurtosis-tech/kurtosis/path-compression v0.0.0-20240307154559-64d2929cd265/go.mod h1:aDMrPeS7Gii8W6SDKSKyrBNgEQAUYidriyeKGf+Ml3I=
github.com/kurtosis-tech/kurtosis/path-compression v0.0.0-20250108161014-0819b8ca912f h1:kys3RDy0uHk+VwYS1mVh48YnogkRTAxUUCV7kpwMNOQ=
github.com/kurtosis-tech/kurtosis/path-compression v0.0.0-20250108161014-0819b8ca912f/go.mod h1:aDMrPeS7Gii8W6SDKSKyrBNgEQAUYidriyeKGf+Ml3I=
github.com/kurtosis-tech/stacktrace v0.0.0-20211028211901-1c67a77b5409 h1:YQTATifMUwZEtZYb0LVA7DK2pj8s71iY8rzweuUQ5+g=
github.com/kurtosis-tech/stacktrace v0.0.0-20211028211901-1c67a77b5409/go.mod h1:y5weVs5d9wXXHcDA1awRxkIhhHC1xxYJN8a7aXnE6S8=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
Expand Down Expand Up @@ -800,8 +800,8 @@ github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqri
github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8=
github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U=
github.com/ulikunitz/xz v0.5.8/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/ulikunitz/xz v0.5.11 h1:kpFauv27b6ynzBNT/Xy+1k+fK4WswhN/6PN5WhFAGw8=
github.com/ulikunitz/xz v0.5.11/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/ulikunitz/xz v0.5.12 h1:37Nm15o69RwBkXM0J6A5OlE67RZTfzUxTj8fB3dfcsc=
github.com/ulikunitz/xz v0.5.12/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/urfave/cli/v2 v2.27.5 h1:WoHEJLdsXr6dDWoJgMq/CboDmyY/8HMMH1fTECbih+w=
github.com/urfave/cli/v2 v2.27.5/go.mod h1:3Sevf16NykTbInEnD0yKkjDAeZDS0A6bzhBH5hrMvTQ=
Expand Down Expand Up @@ -991,8 +991,8 @@ golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
Expand Down
124 changes: 102 additions & 22 deletions kurtosis-devnet/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,21 @@ import (
"log"
"os"
"path/filepath"
"strings"

"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/build"
"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/kurtosis"
"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/kurtosis/api/engine"
"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/kurtosis/backend"
"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/kurtosis/sources/spec"
"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/serve"
"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/tmpl"
"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/util"
"github.com/urfave/cli/v2"
)

const FILESERVER_PACKAGE = "fileserver"

type config struct {
templateFile string
dataFile string
Expand Down Expand Up @@ -138,72 +143,95 @@ func (m *Main) localContractArtifactsOption(server *staticServer) tmpl.TemplateC
})
}

type PrestateInfo struct {
URL string `json:"url"`
Hashes map[string]string `json:"hashes"`
}

func (m *Main) localPrestateOption(server *staticServer) tmpl.TemplateContextOptions {
prestateBuilder := build.NewPrestateBuilder(
build.WithPrestateBaseDir(m.cfg.baseDir),
build.WithPrestateDryRun(m.cfg.dryRun),
)

return tmpl.WithFunction("localPrestate", func() (string, error) {
return tmpl.WithFunction("localPrestate", func() (*PrestateInfo, error) {
// Create build directory with the final path structure
buildDir := filepath.Join(server.dir, "proofs", "op-program", "cannon")
if err := os.MkdirAll(buildDir, 0755); err != nil {
return "", fmt.Errorf("failed to create prestate build directory: %w", err)
return nil, fmt.Errorf("failed to create prestate build directory: %w", err)
}

// Get the relative path from server.dir to buildDir for the URL
relPath, err := filepath.Rel(server.dir, buildDir)
if err != nil {
return "", fmt.Errorf("failed to get relative path: %w", err)
return nil, fmt.Errorf("failed to get relative path: %w", err)
}

url := fmt.Sprintf("%s/%s", server.URL(), relPath)
info := &PrestateInfo{
URL: fmt.Sprintf("%s/%s", server.URL(), relPath),
Hashes: make(map[string]string),
}

if m.cfg.dryRun {
return url, nil
return info, nil
}

// Check if we already have prestate files. Typical in interop mode,
// where we have a prestate for each chain.
if dir, _ := os.ReadDir(buildDir); len(dir) > 0 {
return url, nil
// Map of known file prefixes to their keys
fileToKey := map[string]string{
"prestate-proof.json": "prestate",
"prestate-proof-mt64.json": "prestate-mt64",
"prestate-proof-mt.json": "prestate-mt",
}

// Build all prestate files directly in the target directory
if err := prestateBuilder.Build(buildDir); err != nil {
return "", fmt.Errorf("failed to build prestates: %w", err)
return nil, fmt.Errorf("failed to build prestates: %w", err)
}

// Find all prestate-proof*.json files
// Find and process all prestate files
matches, err := filepath.Glob(filepath.Join(buildDir, "prestate-proof*.json"))
if err != nil {
return "", fmt.Errorf("failed to find prestate files: %w", err)
return nil, fmt.Errorf("failed to find prestate files: %w", err)
}

// Process each file to rename it to its hash
for _, filePath := range matches {
content, err := os.ReadFile(filePath)
if err != nil {
return "", fmt.Errorf("failed to read prestate %s: %w", filepath.Base(filePath), err)
return nil, fmt.Errorf("failed to read prestate %s: %w", filepath.Base(filePath), err)
}

var data struct {
Pre string `json:"pre"`
}
if err := json.Unmarshal(content, &data); err != nil {
return "", fmt.Errorf("failed to parse prestate %s: %w", filepath.Base(filePath), err)
return nil, fmt.Errorf("failed to parse prestate %s: %w", filepath.Base(filePath), err)
}

// Rename the file to just the hash
hashedPath := filepath.Join(buildDir, data.Pre)
if err := os.Rename(filePath, hashedPath); err != nil {
return "", fmt.Errorf("failed to rename prestate %s: %w", filepath.Base(filePath), err)
// Store hash with its corresponding key
if key, exists := fileToKey[filepath.Base(filePath)]; exists {
info.Hashes[key] = data.Pre
}

log.Printf("%s available at: %s/%s/%s\n", filepath.Base(filePath), server.URL(), relPath, data.Pre)
// Rename files to hash-based names
newFileName := data.Pre + ".json"
hashedPath := filepath.Join(buildDir, newFileName)
if err := os.Rename(filePath, hashedPath); err != nil {
return nil, fmt.Errorf("failed to rename prestate %s: %w", filepath.Base(filePath), err)
}
log.Printf("%s available at: %s/%s/%s\n", filepath.Base(filePath), server.URL(), relPath, newFileName)

// Rename the corresponding binary file
binFilePath := strings.Replace(strings.TrimSuffix(filePath, ".json"), "-proof", "", 1) + ".bin.gz"
newBinFileName := data.Pre + ".bin.gz"
binHashedPath := filepath.Join(buildDir, newBinFileName)
if err := os.Rename(binFilePath, binHashedPath); err != nil {
return nil, fmt.Errorf("failed to rename prestate %s: %w", filepath.Base(binFilePath), err)
}
log.Printf("%s available at: %s/%s/%s\n", filepath.Base(binFilePath), server.URL(), relPath, newBinFileName)
}

return url, nil
return info, nil
})
}

Expand Down Expand Up @@ -271,20 +299,66 @@ func (m *Main) deploy(ctx context.Context, r io.Reader) error {
return fmt.Errorf("error creating kurtosis deployer: %w", err)
}

env, err := d.Deploy(ctx, buf)
spec, err := d.Deploy(ctx, buf)
if err != nil {
return fmt.Errorf("error deploying kurtosis package: %w", err)
}

env, err := d.GetEnvironmentInfo(ctx, spec)
if err != nil {
return fmt.Errorf("error getting environment: %w", err)
}

if err := writeEnvironment(m.cfg.environment, env); err != nil {
return fmt.Errorf("error writing environment: %w", err)
}

return nil
}

func (m *Main) deployFileserver(ctx context.Context, sourceDir string) error {
// Create a temp dir in the fileserver package
baseDir := filepath.Join(m.cfg.baseDir, FILESERVER_PACKAGE)
if err := os.MkdirAll(baseDir, 0755); err != nil {
return fmt.Errorf("error creating base directory: %w", err)
}
tempDir, err := os.MkdirTemp(baseDir, "upload-content")
if err != nil {
return fmt.Errorf("error creating temporary directory: %w", err)
}
defer os.RemoveAll(tempDir)

// Copy build dir contents to tempDir
if err := util.CopyDir(sourceDir, tempDir); err != nil {
return fmt.Errorf("error copying directory: %w", err)
}

buf := bytes.NewBuffer(nil)
buf.WriteString(fmt.Sprintf("source_path: %s\n", filepath.Base(tempDir)))

opts := []kurtosis.KurtosisDeployerOptions{
kurtosis.WithKurtosisBaseDir(m.cfg.baseDir),
kurtosis.WithKurtosisDryRun(m.cfg.dryRun),
kurtosis.WithKurtosisPackageName(FILESERVER_PACKAGE),
kurtosis.WithKurtosisEnclave(m.cfg.enclave),
}

d, err := m.newDeployer(opts...)
if err != nil {
return fmt.Errorf("error creating kurtosis deployer: %w", err)
}

_, err = d.Deploy(ctx, buf)
if err != nil {
return fmt.Errorf("error deploying kurtosis package: %w", err)
}

return nil
}

type deployer interface {
Deploy(ctx context.Context, input io.Reader) (*kurtosis.KurtosisEnvironment, error)
Deploy(ctx context.Context, input io.Reader) (*spec.EnclaveSpec, error)
GetEnvironmentInfo(ctx context.Context, spec *spec.EnclaveSpec) (*kurtosis.KurtosisEnvironment, error)
}

func writeEnvironment(path string, env *kurtosis.KurtosisEnvironment) error {
Expand Down Expand Up @@ -328,6 +402,12 @@ func (m *Main) run() error {
return fmt.Errorf("error rendering template: %w", err)
}

// TODO: clean up consumers of static server and replace with fileserver
err = m.deployFileserver(ctx, server.dir)
if err != nil {
return fmt.Errorf("error deploying fileserver: %w", err)
}

return m.deploy(ctx, buf)
}

Expand Down
Loading