GH-200 practice question 7 of 15

Without the need to use additional infrastructure, what is the simplest and most maintainable method for configuring a workflow job to provide access to an empty PostgreSQL database?

Full set: 100 questions
Answer options
A: Use service containers with a Postgres database from Docker hub. Correct answer
B: Run the actions/postgres action in a parallel job.
C: It is currently impossible to access the database with GitHub Actions.
D: Dynamically provision and deprovision an environment.
Correct Answer:
A. Use service containers with a Postgres database from Docker hub.
Explanation

The simplest and most maintainable method is to use service containers. This is a built-in feature of GitHub Actions that allows you to run additional Docker containers alongside your job's primary container on the same runner. These service containers can host databases, caches, or other dependencies. The workflow orchestrates the lifecycle of the service container, making it available on a shared network for the job's steps and then tearing it down automatically. This avoids the complexity and cost of managing external infrastructure.

Why Incorrect

B. Run the actions/postgres action in a parallel job: Jobs run in isolated environments by default and cannot easily share services like a database.
C. It is currently impossible to access the database with GitHub Actions: This is incorrect; service containers are a primary feature designed for this exact use case.
D. Dynamically provision and deprovision an environment: This requires external infrastructure (e.g., a cloud provider) and complex setup, violating the question's constraints.

References

GitHub Docs

"About service containers". This document explains

"Service containers are Docker containers that provide a simple and portable way for you to host services that you might need to test or operate your application in a workflow."

GitHub Docs

"Creating a PostgreSQL service container". This page provides a specific

documented example of how to configure a workflow job with a PostgreSQL service container

directly addressing the scenario in the question.

Scroll to Top