Skip to main content
Version: 2.x

Add a Service Container to a Job

Jobs that need a database can attach a service. options carries the raw docker create arguments, which is where the health check goes โ€” without one the job races the container and steps can start before it accepts connections:

import zio.Chunk
import zio.sbt.githubactions.{ImageRef, Service, ServicePort}

Job(
id = "test",
name = "Test",
services = Seq(
Service(
name = "postgres",
image = ImageRef("postgres:16"),
env = Map("POSTGRES_USER" -> "postgres", "POSTGRES_PASSWORD" -> "postgres"),
ports = Chunk(ServicePort(5432, 5432)),
options = Some("--health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5")
)
),
steps = ...
)

ServicePort(inner, outer) renders as inner:outer, which GitHub reads as <host>:<container> โ€” so inner is the port a step connects to on localhost.

ZIO Chat

Hi, fellow coder! ๐ŸŒŸ Welcome to your ZIO adventure with the ZIO Chat Bot. ๐Ÿš€ Let's master functional Scala together. From referential transparency to concurrent prowess, I've got your back. Ready to dive in? Your questions, my insights โ€“ let's conquer ZIO! ๐Ÿ’ก๐Ÿค–