PostgreSQL and graph databases with Apache AGE, time for an update
A quick update on how to use Apache AGE with Docker on your local machine.
It's been a while since I last posted about Apache AGE, and a lot of things happened since then. Let's have a look at the changes to the database itself and the developer experience.
What's new?
First of all, the project has now graduated from incubator to top-level Apache project, so you can expect it to have greater support from the Foundation, and less to worry about the possibility of it being abandoned anytime soon.
Second, the project now reached version 1.1, so it is now considered stable and usable for "serious projects". A lot of Open Source projects are considered to be production-ready way before reaching version 1.0, but you know, that little 1 in front of the version number is still something that can make you feel less anxious when relying on some tool for your project.
Getting started, with Docker, on an Apple Silicon Mac
When doing some experiments with a tool, be it an application or library, I usually prefer Docker instead of installing the tool directly on my Mac. This is just a way to keep my computer clean, and since I often need to have different versions of databases or other libraries inside my projects, so I prefer not to mess things up.
The official Docker image for Apache AGE is available on Docker Hub at the following link: https://hub.docker.com/r/apache/age.
If you have a look at the tags page, by the way, you can see that at the moment the images are all built for the AMD64 architecture. This doesn't mean that the application won't work on an Apple Silicon Mac, but that the performance is not the best possible, so as I did in my previous article, I'll show you how to build a custom image optimized for my machine.
Step 1: Clone the AGE repo locally
The first step to build the custom Docker image for my machine is to get a copy of the AGE repo locally, so let's clone it via git
git clone https://github.com/apache/age
The cloning process is quite fast since the repo is small, it just takes a few seconds depending on your Internet connection speed.
❯ git clone https://github.com/apache/age
Cloning into 'age'...
remote: Enumerating objects: 13026, done.
remote: Counting objects: 100% (1383/1383), done.
remote: Compressing objects: 100% (792/792), done.
remote: Total 13026 (delta 566), reused 1285 (delta 537), pack-reused 11643
Receiving objects: 100% (13026/13026), 36.17 MiB | 2.55 MiB/s, done.
Resolving deltas: 100% (4660/4660), done.
Now that we have a copy of the repo, let's move on to build the custom image.
Step 2: Build the Docker image
Inside the repo there's the official Dockerfile for Apache AGE, so let's see if we can build the image straight from it without any modification.
cd age
docker build -t apache/age .
The good news is that with the new release, the image builds correctly on Apple Silicon, without needing to edit the Dockerfile as I did in my previous post.
I now have my custom Apache AGE image built locally, let's try to run it to see if it works correctly.
Step 3: Run the locally built image
Now that the image is ready, let's run it to start playing with our graph database
docker run -it \
-e POSTGRES_USER=age \
-e POSTGRES_PASSWORD=developer \
-e POSTGRES_DB=age \
-p 5432:5432 \
--name 'age-playground' \
apache/age
In a couple of seconds, the instance starts correctly and PostgreSQL is ready to accept connections, so let's open our SQL editor and try to connect.
Next steps
Once the database is running you can connect and start playing with the SQL or graph part of it.
Please have a look at my previous article on Apache AGE for instructions on how to connect and create and query graphs.