mirror of
https://github.com/neilotoole/sq.git
synced 2024-12-25 17:25:36 +03:00
Debugging magefile for sakila DB statup
This commit is contained in:
parent
240a493ad6
commit
d1d772c102
76
go.mod
76
go.mod
@ -1,6 +1,6 @@
|
||||
module github.com/neilotoole/sq
|
||||
|
||||
go 1.17
|
||||
go 1.19
|
||||
|
||||
// Using forked cobra for now because v1.1.3 does not pass Context
|
||||
// to valid args completion funcs. There's an open PR for
|
||||
@ -13,14 +13,14 @@ require (
|
||||
github.com/denisenkom/go-mssqldb v0.0.0-20200620013148-b91950f658ec
|
||||
github.com/djherbis/fscache v0.10.1
|
||||
github.com/emirpasic/gods v1.9.0
|
||||
github.com/fatih/color v1.9.0
|
||||
github.com/go-sql-driver/mysql v1.5.0
|
||||
github.com/google/uuid v1.1.1
|
||||
github.com/fatih/color v1.13.0
|
||||
github.com/go-sql-driver/mysql v1.6.0
|
||||
github.com/google/uuid v1.3.0
|
||||
github.com/h2non/filetype v1.1.0
|
||||
github.com/jackc/pgconn v1.5.0
|
||||
github.com/jackc/pgx/v4 v4.6.0
|
||||
github.com/magefile/mage v1.9.0
|
||||
github.com/mattn/go-colorable v0.1.4
|
||||
github.com/mattn/go-colorable v0.1.12
|
||||
github.com/mattn/go-isatty v0.0.14
|
||||
github.com/mattn/go-runewidth v0.0.4
|
||||
github.com/mattn/go-sqlite3 v2.0.3+incompatible
|
||||
@ -34,32 +34,35 @@ require (
|
||||
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24
|
||||
github.com/spf13/cobra v1.1.3
|
||||
github.com/spf13/pflag v1.0.5
|
||||
github.com/stretchr/testify v1.5.1
|
||||
github.com/stretchr/testify v1.8.1
|
||||
github.com/tealeg/xlsx/v2 v2.0.1
|
||||
github.com/testcontainers/testcontainers-go v0.5.0
|
||||
github.com/testcontainers/testcontainers-go v0.15.0
|
||||
github.com/xo/dburl v0.11.0
|
||||
go.uber.org/atomic v1.5.0
|
||||
go.uber.org/multierr v1.4.0
|
||||
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de
|
||||
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7
|
||||
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208
|
||||
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd
|
||||
golang.org/x/net v0.2.0
|
||||
golang.org/x/sync v0.1.0
|
||||
gopkg.in/yaml.v2 v2.4.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
|
||||
github.com/BurntSushi/toml v0.3.1 // indirect
|
||||
github.com/Microsoft/go-winio v0.4.11 // indirect
|
||||
github.com/Microsoft/hcsshim v0.8.6 // indirect
|
||||
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
|
||||
github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc // indirect
|
||||
github.com/Microsoft/go-winio v0.6.0 // indirect
|
||||
github.com/Microsoft/hcsshim v0.9.5 // indirect
|
||||
github.com/cenkalti/backoff/v4 v4.2.0 // indirect
|
||||
github.com/containerd/cgroups v1.0.4 // indirect
|
||||
github.com/containerd/containerd v1.6.10 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/docker/distribution v2.7.1-0.20190205005809-0d3efadf0154+incompatible // indirect
|
||||
github.com/docker/docker v0.7.3-0.20190506211059-b20a14b54661 // indirect
|
||||
github.com/docker/distribution v2.8.1+incompatible // indirect
|
||||
github.com/docker/docker v20.10.21+incompatible // indirect
|
||||
github.com/docker/go-connections v0.4.0 // indirect
|
||||
github.com/docker/go-units v0.3.3 // indirect
|
||||
github.com/gogo/protobuf v1.2.1 // indirect
|
||||
github.com/docker/go-units v0.5.0 // indirect
|
||||
github.com/gogo/protobuf v1.3.2 // indirect
|
||||
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe // indirect
|
||||
github.com/golang/protobuf v1.3.3 // indirect
|
||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
||||
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
|
||||
github.com/jackc/pgio v1.0.0 // indirect
|
||||
@ -67,24 +70,33 @@ require (
|
||||
github.com/jackc/pgproto3/v2 v2.0.1 // indirect
|
||||
github.com/jackc/pgservicefile v0.0.0-20200307190119-3430c5407db8 // indirect
|
||||
github.com/jackc/pgtype v1.3.0 // indirect
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
|
||||
github.com/kr/pretty v0.2.1 // indirect
|
||||
github.com/kr/text v0.2.0 // indirect
|
||||
github.com/opencontainers/go-digest v1.0.0-rc1 // indirect
|
||||
github.com/opencontainers/image-spec v1.0.1 // indirect
|
||||
github.com/opencontainers/runc v0.1.1 // indirect
|
||||
github.com/magiconair/properties v1.8.6 // indirect
|
||||
github.com/moby/sys/mount v0.3.3 // indirect
|
||||
github.com/moby/sys/mountinfo v0.6.2 // indirect
|
||||
github.com/moby/term v0.0.0-20221105221325-4eb28fa6025c // indirect
|
||||
github.com/morikuni/aec v1.0.0 // indirect
|
||||
github.com/opencontainers/go-digest v1.0.0 // indirect
|
||||
github.com/opencontainers/image-spec v1.1.0-rc2 // indirect
|
||||
github.com/opencontainers/runc v1.1.4 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/sirupsen/logrus v1.4.2 // indirect
|
||||
github.com/sirupsen/logrus v1.9.0 // indirect
|
||||
go.opencensus.io v0.24.0 // indirect
|
||||
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee // indirect
|
||||
go.uber.org/zap v1.13.0 // indirect
|
||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de // indirect
|
||||
golang.org/x/sys v0.0.0-20220808155132-1c4a2a72c664 // indirect
|
||||
golang.org/x/text v0.3.2 // indirect
|
||||
golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc // indirect
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 // indirect
|
||||
google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a // indirect
|
||||
google.golang.org/grpc v1.21.1 // indirect
|
||||
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
|
||||
golang.org/x/mod v0.7.0 // indirect
|
||||
golang.org/x/sys v0.2.0 // indirect
|
||||
golang.org/x/term v0.2.0 // indirect
|
||||
golang.org/x/text v0.4.0 // indirect
|
||||
golang.org/x/tools v0.3.0 // indirect
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
|
||||
google.golang.org/genproto v0.0.0-20221118155620-16455021b5e6 // indirect
|
||||
google.golang.org/grpc v1.51.0 // indirect
|
||||
google.golang.org/protobuf v1.28.1 // indirect
|
||||
gopkg.in/djherbis/atime.v1 v1.0.0 // indirect
|
||||
gopkg.in/djherbis/stream.v1 v1.3.1 // indirect
|
||||
honnef.co/go/tools v0.0.1-2019.2.3 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
honnef.co/go/tools v0.0.1-2020.1.3 // indirect
|
||||
)
|
||||
|
@ -23,67 +23,77 @@ type Sakila mg.Namespace
|
||||
|
||||
const startupTimeout = time.Minute * 5
|
||||
|
||||
// containers is the set of database server containers required for
|
||||
// containerReqs is the set of database server containers required for
|
||||
// integration testing.
|
||||
//
|
||||
// NOTE: The wait.ForLog mechanism is probably not fully correct for any of the
|
||||
//
|
||||
// containers (e.g. the string may appear multiple times in the log output),
|
||||
// thus the containers may not have started fully when WaitingFor completes.
|
||||
var containers = []testcontainers.ContainerRequest{
|
||||
var containerReqs = []testcontainers.ContainerRequest{
|
||||
{
|
||||
Image: "sakiladb/sqlserver:2017-CU19",
|
||||
Image: "sakiladb/sqlserver:2017",
|
||||
Name: "sakiladb-sqlserver-2017",
|
||||
ExposedPorts: []string{"14337:1433"},
|
||||
WaitingFor: wait.ForLog("Changed database context to 'sakila'.").WithStartupTimeout(startupTimeout),
|
||||
},
|
||||
{
|
||||
Image: "sakiladb/postgres:9",
|
||||
Name: "sakiladb-postgres-9",
|
||||
ExposedPorts: []string{"54329:5432"},
|
||||
WaitingFor: wait.ForLog("PostgreSQL init process complete; ready for start up.").WithStartupTimeout(startupTimeout),
|
||||
},
|
||||
{
|
||||
Image: "sakiladb/postgres:10",
|
||||
Name: "sakiladb-postgres-10",
|
||||
ExposedPorts: []string{"54330:5432"},
|
||||
WaitingFor: wait.ForLog("PostgreSQL init process complete; ready for start up.").WithStartupTimeout(startupTimeout),
|
||||
},
|
||||
{
|
||||
Image: "sakiladb/postgres:11",
|
||||
Name: "sakiladb-postgres-11",
|
||||
ExposedPorts: []string{"54331:5432"},
|
||||
WaitingFor: wait.ForLog("PostgreSQL init process complete; ready for start up.").WithStartupTimeout(startupTimeout),
|
||||
},
|
||||
{
|
||||
Image: "sakiladb/postgres:12",
|
||||
Name: "sakiladb-postgres-12",
|
||||
ExposedPorts: []string{"54332:5432"},
|
||||
WaitingFor: wait.ForLog("PostgreSQL init process complete; ready for start up.").WithStartupTimeout(startupTimeout),
|
||||
},
|
||||
{
|
||||
Image: "sakiladb/mysql:5.6",
|
||||
Name: "sakiladb-mysql-5.6",
|
||||
ExposedPorts: []string{"33066:3306"},
|
||||
WaitingFor: wait.ForLog("[Note] mysqld: ready for connections.").WithStartupTimeout(startupTimeout),
|
||||
},
|
||||
{
|
||||
Image: "sakiladb/mysql:5.7",
|
||||
Name: "sakiladb-mysql-5.7",
|
||||
ExposedPorts: []string{"33067:3306"},
|
||||
WaitingFor: wait.ForLog("[Note] mysqld: ready for connections.").WithStartupTimeout(startupTimeout),
|
||||
},
|
||||
{
|
||||
Image: "sakiladb/mysql:8",
|
||||
Name: "sakiladb-mysql-8",
|
||||
ExposedPorts: []string{"33068:3306"},
|
||||
WaitingFor: wait.ForLog("[Server] /usr/sbin/mysqld: ready for connections.").WithStartupTimeout(startupTimeout),
|
||||
},
|
||||
// {
|
||||
// Image: "sakiladb/postgres:9",
|
||||
// Name: "sakiladb-postgres-9",
|
||||
// ExposedPorts: []string{"54329:5432"},
|
||||
// WaitingFor: wait.ForLog("PostgreSQL init process complete; ready for start up.").WithStartupTimeout(startupTimeout),
|
||||
// },
|
||||
// {
|
||||
// Image: "sakiladb/postgres:10",
|
||||
// Name: "sakiladb-postgres-10",
|
||||
// ExposedPorts: []string{"54330:5432"},
|
||||
// WaitingFor: wait.ForLog("PostgreSQL init process complete; ready for start up.").WithStartupTimeout(startupTimeout),
|
||||
// },
|
||||
// {
|
||||
// Image: "sakiladb/postgres:11",
|
||||
// Name: "sakiladb-postgres-11",
|
||||
// ExposedPorts: []string{"54331:5432"},
|
||||
// WaitingFor: wait.ForLog("PostgreSQL init process complete; ready for start up.").WithStartupTimeout(startupTimeout),
|
||||
// },
|
||||
// {
|
||||
// Image: "sakiladb/postgres:12",
|
||||
// Name: "sakiladb-postgres-12",
|
||||
// ExposedPorts: []string{"54332:5432"},
|
||||
// WaitingFor: wait.ForLog("PostgreSQL init process complete; ready for start up.").WithStartupTimeout(startupTimeout),
|
||||
// },
|
||||
// {
|
||||
// Image: "sakiladb/mysql:5.6",
|
||||
// Name: "sakiladb-mysql-5.6",
|
||||
// ExposedPorts: []string{"33066:3306"},
|
||||
// WaitingFor: wait.ForLog("[Note] mysqld: ready for connections.").WithStartupTimeout(startupTimeout),
|
||||
// },
|
||||
// {
|
||||
// Image: "sakiladb/mysql:5.7",
|
||||
// Name: "sakiladb-mysql-5.7",
|
||||
// ExposedPorts: []string{"33067:3306"},
|
||||
// WaitingFor: wait.ForLog("[Note] mysqld: ready for connections.").WithStartupTimeout(startupTimeout),
|
||||
// },
|
||||
// {
|
||||
// Image: "sakiladb/mysql:8",
|
||||
// Name: "sakiladb-mysql-8",
|
||||
// ExposedPorts: []string{"33068:3306"},
|
||||
// WaitingFor: wait.ForLog("[Server] /usr/sbin/mysqld: ready for connections.").WithStartupTimeout(startupTimeout),
|
||||
// },
|
||||
}
|
||||
|
||||
var startedContainers []testcontainers.Container
|
||||
var startedContainersMu sync.Mutex
|
||||
|
||||
func containerStarted(cont testcontainers.Container) {
|
||||
startedContainersMu.Lock()
|
||||
defer startedContainersMu.Unlock()
|
||||
|
||||
startedContainers = append(startedContainers, cont)
|
||||
}
|
||||
|
||||
// StartAll starts all the sakila database server containers locally.
|
||||
// Use RemoveAll to stop & remove the containers.
|
||||
func (Sakila) StartAll() error {
|
||||
func (Sakila) StartAll(ctx context.Context) error {
|
||||
const envarInfo = `export SQ_TEST_SRC__SAKILA_MY56=localhost:33066
|
||||
export SQ_TEST_SRC__SAKILA_MY57=localhost:33067
|
||||
export SQ_TEST_SRC__SAKILA_MY8=localhost:33068
|
||||
@ -96,26 +106,28 @@ export SQ_TEST_SRC__SAKILA_MS17=localhost:14337`
|
||||
fmt.Println("Starting all containers...")
|
||||
fmt.Printf("'src' the following:\n===\n%s\n===\n\n", envarInfo)
|
||||
|
||||
errGroup, ctx := errgroup.WithContext(context.Background())
|
||||
errGroup, ctx := errgroup.WithContext(ctx)
|
||||
|
||||
for _, container := range containers {
|
||||
container := container
|
||||
for _, containerReq := range containerReqs {
|
||||
containerReq := containerReq
|
||||
// The user invokes mage sakila:RemoveAll to remove all the containers.
|
||||
container.SkipReaper = true
|
||||
containerReq.SkipReaper = true
|
||||
|
||||
errGroup.Go(func() error {
|
||||
fmt.Printf("Starting container %s for %s\n", container.Name, container.Image)
|
||||
fmt.Printf("Starting container %s for %s\n", containerReq.Name, containerReq.Image)
|
||||
|
||||
_, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
|
||||
ContainerRequest: container,
|
||||
gotContainer, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
|
||||
ContainerRequest: containerReq,
|
||||
Started: true,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("image %s: %w", container.Image, err)
|
||||
return fmt.Errorf("image %s: %w", containerReq.Image, err)
|
||||
}
|
||||
|
||||
fmt.Printf("SUCCESS: started container %s for %s\n", container.Name, container.Image)
|
||||
containerStarted(gotContainer)
|
||||
|
||||
fmt.Printf("SUCCESS: started container %s for %s\n", containerReq.Name, containerReq.Image)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@ -132,16 +144,16 @@ export SQ_TEST_SRC__SAKILA_MS17=localhost:14337`
|
||||
}
|
||||
|
||||
// RemoveAll removes all the Sakila docker containers.
|
||||
func (Sakila) RemoveAll() {
|
||||
func (Sakila) RemoveAll(ctx context.Context) {
|
||||
wg := &sync.WaitGroup{}
|
||||
wg.Add(len(containers))
|
||||
for _, container := range containers {
|
||||
container := container
|
||||
wg.Add(len(containerReqs))
|
||||
for _, containerReq := range containerReqs {
|
||||
containerReq := containerReq
|
||||
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
// We don't care if there's an error
|
||||
_ = execDocker("rm", "-f", container.Name)
|
||||
_ = execDocker("rm", "-f", containerReq.Name)
|
||||
}()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user