Skip to content
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
23 changes: 13 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,6 @@ jobs:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

minio:
image: bitnami/minio:latest
env:
MINIO_ROOT_USER: root
MINIO_ROOT_PASSWORD: tembatemba
MINIO_DEFAULT_BUCKETS: temba-archives
ports:
- 9000:9000
options: --health-cmd "mc ready local" --health-interval 10s --health-timeout 5s --health-retries 5

steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -37,6 +27,19 @@ jobs:
with:
go-version: ${{ env.go-version }}

- name: Run MinIO docker container
run: |
docker run -d --rm \
-p 9000:9000 \
-p 9001:9001 \
--env MINIO_ROOT_USER=root \
--env MINIO_ROOT_PASSWORD=tembatemba \
--health-cmd "curl -f http://127.0.0.1:9000/minio/health/live" \
--health-interval 10s \
--health-timeout 5s \
--health-retries 5 \
minio/minio:latest minio server /data --console-address ":9001"
Copy link
Preview

Copilot AI Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using 'latest' tag for the MinIO container can lead to unpredictable CI builds when new versions are released. Consider pinning to a specific version tag for reproducible builds.

Suggested change
minio/minio:latest minio server /data --console-address ":9001"
minio/minio:RELEASE.2024-05-10T03-52-56Z minio server /data --console-address ":9001"

Copilot uses AI. Check for mistakes.


- name: Run tests
run: go test -p=1 -coverprofile=coverage.text -covermode=atomic ./...

Expand Down
15 changes: 13 additions & 2 deletions archives/archives_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"testing"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/jmoiron/sqlx"
_ "github.com/lib/pq"
"github.com/nyaruka/gocommon/aws/cwatch"
Expand All @@ -18,7 +20,7 @@ import (
)

func setup(t *testing.T) (context.Context, *runtime.Runtime) {
ctx := context.Background()
ctx := t.Context()
config := runtime.NewDefaultConfig()
config.DB = "postgres://archiver_test:temba@localhost:5432/archiver_test?sslmode=disable&TimeZone=UTC"

Expand All @@ -38,14 +40,23 @@ func setup(t *testing.T) (context.Context, *runtime.Runtime) {
_, err = db.Exec(string(testDB))
require.NoError(t, err)

s3Client, err := NewS3Client(config)
s3Client, err := NewS3Client(config, false)
require.NoError(t, err)

if s3Client.Test(ctx, "temba-archives") != nil {
_, err = s3Client.Client.CreateBucket(ctx, &s3.CreateBucketInput{Bucket: aws.String("temba-archives")})
require.NoError(t, err)
}
Comment on lines +46 to +49
Copy link
Preview

Copilot AI Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bucket name 'temba-archives' is hardcoded in multiple places. Consider defining it as a constant to improve maintainability and reduce the risk of typos.

Copilot uses AI. Check for mistakes.


slog.SetDefault(slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug})))

CW, err := cwatch.NewService(config.AWSAccessKeyID, config.AWSSecretAccessKey, config.AWSRegion, config.CloudwatchNamespace, config.DeploymentID)
require.NoError(t, err)

t.Cleanup(func() {
s3Client.EmptyBucket(ctx, "temba-archives")
})

return ctx, &runtime.Runtime{Config: config, DB: db, S3: s3Client, CW: CW}
}

Expand Down
11 changes: 6 additions & 5 deletions archives/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,17 @@ const maxSingleUploadBytes = 5e9 // 5GB
const chunkSizeBytes = 1e9 // 1GB

// NewS3Client creates a new s3 service from the passed in config, testing it as necessary
func NewS3Client(cfg *runtime.Config) (*s3x.Service, error) {
func NewS3Client(cfg *runtime.Config, test bool) (*s3x.Service, error) {
svc, err := s3x.NewService(cfg.AWSAccessKeyID, cfg.AWSSecretAccessKey, cfg.AWSRegion, cfg.S3Endpoint, cfg.S3Minio)
if err != nil {
return nil, err
}

// test out our S3 credentials
if err := svc.Test(context.TODO(), cfg.S3Bucket); err != nil {
slog.Error("s3 bucket not reachable", "error", err)
return nil, err
if test {
if err := svc.Test(context.TODO(), cfg.S3Bucket); err != nil {
slog.Error("s3 bucket not reachable", "error", err)
return nil, err
}
}

return svc, nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/rp-archiver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func main() {
}

if config.UploadToS3 {
rt.S3, err = archives.NewS3Client(config)
rt.S3, err = archives.NewS3Client(config, true)
if err != nil {
logger.Error("unable to initialize s3 client", "error", err)
} else {
Expand Down