mirror of
https://github.com/coder/coder.git
synced 2025-07-09 11:45:56 +00:00
ci: Run PostgreSQL with a scratch directory to improve CI durability (#89)
When using parallel before, multiple PostgreSQL containers would
unintentionally interfere with the other's data. This ensures
both containers have separated data, and don't create a volume.
🌮 @bryphe-coder for the idea!
This commit is contained in:
2
.github/workflows/coder.yaml
vendored
2
.github/workflows/coder.yaml
vendored
@ -159,7 +159,7 @@ jobs:
|
|||||||
run:
|
run:
|
||||||
DB=true gotestsum --jsonfile="gotests.json" --packages="./..." --
|
DB=true gotestsum --jsonfile="gotests.json" --packages="./..." --
|
||||||
-covermode=atomic -coverprofile="gotests.coverage" -timeout=3m
|
-covermode=atomic -coverprofile="gotests.coverage" -timeout=3m
|
||||||
-count=1 -race -parallel=1
|
-count=1 -race -parallel=2
|
||||||
|
|
||||||
- uses: codecov/codecov-action@v2
|
- uses: codecov/codecov-action@v2
|
||||||
with:
|
with:
|
||||||
|
@ -3,6 +3,8 @@ package postgres
|
|||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ory/dockertest/v3"
|
"github.com/ory/dockertest/v3"
|
||||||
@ -16,6 +18,10 @@ func Open() (string, func(), error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", nil, xerrors.Errorf("create pool: %w", err)
|
return "", nil, xerrors.Errorf("create pool: %w", err)
|
||||||
}
|
}
|
||||||
|
tempDir, err := ioutil.TempDir(os.TempDir(), "postgres")
|
||||||
|
if err != nil {
|
||||||
|
return "", nil, xerrors.Errorf("create tempdir: %w", err)
|
||||||
|
}
|
||||||
resource, err := pool.RunWithOptions(&dockertest.RunOptions{
|
resource, err := pool.RunWithOptions(&dockertest.RunOptions{
|
||||||
Repository: "postgres",
|
Repository: "postgres",
|
||||||
Tag: "11",
|
Tag: "11",
|
||||||
@ -23,8 +29,18 @@ func Open() (string, func(), error) {
|
|||||||
"POSTGRES_PASSWORD=postgres",
|
"POSTGRES_PASSWORD=postgres",
|
||||||
"POSTGRES_USER=postgres",
|
"POSTGRES_USER=postgres",
|
||||||
"POSTGRES_DB=postgres",
|
"POSTGRES_DB=postgres",
|
||||||
|
// The location for temporary database files!
|
||||||
|
"PGDATA=/tmp",
|
||||||
"listen_addresses = '*'",
|
"listen_addresses = '*'",
|
||||||
},
|
},
|
||||||
|
Mounts: []string{
|
||||||
|
// The postgres image has a VOLUME parameter in it's image.
|
||||||
|
// If we don't mount at this point, Docker will allocate a
|
||||||
|
// volume for this directory.
|
||||||
|
//
|
||||||
|
// This isn't used anyways, since we override PGDATA.
|
||||||
|
fmt.Sprintf("%s:/var/lib/postgresql/data", tempDir),
|
||||||
|
},
|
||||||
}, func(config *docker.HostConfig) {
|
}, func(config *docker.HostConfig) {
|
||||||
// set AutoRemove to true so that stopped container goes away by itself
|
// set AutoRemove to true so that stopped container goes away by itself
|
||||||
config.AutoRemove = true
|
config.AutoRemove = true
|
||||||
@ -57,5 +73,6 @@ func Open() (string, func(), error) {
|
|||||||
}
|
}
|
||||||
return dbURL, func() {
|
return dbURL, func() {
|
||||||
_ = pool.Purge(resource)
|
_ = pool.Purge(resource)
|
||||||
|
_ = os.RemoveAll(tempDir)
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user