@@ -10,9 +10,6 @@ import (
1010 "github.com/dagger/container-use/edit"
1111)
1212
13- // FIXME: See hack where it's used
14- const fileUtilsBaseImage = "busybox"
15-
1613func (env * Environment ) FileRead (ctx context.Context , targetFile string , shouldReadEntireFile bool , startLineOneIndexedInclusive int , endLineOneIndexedInclusive int ) (string , error ) {
1714 file , err := env .container ().File (targetFile ).Contents (ctx )
1815 if err != nil {
@@ -85,10 +82,10 @@ func (env *Environment) ls(ctx context.Context, path string, filter dagger.Direc
8582
8683func (env * Environment ) FileGrep (ctx context.Context , path , pattern , include string ) (string , error ) {
8784 // Hack: use busybox to run `sed` since dagger doesn't have native file editing primitives.
88- args := []string {"/bin/grep " , "-E " , "-- " , pattern , include }
85+ args := []string {"/usr/ bin/rg " , "--no-unicode " , "-g" , include , "-- " , pattern , path }
8986
90- dir := env .container ().Rootfs (). Directory (path )
91- out , err := dag . Container (). From ( fileUtilsBaseImage ).WithMountedDirectory ("/mnt " , dir ).WithWorkdir ("/mnt " ).WithExec (args ).Stdout (ctx )
87+ dir := env .container ().Directory (path )
88+ out , err := GrepUtil ( env . dag ).WithMountedDirectory ("/workdir " , dir ).WithWorkdir ("/workdir " ).WithExec (args , dagger. ContainerWithExecOpts { Expect : dagger . ReturnTypeAny } ).Stdout (ctx )
9289 if err != nil {
9390 return "" , err
9491 }
@@ -107,8 +104,13 @@ func EditUtil(dag *dagger.Client) *dagger.Container {
107104 WithNewFile ("/go/src/go.mod" , edit .GoMod ).
108105 WithNewFile ("/go/src/go.sum" , edit .GoSum ).
109106 WithEnvVariable ("CGO_ENABLED" , "0" ).
107+ WithWorkdir ("/go/src" ).
110108 WithExec ([]string {"go" , "build" , "-o" , "/edit" , "-ldflags" , "-w -s" , "/go/src/edit.go" }).File ("/edit" )
111- return dag .Container ().From ("scratch" ).WithFile ("/edit" , editBin ).WithEntrypoint ([]string {"/edit" })
109+ return dag .Container ().From (alpineImage ).WithFile ("/edit" , editBin ).WithEntrypoint ([]string {"/edit" })
110+ }
111+
112+ func GrepUtil (dag * dagger.Client ) * dagger.Container {
113+ return dag .Container ().From (alpineImage ).WithExec ([]string {"apk" , "add" , "-U" , "ripgrep" })
112114}
113115
114116func (env * Environment ) FileEdit (ctx context.Context , targetFile string , edits []FileEdit ) error {
0 commit comments