@@ -14,24 +14,25 @@ import (
1414 "github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/build"
1515 "github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/kurtosis"
1616 "github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/kurtosis/api/engine"
17- "github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/kurtosis/backend"
1817 "github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/kurtosis/sources/spec"
19- "github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/serve"
2018 "github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/tmpl"
2119 "github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/util"
2220 "github.com/urfave/cli/v2"
2321)
2422
2523const FILESERVER_PACKAGE = "fileserver"
2624
25+ func fileserverURL (path ... string ) string {
26+ return fmt .Sprintf ("http://%s/%s" , FILESERVER_PACKAGE , strings .Join (path , "/" ))
27+ }
28+
2729type config struct {
2830 templateFile string
2931 dataFile string
3032 kurtosisPackage string
3133 enclave string
3234 environment string
3335 dryRun bool
34- localHostName string
3536 baseDir string
3637 kurtosisBinary string
3738}
@@ -44,7 +45,6 @@ func newConfig(c *cli.Context) (*config, error) {
4445 enclave : c .String ("enclave" ),
4546 environment : c .String ("environment" ),
4647 dryRun : c .Bool ("dry-run" ),
47- localHostName : c .String ("local-hostname" ),
4848 kurtosisBinary : c .String ("kurtosis-binary" ),
4949 }
5050
@@ -57,11 +57,6 @@ func newConfig(c *cli.Context) (*config, error) {
5757 return cfg , nil
5858}
5959
60- type staticServer struct {
61- dir string
62- * serve.Server
63- }
64-
6560type engineManager interface {
6661 EnsureRunning () error
6762}
@@ -72,34 +67,6 @@ type Main struct {
7267 engineManager engineManager
7368}
7469
75- func (m * Main ) launchStaticServer (ctx context.Context ) (* staticServer , func (), error ) {
76- // we will serve content from this tmpDir for the duration of the devnet creation
77- tmpDir , err := os .MkdirTemp ("" , m .cfg .enclave )
78- if err != nil {
79- return nil , nil , fmt .Errorf ("error creating temporary directory: %w" , err )
80- }
81-
82- server := serve .NewServer (
83- serve .WithStaticDir (tmpDir ),
84- serve .WithHostname (m .cfg .localHostName ),
85- )
86- if err := server .Start (ctx ); err != nil {
87- return nil , nil , fmt .Errorf ("error starting server: %w" , err )
88- }
89-
90- return & staticServer {
91- dir : tmpDir ,
92- Server : server ,
93- }, func () {
94- if err := server .Stop (ctx ); err != nil {
95- log .Printf ("Error stopping server: %v\n " , err )
96- }
97- if err := os .RemoveAll (tmpDir ); err != nil {
98- log .Printf ("Error removing temporary directory: %v\n " , err )
99- }
100- }, nil
101- }
102-
10370func (m * Main ) localDockerImageOption () tmpl.TemplateContextOptions {
10471 dockerBuilder := build .NewDockerBuilder (
10572 build .WithDockerBaseDir (m .cfg .baseDir ),
@@ -115,11 +82,12 @@ func (m *Main) localDockerImageOption() tmpl.TemplateContextOptions {
11582 })
11683}
11784
118- func (m * Main ) localContractArtifactsOption (server * staticServer ) tmpl.TemplateContextOptions {
85+ func (m * Main ) localContractArtifactsOption (dir string ) tmpl.TemplateContextOptions {
11986 contractsBundle := fmt .Sprintf ("contracts-bundle-%s.tar.gz" , m .cfg .enclave )
12087 contractsBundlePath := func (_ string ) string {
121- return filepath .Join (server . dir , contractsBundle )
88+ return filepath .Join (dir , contractsBundle )
12289 }
90+ contractsURL := fileserverURL (contractsBundle )
12391
12492 contractBuilder := build .NewContractBuilder (
12593 build .WithContractBaseDir (m .cfg .baseDir ),
@@ -128,18 +96,12 @@ func (m *Main) localContractArtifactsOption(server *staticServer) tmpl.TemplateC
12896
12997 return tmpl .WithFunction ("localContractArtifacts" , func (layer string ) (string , error ) {
13098 bundlePath := contractsBundlePath (layer )
131- // we're in a temp dir, so we can skip the build if the file already
132- // exists: it'll be the same file! In particular, since we're ignoring
133- // layer for now, skip the 2nd build.
134- if _ , err := os .Stat (bundlePath ); err != nil {
135- if err := contractBuilder .Build (layer , bundlePath ); err != nil {
136- return "" , err
137- }
99+ if err := contractBuilder .Build (layer , bundlePath ); err != nil {
100+ return "" , err
138101 }
139102
140- url := fmt .Sprintf ("%s/%s" , server .URL (), contractsBundle )
141- log .Printf ("%s: contract artifacts available at: %s\n " , layer , url )
142- return url , nil
103+ log .Printf ("%s: contract artifacts available at: %s\n " , layer , contractsURL )
104+ return contractsURL , nil
143105 })
144106}
145107
@@ -148,27 +110,24 @@ type PrestateInfo struct {
148110 Hashes map [string ]string `json:"hashes"`
149111}
150112
151- func (m * Main ) localPrestateOption (server * staticServer ) tmpl.TemplateContextOptions {
113+ func (m * Main ) localPrestateOption (dir string ) tmpl.TemplateContextOptions {
152114 prestateBuilder := build .NewPrestateBuilder (
153115 build .WithPrestateBaseDir (m .cfg .baseDir ),
154116 build .WithPrestateDryRun (m .cfg .dryRun ),
155117 )
156118
157119 return tmpl .WithFunction ("localPrestate" , func () (* PrestateInfo , error ) {
120+ prestatePath := []string {"proofs" , "op-program" , "cannon" }
121+ prestateURL := fileserverURL (prestatePath ... )
122+
158123 // Create build directory with the final path structure
159- buildDir := filepath .Join (server . dir , "proofs" , "op-program" , "cannon" )
124+ buildDir := filepath .Join (append ([] string { dir }, prestatePath ... ) ... )
160125 if err := os .MkdirAll (buildDir , 0755 ); err != nil {
161126 return nil , fmt .Errorf ("failed to create prestate build directory: %w" , err )
162127 }
163128
164- // Get the relative path from server.dir to buildDir for the URL
165- relPath , err := filepath .Rel (server .dir , buildDir )
166- if err != nil {
167- return nil , fmt .Errorf ("failed to get relative path: %w" , err )
168- }
169-
170129 info := & PrestateInfo {
171- URL : fmt . Sprintf ( "%s/%s" , server . URL (), relPath ) ,
130+ URL : prestateURL ,
172131 Hashes : make (map [string ]string ),
173132 }
174133
@@ -219,7 +178,7 @@ func (m *Main) localPrestateOption(server *staticServer) tmpl.TemplateContextOpt
219178 if err := os .Rename (filePath , hashedPath ); err != nil {
220179 return nil , fmt .Errorf ("failed to rename prestate %s: %w" , filepath .Base (filePath ), err )
221180 }
222- log .Printf ("%s available at: %s/%s/%s \n " , filepath .Base (filePath ), server . URL (), relPath , newFileName )
181+ log .Printf ("%s available at: %s/%s\n " , filepath .Base (filePath ), prestateURL , newFileName )
223182
224183 // Rename the corresponding binary file
225184 binFilePath := strings .Replace (strings .TrimSuffix (filePath , ".json" ), "-proof" , "" , 1 ) + ".bin.gz"
@@ -228,18 +187,18 @@ func (m *Main) localPrestateOption(server *staticServer) tmpl.TemplateContextOpt
228187 if err := os .Rename (binFilePath , binHashedPath ); err != nil {
229188 return nil , fmt .Errorf ("failed to rename prestate %s: %w" , filepath .Base (binFilePath ), err )
230189 }
231- log .Printf ("%s available at: %s/%s/%s \n " , filepath .Base (binFilePath ), server . URL (), relPath , newBinFileName )
190+ log .Printf ("%s available at: %s/%s\n " , filepath .Base (binFilePath ), prestateURL , newBinFileName )
232191 }
233192
234193 return info , nil
235194 })
236195}
237196
238- func (m * Main ) renderTemplate (server * staticServer ) (* bytes.Buffer , error ) {
197+ func (m * Main ) renderTemplate (dir string ) (* bytes.Buffer , error ) {
239198 opts := []tmpl.TemplateContextOptions {
240199 m .localDockerImageOption (),
241- m .localContractArtifactsOption (server ),
242- m .localPrestateOption (server ),
200+ m .localContractArtifactsOption (dir ),
201+ m .localPrestateOption (dir ),
243202 }
244203
245204 // Read and parse the data file if provided
@@ -391,19 +350,19 @@ func (m *Main) run() error {
391350 }
392351 }
393352
394- server , cleanup , err := m . launchStaticServer ( ctx )
353+ tmpDir , err := os . MkdirTemp ( "" , m . cfg . enclave )
395354 if err != nil {
396- return fmt .Errorf ("error launching static server : %w" , err )
355+ return fmt .Errorf ("error creating temporary directory : %w" , err )
397356 }
398- defer cleanup ( )
357+ defer os . RemoveAll ( tmpDir )
399358
400- buf , err := m .renderTemplate (server )
359+ buf , err := m .renderTemplate (tmpDir )
401360 if err != nil {
402361 return fmt .Errorf ("error rendering template: %w" , err )
403362 }
404363
405364 // TODO: clean up consumers of static server and replace with fileserver
406- err = m .deployFileserver (ctx , server . dir )
365+ err = m .deployFileserver (ctx , tmpDir )
407366 if err != nil {
408367 return fmt .Errorf ("error deploying fileserver: %w" , err )
409368 }
@@ -455,11 +414,6 @@ func getFlags() []cli.Flag {
455414 Name : "dry-run" ,
456415 Usage : "Dry run mode (optional)" ,
457416 },
458- & cli.StringFlag {
459- Name : "local-hostname" ,
460- Usage : "DNS for localhost from Kurtosis perspective (optional)" ,
461- Value : backend .DefaultDockerHost (),
462- },
463417 & cli.StringFlag {
464418 Name : "kurtosis-binary" ,
465419 Usage : "Path to kurtosis binary (optional)" ,
0 commit comments