Skip to content

Commit

Permalink
feat(postgresql): Add initial docs builders for postgresql
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenj committed Dec 13, 2023
1 parent ae3af0c commit 5de764f
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 2 deletions.
42 changes: 40 additions & 2 deletions earthly/postgresql/Earthfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Common PostgreSQL Earthly builders
VERSION --global-cache 0.7

# cspell: words colordiff nushell
# cspell: words colordiff nushell psycopg dbviz

postgres-base:
FROM postgres:16.0-alpine3.18
Expand All @@ -17,7 +17,9 @@ postgres-base:
musl-dev \
curl \
gcc \
py3-pip
py3-pip \
py3-rich \
py3-psycopg

# Install SQLFluff
RUN pip3 install sqlfluff==2.3.5
Expand All @@ -26,6 +28,10 @@ postgres-base:
# Get refinery
COPY ../rust+rust-base/refinery /bin

# Get dbviz
COPY ../../utilities/dbviz+build/dbviz /bin
RUN dbviz --help

# Get nushell
COPY ../../utilities/nushell+nushell-build/nu /bin

Expand All @@ -36,6 +42,7 @@ postgres-base:
COPY --dir scripts /scripts
# Copy our common scripts so we can use them inside the container.
DO ../../utilities/scripts+ADD_BASH_SCRIPTS
DO ../../utilities/scripts+ADD_PYTHON_SCRIPTS

SAVE ARTIFACT /scripts /scripts

Expand All @@ -62,6 +69,37 @@ BUILDER:
COPY --dir $seed .
COPY --dir $refinery_toml .

# DOCS - UDC to build the docs, needs to be run INSIDE the BUILDER like so:
#
# 1. Create a ./docs/diagrams.json which has the options needed to run to generate the docs to /docs
# 2. Define the following targets in your earthfile
#
# builder:
# DO github.com/input-output-hk/catalyst-ci/earthly/postgresql:<ver>+BUILDER --sqlfluff_cfg=./../../+repo-config/repo/.sqlfluff
#
# build:
# FROM +builder
#
# DO github.com/input-output-hk/catalyst-ci/earthly/postgresql:<ver>+BUILD --image_name=<name>
# DO github.com/input-output-hk/catalyst-ci/earthly/postgresql:<ver>+DOCS
DOCS:
COMMAND

ARG diagrams=./diagrams.json
ARG migrations=./migrations
ARG refinery_toml=./refinery.toml

USER postgres:postgres
WORKDIR /docs

COPY $diagrams ./diagrams.json
COPY --dir $migrations .
COPY --dir $refinery_toml .

RUN /scripts/std_docs.py ./diagrams.json



# Linter checks for sql files
CHECK:
COMMAND
Expand Down
1 change: 1 addition & 0 deletions earthly/postgresql/scripts/python
45 changes: 45 additions & 0 deletions earthly/postgresql/scripts/std_docs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env python3

import python.cli as cli
import python.db_ops as db_ops
import argparse
import rich

def main():
# Force color output in CI
rich.reconfigure(color_system='256')

parser = argparse.ArgumentParser(description='Standard Postgresql Documentation Processing.')
parser.add_argument('container_name', help='Name of the container')
parser.add_argument('--verbose', action='store_true', help='Enable verbose output')
db_ops.add_args(parser)

args = parser.parse_args()

db = db_ops.DBOps(args)

results = cli.Results("Generate Database Documentation")

# Init the DB.
res = db.init_database()
results.add(res)

if res.ok():
db.start()
res = db.wait_ready(timeout=10)
results.add(res)

if res.ok():
res = db.setup()
results.add(res)

if res.ok():
res = db.migrate_schema()
results.add(res)


results.print()


if __name__ == '__main__':
main()
1 change: 1 addition & 0 deletions examples/postgresql/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ build:
FROM +builder

DO ./../../earthly/postgresql+BUILD --image_name=example-db
DO ./../../earthly/postgresql+DOCS

# Internal: common integration test image
all-tests:
Expand Down
Empty file.

0 comments on commit 5de764f

Please sign in to comment.