VOOZH about

URL: https://thenewstack.io/how-to-use-databases-inside-github-actions/

⇱ How to Use Databases Inside GitHub Actions - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2023-11-09 09:40:42
How to Use Databases Inside GitHub Actions
sponsor-oracle,sponsored-post-contributed,
CI/CD / Data / Software Development

How to Use Databases Inside GitHub Actions

A look at spinning up databases GitHub Actions services, yet they can also be created manually or via the many third-party actions on the marketplace.
Nov 9th, 2023 9:40am by Gerald Venzl
👁 Featued image for: How to Use Databases Inside GitHub Actions
Image from Feel good studio on Shutterstock.
Oracle sponsored this post.

GitHub Actions is a platform that automates the build, test and deployment pipeline of your GitHub projects. Since its introduction, GitHub Actions has been steadily gaining popularity among developers. Not only do GitHub Actions help automate the test and integration cycles, but it can also drastically shorten them, accelerating developer feedback as part of the process.

GitHub Actions are defined as part of your GitHub project repository and automatically triggered on specific events, such as a pull request or push to the repo. As the name suggests, GitHub will run various “actions” as part of the execution. One significant benefit of GitHub Actions is that there are predefined actions from GitHub and an entire marketplace of third-party GitHub Actions that can be used, allowing developers to write their own and share them with the world. For an overview of commonly used GitHub Actions, check out “8 GitHub Actions for Setting Up Your CI/CD Pipelines.” For more of a tutorial on how to build your first GitHub Actions pipeline yourself, you may want to check out “Building a To-Do App using GitHub Actions, Playwright, Next.js.”

Oracle offers a wide range of technologies for building, testing, and maintaining applications in the cloud and in your data center. Find free tools and learning resources at oracle.com/developer
Learn More
The latest from Oracle

GitHub Actions and Databases

Using GitHub Action Services

When it comes to using databases inside your GitHub Actions (GHA), service containers can be used to spin up one or more “services” that will then be available for the particular job.

👁 Image

While services are great for getting a database or similar resource up and running, there are a couple of things that need to be kept in mind:

  • The container runtime cannot be chosen, but defaults to Docker. That in itself may not be a big deal but it’s still something to be aware of.
  • None of the GHA service container examples as of today show how to use a volume. Although persistency of the database is usually not required during or across multiple GHA runs, many database container images do provide additional functionality exposed via a volume, such as running initial data model setup scripts automatically, for example.
  • Even though health check options have been provided to the container runtime `(–health-interval 10s; –health-retries 10; …)`, GitHub adds its own health check delays on top of that, unnecessarily delaying the overall pipeline execution:

👁 Image

GitHub Action services’ implicit delay for checking whether the service is ready.

Manually Running Your Database Container

Of course, given that GHA allows you to run anything on the command line shell directly, there is practically no limit to what you can do yourself. That includes starting your own container if you wish to do so.

👁 Image

There are a couple of things to note here:

  1. The new container is started using Podman instead of Docker
  2. A volume is attached to the container via `-v ./datamodel:/container-entrypoint-initdb.d`. This particular database image provides a setup mechanism as part of the container startup. Once the database has been brought up inside the container, the container then automatically executes any scripts present in `/container-entrypoint-initdb.d`. This example uses this mechanism to initialize a data model. As you can see in the GHA definition above as a last step, the SQLcl command line prompt no longer selects a string literal `Hey there!` but instead selects `country_code, official_name, population` from the `countries` table inside the database where the country name happens to be `Austria`.
    A side note here, note the leading `./` in front of `datamodel`. It is paramount to specify a relative or absolute filesystem path. If you omit the `./`, the container runtime will automatically create an (empty) named volume called `datamodel`, instead of mounting the local `datamodel` folder. You can exchange the `./` for `$PWD` or `${{ github.workspace }}` for better readability, if you like.
  3. Instead of relying on the GHA health check, the script checks every 1 second (indicated by `sleep 1` in the script) whether the container is ready for use. This can be quite important for your overall job execution duration. Remember above where we saw that GitHub Actions automatically added more and more delay for checking the health of the container, the last one being a 32-second delay? What would happen if the database came up just 2 seconds after the delay? Well, nothing at all, the execution would be waiting another 30 seconds before checking the container readiness again. Here, however, there is not such a long delay, at a maximum the job will incur a delay of just 1 additional second. This is not to be underestimated; the difference in overall execution time can be quite significant.
👁 Image

Starting a container manually via the command line shell.

👁 Image

Difference in run duration between manual container creation (database-manual) and GitHub Actions service (database-via-gha-service)

Using a GitHub Action

As mentioned earlier, GitHub has a marketplace where any third-party developer can publish their own GitHub Actions. You will find several actions also for databases, including the Oracle Database that we have used so far. The action is called setup-oracle-free and wraps around the same container image that we have used before.

The action provides the best of both worlds: simple and succinct syntax to spin up a container, but without having to cut back on the functionality provided by the container. Using the action, the same steps as above can be accomplished with just this:

👁 Image

👁 Image

Output of GitHub Actions run with third-party `setup-oracle-free` action.

Using GitHub Actions Secrets

Any post on GitHub Actions that showcases the use of credentials or otherwise sensitive information should never be completed without talking about GitHub Actions secrets. The previous GHA jobs all had one thing in common: They used a hardcoded username and password for the database user, in both cases `test`. That’s maybe OK for quick-and-dirty construction of your pipeline but you should never, ever use a plain username/password or any other sensitive information (access tokens, etc.) as part of your GitHub Actions definition, as, remember, the GitHub Actions definition itself is part of the repository and readable to anyone.

For that reason, GitHub introduced the concept of secrets, which are read-only, encrypted variables in the repository that can only be read by GHA if you explicitly include the secret in a workflow. The important part here is that secrets are defined inside the settings of a GitHub repository and hence not available to anybody but only users with admin rights. Furthermore, once set, the secret can never, ever be seen again. If you want to change it or have a typo, you must update the secret with a new value that then again will be invisible going forward.

To add one or more secrets to your GitHub.com repository, head to SettingsSecuritySecrets and variablesActions. There, click on New repository secret.

👁 Image

Enter a name with which you will reference the secret later on and the secret value itself. Note: This is the only time you will see the secret value, once you hit Add secret, it will no longer be readable to you.

👁 Image

👁 Image

Once the secrets are created, in this case, one for the application user (`APP_USER`) and one for the application user password (`APP_USER_PASSWORD`), they can be referenced inside GHA jobs using `${{ secrets.<SECRET NAME> }}`, where `<SECRET NAME>` is the name of the secret that should be used:

👁 Image

👁 Image

GitHub Actions run with GitHub Action secrets instead of hard-coded username and password.

Notice how the SQLcl CLI invocation no longer shows `${{ secrets.APP_USER }}/${{ secrets.APP_USER_PASSWORD }}@localhost/FREEPDB1` as defined in the action’s definition itself, but instead `***/***@localhost/FREEPDB1`. This is done by GitHub Actions automatically so that the values of secrets are not leaked into the GitHub Actions run logs.

Conclusion

GitHub Actions is a powerful platform to arm your GitHub projects with their own CI/CD pipelines. Spinning up databases inside GitHub Actions is officially documented via GitHub Actions services, yet they can also be created either manually or via the many third-party actions on the marketplace.

Oracle offers a wide range of technologies for building, testing, and maintaining applications in the cloud and in your data center. Find free tools and learning resources at oracle.com/developer
Learn More
The latest from Oracle
TRENDING STORIES
Gerald Venzl has worked as a developer, DBA, performance engineer, software architect, consultant and enterprise architect. He is still active as a developer in his free time and on open source projects. Gerald is currently VP, developer initiatives, Oracle Database.
Read more from Gerald Venzl
Oracle sponsored this post.
SHARE THIS STORY
TRENDING STORIES
TNS owner Insight Partners is an investor in: Pragma, Docker.
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.