Skip to content

Commit d388272

Browse files
committed
feat: Fetch and load Postgresql and spin up as a SUT.
1 parent b5866c5 commit d388272

File tree

4 files changed

+66
-4
lines changed

4 files changed

+66
-4
lines changed

MODULE.bazel

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,15 @@ use_repo(pnpm, "pnpm")
4646

4747
bazel_dep(name = "bazel_skylib", version = "1.8.2")
4848
bazel_dep(name = "rules_itest", version = "0.0.41")
49+
bazel_dep(name = "platforms", version = "1.0.0")
50+
bazel_dep(name = "rules_img", version = "0.2.8")
51+
52+
pull = use_repo_rule("@rules_img//img:pull.bzl", "pull")
53+
54+
pull(
55+
name = "postgresql",
56+
digest = "sha256:48c8ad3a7284b82be4482a52076d47d879fd6fb084a1cbfccbd551f9331b0e40",
57+
registry = "index.docker.io",
58+
repository = "library/postgres",
59+
tag = "18.0-alpine3.22",
60+
)

MODULE.bazel.lock

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

db/BUILD.bazel

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
load("@rules_img//img:image.bzl", "image_manifest")
2+
load("@rules_img//img:load.bzl", "image_load")
3+
load("@rules_itest//:itest.bzl", "itest_service", "itest_task")
4+
5+
platform(
6+
name = "host_docker_platform",
7+
constraint_values = ["@platforms//os:linux"], # but linux OS inside Docker
8+
parents = ["@platforms//host"], # use host CPU
9+
)
10+
11+
image_manifest(
12+
name = "pg_image",
13+
base = "@postgresql",
14+
platform = ":host_docker_platform",
15+
)
16+
17+
image_load(
18+
name = "load_pg_image",
19+
image = ":pg_image",
20+
tag = "pg_image:latest",
21+
)
22+
23+
itest_task(
24+
name = "load_pg_image_task",
25+
testonly = True,
26+
exe = ":load_pg_image",
27+
)
28+
29+
itest_service(
30+
name = "sut",
31+
testonly = True,
32+
args = [
33+
"--name",
34+
"pg_image:latest",
35+
"--env=POSTGRES_USER,POSTGRES_PASSWORD,POSTGRES_DB",
36+
],
37+
env = {
38+
"POSTGRES_USER": "postgres",
39+
"POSTGRES_PASSWORD": "postgres",
40+
"POSTGRES_DB": "postgres",
41+
},
42+
exe = "//testing/itestcontainer:itestcontainer",
43+
named_ports = [
44+
"5432",
45+
],
46+
deps = [":load_pg_image_task"],
47+
)

testing/itestcontainer/itestcontainer.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"log"
2525
"os"
2626
"os/signal"
27+
"strings"
2728
"sync"
2829
"syscall"
2930

@@ -66,7 +67,7 @@ func main() {
6667
// Map the suffix of the named ports to exposed ports.
6768
exposedPorts := []string{}
6869
for portName, externalPort := range assignedPorts {
69-
parts := strings.Split(portname, ":")
70+
parts := strings.Split(portName, ":")
7071
exposedPortName := parts[len(parts)-1]
7172
exposedPorts = append(exposedPorts, externalPort+":"+exposedPortName)
7273
}
@@ -125,7 +126,7 @@ func main() {
125126
wg.Add(1)
126127
go func() {
127128
defer wg.Done()
128-
name := c.GetContainerId()
129+
name := c.GetContainerID()
129130
n, err := c.Inspect(ctx)
130131
if err != nil {
131132
name = n.Name

0 commit comments

Comments
 (0)