Interview Prep/CI/CD/GitHub Actions

You need to run integration tests against Postgres and Redis inside a job.

BeginnerScenarioGitHub Actions
Answer

Situation read → Service containers.

What I'd do →

services:
  db:
    image: postgres:16
    env: { POSTGRES_PASSWORD: test }
    ports: ['5432:5432']
    options: >-
      --health-cmd "pg_isready -U postgres"
      --health-interval 5s --health-retries 10
  redis:
    image: redis:7
    ports: ['6379:6379']

Why → Health checks make the job wait until the service is ready, and services are destroyed after the job.

Interview tip → On the runner host use localhost:<mapped port>; inside a container job use the service name.

All CI/CD questions

More on GitHub Actions