Skip to content

Commit

Permalink
docker-compose.yml ; Dockerfile.test ; connect to yugabyte and not …
Browse files Browse the repository at this point in the history
…localhost
  • Loading branch information
nonsense committed May 8, 2023
1 parent 508bd8a commit 20a7fc2
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 63 deletions.
20 changes: 16 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ jobs:
paths:
- linux

lid-docker-compose:
description: 'Run LID integration tests'
machine:
image: ubuntu-2004:202104-01
resource_class: xlarge
steps:
- checkout
- run:
name: local index directory docker compose tests
command: |
set -x
cd ./extern/boostd-data
docker-compose up --build --exit-code-from go-tests
test:
description: |
Run go tests
Expand Down Expand Up @@ -322,7 +336,5 @@ workflows:
suite: all
target: "`go list ./... | grep -v boost/itests`"

- test:
name: local index directory
suite: all
cwd: "./extern/boostd-data"
- lid-docker-compose

8 changes: 8 additions & 0 deletions extern/boostd-data/Dockerfile.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM golang:1.18-alpine

WORKDIR /go/src/

ENV CGO_ENABLED=0

ENTRYPOINT ["go", "test"]
CMD ["-v", "./..."]
18 changes: 18 additions & 0 deletions extern/boostd-data/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: '3.7'

services:

yugabyte:
image: public.ecr.aws/n6b0k8i7/yugabyte-test:x86_64-2.17.2.0
#image: public.ecr.aws/n6b0k8i7/yugabyte-test:aarch64-2.17.2.0
restart: on-failure

go-tests:
build:
context: .
dockerfile: ./Dockerfile.test
environment:
YUGABYTE_HOST: yugabyte
volumes:
- ./:/go/src/
command: -v -count=1 -p=1 ./...
101 changes: 48 additions & 53 deletions extern/boostd-data/svc/setup_yugabyte_test_util.go
Original file line number Diff line number Diff line change
@@ -1,78 +1,72 @@
package svc

import (
"github.com/davecgh/go-spew/spew"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
dockercl "github.com/docker/docker/client"
"github.com/docker/go-connections/nat"
"testing"
"time"

"github.com/filecoin-project/boostd-data/yugabyte"
"github.com/stretchr/testify/require"
"github.com/yugabyte/gocql"
"golang.org/x/net/context"
"io"
"os"
"testing"
"time"
)

func SetupYugabyte(t *testing.T) {
ctx := context.Background()
cli, err := dockercl.NewClientWithOpts(dockercl.FromEnv)
require.NoError(t, err)
//cli, err := dockercl.NewClientWithOpts(dockercl.FromEnv)
//require.NoError(t, err)

imageName := "public.ecr.aws/n6b0k8i7/yugabyte-test:x86_64-2.17.2.0"
out, err := cli.ImagePull(ctx, imageName, types.ImagePullOptions{})
require.NoError(t, err)
//imageName := "public.ecr.aws/n6b0k8i7/yugabyte-test:x86_64-2.17.2.0"
//out, err := cli.ImagePull(ctx, imageName, types.ImagePullOptions{})
//require.NoError(t, err)

_, err = io.Copy(os.Stdout, out)
require.NoError(t, err)
//_, err = io.Copy(os.Stdout, out)
//require.NoError(t, err)

tlog.Info("yugabyte docker container create...")
resp, err := cli.ContainerCreate(ctx, &container.Config{
Image: imageName,
ExposedPorts: nat.PortSet{
"7000": struct{}{},
"9000": struct{}{},
"5433": struct{}{},
"9042": struct{}{},
},
}, &container.HostConfig{
PortBindings: map[nat.Port][]nat.PortBinding{
"7000": {{HostIP: "127.0.0.1", HostPort: "7001"}},
"9000": {{HostIP: "127.0.0.1", HostPort: "9000"}},
"5433": {{HostIP: "127.0.0.1", HostPort: "5433"}},
"9042": {{HostIP: "127.0.0.1", HostPort: "9042"}},
},
}, nil, nil, "")
require.NoError(t, err)
tlog.Info("yugabyte docker container created")
//tlog.Info("yugabyte docker container create...")
//resp, err := cli.ContainerCreate(ctx, &container.Config{
//Image: imageName,
//ExposedPorts: nat.PortSet{
//"7000": struct{}{},
//"9000": struct{}{},
//"5433": struct{}{},
//"9042": struct{}{},
//},
//}, &container.HostConfig{
//PortBindings: map[nat.Port][]nat.PortBinding{
//"7000": {{HostIP: "127.0.0.1", HostPort: "7001"}},
//"9000": {{HostIP: "127.0.0.1", HostPort: "9000"}},
//"5433": {{HostIP: "127.0.0.1", HostPort: "5433"}},
//"9042": {{HostIP: "127.0.0.1", HostPort: "9042"}},
//},
//}, nil, nil, "")
//require.NoError(t, err)
//tlog.Info("yugabyte docker container created")

tlog.Info("yugabyte docker container start...")
err = cli.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{})
require.NoError(t, err)
tlog.Info("yugabyte docker container started")
//tlog.Info("yugabyte docker container start...")
//err = cli.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{})
//require.NoError(t, err)
//tlog.Info("yugabyte docker container started")

inspect, err := cli.ContainerInspect(ctx, resp.ID)
require.NoError(t, err)
spew.Dump(inspect)
//inspect, err := cli.ContainerInspect(ctx, resp.ID)
//require.NoError(t, err)
//spew.Dump(inspect)

t.Cleanup(func() {
tlog.Info("yugabyte docker container remove...")
err := cli.ContainerRemove(ctx, resp.ID, types.ContainerRemoveOptions{Force: true})
require.NoError(t, err)
tlog.Info("yugabyte docker container removed")
})
//t.Cleanup(func() {
//tlog.Info("yugabyte docker container remove...")
//err := cli.ContainerRemove(ctx, resp.ID, types.ContainerRemoveOptions{Force: true})
//require.NoError(t, err)
//tlog.Info("yugabyte docker container removed")
//})

tlog.Info("wait for yugabyte start...")
awaitYugabyteUp(t, time.Minute)
tlog.Info("yugabyte started")

store := yugabyte.NewStore(yugabyte.DBSettings{
Hosts: []string{"127.0.0.1"},
ConnectString: "postgresql://postgres:postgres@localhost",
Hosts: []string{"yugabyte"},
ConnectString: "postgresql://postgres:postgres@yugabyte:5433",
})
err = store.Start(ctx)
err := store.Start(ctx)
require.NoError(t, err)

RecreateTables(ctx, t, store)
Expand All @@ -87,10 +81,11 @@ func RecreateTables(ctx context.Context, t *testing.T, store *yugabyte.Store) {

func awaitYugabyteUp(t *testing.T, duration time.Duration) {
start := time.Now()
cluster := gocql.NewCluster("127.0.0.1")
cluster := gocql.NewCluster("yugabyte")
for {
session, err := cluster.CreateSession()
if err == nil {
time.Sleep(5 * time.Second)
return
}
_ = session
Expand All @@ -99,6 +94,6 @@ func awaitYugabyteUp(t *testing.T, duration time.Duration) {
if time.Since(start) > duration {
t.Fatalf("failed to start yugabyte within %s", duration)
}
time.Sleep(time.Second)
time.Sleep(5 * time.Second)
}
}
6 changes: 4 additions & 2 deletions extern/boostd-data/svc/svc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ var testCouchSettings = couchbase.DBSettings{
}

var testYugaSettings = yugabyte.DBSettings{
Hosts: []string{"127.0.0.1"},
ConnectString: "postgresql://postgres:postgres@localhost",
//Hosts: []string{"127.0.0.1"},
Hosts: []string{"yugabyte"},
//ConnectString: "postgresql://postgres:postgres@localhost",
ConnectString: "postgresql://postgres:postgres@yugabyte:5433",
}

func TestService(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions piecedirectory/doctor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ func TestPieceDoctor(t *testing.T) {
svc.SetupYugabyte(t)

bdsvc := svc.NewYugabyte(yugabyte.DBSettings{
Hosts: []string{"127.0.0.1"},
ConnectString: "postgresql://postgres:postgres@localhost",
Hosts: []string{"yugabyte"},
ConnectString: "postgresql://postgres:postgres@yugabyte:5433",
})

addr := "localhost:8044"
Expand Down
4 changes: 2 additions & 2 deletions piecedirectory/piecedirectory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ func TestPieceDirectory(t *testing.T) {
svc.SetupYugabyte(t)

bdsvc := svc.NewYugabyte(yugabyte.DBSettings{
Hosts: []string{"127.0.0.1"},
ConnectString: "postgresql://postgres:postgres@localhost",
Hosts: []string{"yugabyte"},
ConnectString: "postgresql://postgres:postgres@yugabyte:5433",
})

addr := "localhost:8044"
Expand Down

0 comments on commit 20a7fc2

Please sign in to comment.