Created
April 7, 2025 10:26
-
-
Save bestie/99bc59f0f5d8cecc4df9e40910bfdced to your computer and use it in GitHub Desktop.
Earthly auto-skip DB dumper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM golang:1.24-bookworm | |
WORKDIR /app | |
COPY dumper.go . | |
RUN go mod init boltdbdumper && \ | |
go get go.etcd.io/bbolt@latest && \ | |
go mod tidy && \ | |
go build -o dumper | |
CMD ["./dumper"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euxo pipefail | |
dbfile=$(readlink --canonicalize "$1") | |
docker build --tag earthly-auto-skip-db-dumper . | |
docker run \ | |
--rm \ | |
--interactive --tty \ | |
--env "DB_FILE=target.db" \ | |
--volume "$dbfile:/app/target.db" \ | |
earthly-auto-skip-db-dumper |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/hex" | |
"fmt" | |
"log" | |
"os" | |
bolt "go.etcd.io/bbolt" | |
) | |
func main() { | |
path := os.Getenv("DB_FILE") | |
if path == "" { | |
log.Fatal("DB_FILE environment variable is not set") | |
} | |
db, err := bolt.Open(path, 0600, nil) | |
if err != nil { | |
log.Fatal(err) | |
} | |
defer db.Close() | |
err = db.View(func(tx *bolt.Tx) error { | |
return tx.ForEach(func(bname []byte, b *bolt.Bucket) error { | |
fmt.Printf("Bucket: %s\n", bname) | |
return b.ForEach(func(k, v []byte) error { | |
fmt.Printf(" %s => %s\n", hex.EncodeToString(k), v) | |
return nil | |
}) | |
}) | |
}) | |
if err != nil { | |
log.Fatal(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment