Skip to content

Commit 039d6d6

Browse files
committed
Switch to official minio container for CI
1 parent c01db89 commit 039d6d6

File tree

4 files changed

+33
-18
lines changed

4 files changed

+33
-18
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,6 @@ jobs:
1818
- 5432:5432
1919
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
2020

21-
minio:
22-
image: bitnami/minio:latest
23-
env:
24-
MINIO_ROOT_USER: root
25-
MINIO_ROOT_PASSWORD: tembatemba
26-
MINIO_DEFAULT_BUCKETS: temba-archives
27-
ports:
28-
- 9000:9000
29-
options: --health-cmd "mc ready local" --health-interval 10s --health-timeout 5s --health-retries 5
30-
3121
steps:
3222
- name: Checkout code
3323
uses: actions/checkout@v4
@@ -37,6 +27,19 @@ jobs:
3727
with:
3828
go-version: ${{ env.go-version }}
3929

30+
- name: Run MinIO docker container
31+
run: |
32+
docker run -d --rm \
33+
-p 9000:9000 \
34+
-p 9001:9001 \
35+
--env MINIO_ROOT_USER=root \
36+
--env MINIO_ROOT_PASSWORD=tembatemba \
37+
--health-cmd "curl -f http://127.0.0.1:9000/minio/health/live" \
38+
--health-interval 10s \
39+
--health-timeout 5s \
40+
--health-retries 5 \
41+
minio/minio:latest minio server /data --console-address ":9001"
42+
4043
- name: Run tests
4144
run: go test -p=1 -coverprofile=coverage.text -covermode=atomic ./...
4245

archives/archives_test.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"testing"
1010
"time"
1111

12+
"github.com/aws/aws-sdk-go-v2/aws"
13+
"github.com/aws/aws-sdk-go-v2/service/s3"
1214
"github.com/jmoiron/sqlx"
1315
_ "github.com/lib/pq"
1416
"github.com/nyaruka/gocommon/aws/cwatch"
@@ -18,7 +20,7 @@ import (
1820
)
1921

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

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

41-
s3Client, err := NewS3Client(config)
43+
s3Client, err := NewS3Client(config, false)
4244
require.NoError(t, err)
4345

46+
if s3Client.Test(ctx, "temba-archives") != nil {
47+
_, err = s3Client.Client.CreateBucket(ctx, &s3.CreateBucketInput{Bucket: aws.String("temba-archives")})
48+
require.NoError(t, err)
49+
}
50+
4451
slog.SetDefault(slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug})))
4552

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

56+
t.Cleanup(func() {
57+
s3Client.EmptyBucket(ctx, "temba-archives")
58+
})
59+
4960
return ctx, &runtime.Runtime{Config: config, DB: db, S3: s3Client, CW: CW}
5061
}
5162

archives/s3.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,17 @@ const maxSingleUploadBytes = 5e9 // 5GB
3030
const chunkSizeBytes = 1e9 // 1GB
3131

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

39-
// test out our S3 credentials
40-
if err := svc.Test(context.TODO(), cfg.S3Bucket); err != nil {
41-
slog.Error("s3 bucket not reachable", "error", err)
42-
return nil, err
39+
if test {
40+
if err := svc.Test(context.TODO(), cfg.S3Bucket); err != nil {
41+
slog.Error("s3 bucket not reachable", "error", err)
42+
return nil, err
43+
}
4344
}
4445

4546
return svc, nil

cmd/rp-archiver/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func main() {
9797
}
9898

9999
if config.UploadToS3 {
100-
rt.S3, err = archives.NewS3Client(config)
100+
rt.S3, err = archives.NewS3Client(config, true)
101101
if err != nil {
102102
logger.Error("unable to initialize s3 client", "error", err)
103103
} else {

0 commit comments

Comments
 (0)