Codespaces

December 4, 2023 · View on GitHub

You can create a GitHub Codespace for pgec that has PostgreSQL and Prometheus setup with instructions from GitHub on creating a codespace. Some CLI convenience snippets follow.

Firstly, follow the GitHub CLI installation instructions for your OS.

Clone the pgec repository:

gh repo clone shortishly/pgec

Change directory to be within the repository:

cd pgec

Create a codespace for pgec:

./bin/codespace-create

Run a secure shell into the codespace, you may see Starting codespace while it is provisioned (which can take a while):

./bin/codespace-ssh

Running

Once in the codespace secure shell, you can check that PostgreSQL, Prometheus, Grafana and pgec are all running with:

./bin/ps

The services may still be provisioning after you have logged in. If you see:

@shortishly /workspaces/pgec (develop) $ ./bin/ps
SERVICE   IMAGE     STATUS

Wait a couple of minutes until:

@shortishly /workspaces/pgec (develop) $ ./bin/ps
SERVICE          IMAGE                             STATUS
db               postgres:16.1                     Up 5 minutes (healthly)
grafana          grafana/grafana:10.1.5            Up 5 minutes
load-generator   postgres:16.1                     Up 5 minutes
pgec             ghcr.io/shortishly/pgec:develop   Up 5 minutes
prometheus       prom/prometheus:v2.47.2           Up 5 minutes

To run the smoke tests against the example data:

@shortishly /workspaces/pgec (develop) $ bats test/bats

The service ports are published and forwarded by the codespace. In a terminal on your local machine you can look at the Grafana running remotely on the codespace with sample dashboards installed with:

./bin/codespace-grafana

Building

To build pgec, dialyze and run the unit tests:

make deps app dialyze eunit

To run the common tests against the PostgreSQL already running in the codespace:

make ct

To run an interactive Erlang/OTP shell with the pgec application running:

make shell

Once you are finished you can delete the codespace using:

gh codespace delete \
    --codespace $(gh codespace ls \
        --repo $(gh repo view \
            --json nameWithOwner \
            --jq .nameWithOwner) \
        --json name \
        --jq '.[].name')