Subdomain 1.2: Design and implement workflow structure
1.Your CI workflow runs integration tests that require a PostgreSQL database. You want to provide a clean database instance for each workflow run without manually managing infrastructure. How should you configure this in the workflow?
- A.Adding a service container for PostgreSQL
- B.Installing PostgreSQL on the runner
- C.Using an action from the marketplace
- D.Managing a Docker container manually
Show answer & explanation
Correct answer: A — Adding a service container for PostgreSQL
- A. Adding a service container for PostgreSQL in the workflow YAML allows GitHub Actions to automatically spin up a PostgreSQL instance as a sidecar. This provides a clean, isolated database for each workflow run without manual setup.
- B. Installing PostgreSQL on the runner requires manual setup and may leave residual data between runs. It does not leverage the ephemeral nature of runners and adds cleanup overhead.
- C. Marketplace actions can assist with setup, but they do not inherently provide a clean, isolated database instance. Service containers are the native and recommended method.
- D. Manually managing a Docker container requires you to handle the container lifecycle yourself, defeating automation. GitHub Actions service containers automate this process.