Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf9e594f

Browse files
authored
ci: Run PostgreSQL with a scratch directory to improve CI durability (#89)
When using parallel before, multiple PostgreSQL containers wouldunintentionally interfere with the other's data. This ensuresboth containers have separated data, and don't create a volume.🌮@bryphe-coder for the idea!
1 parent2b922b1 commitf9e594f

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

‎.github/workflows/coder.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ jobs:
159159
run:
160160
DB=true gotestsum --jsonfile="gotests.json" --packages="./..." --
161161
-covermode=atomic -coverprofile="gotests.coverage" -timeout=3m
162-
-count=1 -race -parallel=1
162+
-count=1 -race -parallel=2
163163

164164
-uses:codecov/codecov-action@v2
165165
with:

‎database/postgres/postgres.go‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package postgres
33
import (
44
"database/sql"
55
"fmt"
6+
"io/ioutil"
7+
"os"
68
"time"
79

810
"github.com/ory/dockertest/v3"
@@ -16,15 +18,29 @@ func Open() (string, func(), error) {
1618
iferr!=nil {
1719
return"",nil,xerrors.Errorf("create pool: %w",err)
1820
}
21+
tempDir,err:=ioutil.TempDir(os.TempDir(),"postgres")
22+
iferr!=nil {
23+
return"",nil,xerrors.Errorf("create tempdir: %w",err)
24+
}
1925
resource,err:=pool.RunWithOptions(&dockertest.RunOptions{
2026
Repository:"postgres",
2127
Tag:"11",
2228
Env: []string{
2329
"POSTGRES_PASSWORD=postgres",
2430
"POSTGRES_USER=postgres",
2531
"POSTGRES_DB=postgres",
32+
// The location for temporary database files!
33+
"PGDATA=/tmp",
2634
"listen_addresses = '*'",
2735
},
36+
Mounts: []string{
37+
// The postgres image has a VOLUME parameter in it's image.
38+
// If we don't mount at this point, Docker will allocate a
39+
// volume for this directory.
40+
//
41+
// This isn't used anyways, since we override PGDATA.
42+
fmt.Sprintf("%s:/var/lib/postgresql/data",tempDir),
43+
},
2844
},func(config*docker.HostConfig) {
2945
// set AutoRemove to true so that stopped container goes away by itself
3046
config.AutoRemove=true
@@ -57,5 +73,6 @@ func Open() (string, func(), error) {
5773
}
5874
returndbURL,func() {
5975
_=pool.Purge(resource)
76+
_=os.RemoveAll(tempDir)
6077
},nil
6178
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp