Skip to content

Commit 9c07467

Browse files
authored
Merge pull request #27 from ConstellationCrypto/inomurko/path-trim-fix
Add S3 path, replace deprecated docker compose, trim origin block
2 parents 42bd2a1 + fcf4e9b commit 9c07467

File tree

7 files changed

+25
-11
lines changed

7 files changed

+25
-11
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build:
55
.PHONY: build
66

77
build-docker:
8-
docker-compose build
8+
docker compose build
99
.PHONY: build-docker
1010

1111
clean:
@@ -21,8 +21,8 @@ test:
2121
.PHONY: test
2222

2323
integration:
24-
docker-compose down
25-
docker-compose up -d minio create-buckets
24+
docker compose down
25+
docker compose up -d minio create-buckets
2626
RUN_INTEGRATION_TESTS=true go test -v ./...
2727
.PHONY: integration
2828

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ To run the project locally, you should first copy `.env.template` to `.env` and
4646
to your beacon client and storage backend of choice. Then you can run the project with:
4747

4848
```sh
49-
docker-compose up
49+
docker compose up
5050
```
5151

5252
You can see a full list of configuration options by running:

archiver/flags/config.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package flags
22

33
import (
44
"fmt"
5+
"strings"
56
"time"
67

78
common "github.com/base-org/blob-archiver/common/flags"
@@ -35,7 +36,7 @@ func (c ArchiverConfig) Check() error {
3536
}
3637

3738
if c.OriginBlock == (geth.Hash{}) {
38-
return fmt.Errorf("invalid origin block")
39+
return fmt.Errorf("invalid origin block %s", c.OriginBlock)
3940
}
4041

4142
if c.ListenAddr == "" {
@@ -53,7 +54,7 @@ func ReadConfig(cliCtx *cli.Context) ArchiverConfig {
5354
BeaconConfig: common.NewBeaconConfig(cliCtx),
5455
StorageConfig: common.NewStorageConfig(cliCtx),
5556
PollInterval: pollInterval,
56-
OriginBlock: geth.HexToHash(cliCtx.String(ArchiverOriginBlock.Name)),
57+
OriginBlock: geth.HexToHash(strings.Trim(cliCtx.String(ArchiverOriginBlock.Name), "\"")),
5758
ListenAddr: cliCtx.String(ArchiverListenAddrFlag.Name),
5859
}
5960
}

common/flags/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type S3Config struct {
2424
Endpoint string
2525
UseHttps bool
2626
Bucket string
27+
Path string
2728

2829
S3CredentialType S3CredentialType
2930
AccessKey string
@@ -106,6 +107,7 @@ func readS3Config(ctx *cli.Context) S3Config {
106107
SecretAccessKey: ctx.String(S3SecretAccessKeyFlagName),
107108
UseHttps: ctx.Bool(S3EndpointHttpsFlagName),
108109
Bucket: ctx.String(S3BucketFlagName),
110+
Path: ctx.String(S3PathFlagName),
109111
S3CredentialType: toS3CredentialType(ctx.String(S3CredentialTypeFlagName)),
110112
Compress: ctx.Bool(S3CompressFlagName),
111113
}

common/flags/flags.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const (
1717
S3AccessKeyFlagName = "s3-access-key"
1818
S3SecretAccessKeyFlagName = "s3-secret-access-key"
1919
S3BucketFlagName = "s3-bucket"
20+
S3PathFlagName = "s3-path"
2021
FileStorageDirectoryFlagName = "file-directory"
2122
)
2223

@@ -77,6 +78,13 @@ func CLIFlags(envPrefix string) []cli.Flag {
7778
Hidden: true,
7879
EnvVars: opservice.PrefixEnvVar(envPrefix, "S3_BUCKET"),
7980
},
81+
&cli.StringFlag{
82+
Name: S3PathFlagName,
83+
Usage: "The path to append to file",
84+
Hidden: true,
85+
EnvVars: opservice.PrefixEnvVar(envPrefix, "S3_PATH"),
86+
Value: "",
87+
},
8088
// File Data Store Flags
8189
&cli.StringFlag{
8290
Name: FileStorageDirectoryFlagName,

common/storage/s3.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"context"
77
"encoding/json"
88
"io"
9+
"path"
910

1011
"github.com/base-org/blob-archiver/common/flags"
1112
"github.com/ethereum/go-ethereum/common"
@@ -17,6 +18,7 @@ import (
1718
type S3Storage struct {
1819
s3 *minio.Client
1920
bucket string
21+
path string
2022
log log.Logger
2123
compress bool
2224
}
@@ -41,13 +43,14 @@ func NewS3Storage(cfg flags.S3Config, l log.Logger) (*S3Storage, error) {
4143
return &S3Storage{
4244
s3: client,
4345
bucket: cfg.Bucket,
46+
path: cfg.Path,
4447
log: l,
4548
compress: cfg.Compress,
4649
}, nil
4750
}
4851

4952
func (s *S3Storage) Exists(ctx context.Context, hash common.Hash) (bool, error) {
50-
_, err := s.s3.StatObject(ctx, s.bucket, hash.String(), minio.StatObjectOptions{})
53+
_, err := s.s3.StatObject(ctx, s.bucket, path.Join(s.path, hash.String()), minio.StatObjectOptions{})
5154
if err != nil {
5255
errResponse := minio.ToErrorResponse(err)
5356
if errResponse.Code == "NoSuchKey" {
@@ -61,7 +64,7 @@ func (s *S3Storage) Exists(ctx context.Context, hash common.Hash) (bool, error)
6164
}
6265

6366
func (s *S3Storage) Read(ctx context.Context, hash common.Hash) (BlobData, error) {
64-
res, err := s.s3.GetObject(ctx, s.bucket, hash.String(), minio.GetObjectOptions{})
67+
res, err := s.s3.GetObject(ctx, s.bucket, path.Join(s.path, hash.String()), minio.GetObjectOptions{})
6568
if err != nil {
6669
s.log.Info("unexpected error fetching blob", "hash", hash.String(), "err", err)
6770
return BlobData{}, ErrStorage
@@ -122,7 +125,7 @@ func (s *S3Storage) Write(ctx context.Context, data BlobData) error {
122125

123126
reader := bytes.NewReader(b)
124127

125-
_, err = s.s3.PutObject(ctx, s.bucket, data.Header.BeaconBlockHash.String(), reader, int64(len(b)), options)
128+
_, err = s.s3.PutObject(ctx, s.bucket, path.Join(s.path, data.Header.BeaconBlockHash.String()), reader, int64(len(b)), options)
126129

127130
if err != nil {
128131
s.log.Warn("error writing blob", "err", err)

common/storage/s3_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import (
1414

1515
// Prior to running these tests, a local Minio server must be running.
1616
// You can accomplish this with:
17-
// docker-compose down # shut down any running services
18-
// docker-compose up minio create-buckets # start the minio service
17+
// docker compose down # shut down any running services
18+
// docker compose up minio create-buckets # start the minio service
1919
func setupS3(t *testing.T) *S3Storage {
2020
if os.Getenv("RUN_INTEGRATION_TESTS") == "" {
2121
t.Skip("skipping integration tests: set RUN_INTEGRATION_TESTS environment variable")

0 commit comments

Comments
 (0)