Skip to content

Commit da59921

Browse files
authored
fix(postgresql): various fixes/improvements related to using the postgres builders in catalyst voices. (#108)
* fix(postgresql): Not permitted to push images to a registry in the build step. * fix(postgresql): Remove necessity to manually build the sqlfluff-image when locally formatting sql. * fix(postgresql): Don't overwrite .sqlfluff file if it is provided already. * fix(postgresql): Globally disable `format` as its corrupting file ownership * fix(postgresql): Test if behavior changed from v2.3.2 and 2.3.5 * fix(postgresql): Fix sqlfluff version back to latest after lint discrepancy found * feat(postgresql): Add utility we need to generate postgresql schema diagrams * fix(postgresql): fix format of dbviz code * feat(bash): Add a bash duplicate and lint checker, as we are starting to accumulate a lot of bash scripts. * docs(bash): fix spelling errors * fix(docs): Fix script includes copy path * fix(postgresql): check the schema applies cleanly during the build, so that containers won't be created if they don't. * fix(postgresql): We probably don't want to dump the password to logs. * feat(postgresql): Add new file of bash functions to do the various steps we execute on the database. * feat(bash): add bash utility function to make handling parameters easier. * feat(postgresql): Build now ensures the schema can apply cleanly, and that all seed data is valid, * refactor(postgresql): Move seed ata from data to seed directory in the example * fix(bash): Fix bash scripts finding relative references (as good as bash can) * feat(bash): Add bash format checks * fix(bash): Fix bash script formatting * fix(bash): Fix bash format check not running on correct src * fix(bash): Fix spelling in bash files * fix(postgresql): Fix global .sql linting in the CI repo * fix(bash): Fix sourced bash script references because bash is unreliable at importing with relative references. * refactor(postgresql): Rework how postgresql integration tests could work in the example * fix(cat-ci): Add --global-cache option to cat-ci to improve cache locality and hits across multiple earthfiles * fix(rust): Don't build nushell in the rust builder * feat(postgresql): Add nushell to postgres integration test container * feat(postgresql): Refactored sql builders and nushell utility * Add dbviz artifacts for postgres builder to use * feat(postgresql): Add python scripting for the postgres builders * fix(cat-ci): Ignore python cruft * feat(postgresql): Add initial docs builders for postgresql * fix(bash): Fix bash linter to be multi-check target compliant * feat(postgresql): First auto postgres db docs building running * fix(bash): Fix shell format errors that exist in master * fix(bash): bash lint issues * fix(postgresql): Use latest rust configs for dbviz * fix(postgresql): update cargo.toml for dbviz * docs(postgresql): Try and add generated docs for the postgres example, to our example docs * fix(docs): Put postgres docs in the correct place and include the markdown file. * fix(postgresql): Migrations need to use the user role, not super user. * fix(postgresql): Use the correct role when generating db diagrams * fix(docs): Seems graphviz needs fonts installed to generate svg reliably * fix(postgresql): Make sure schema definitions in docs don;t accumulate * fix(docs): spelling correction * fix(docs): Fix included tables in autogenerated diagrams * fix(postgresql): can not pass targets as arguments, because the target is relative to cat-ci not the caller. * fix(postgresql): Allow lines up to 120 chars, 80 is a bit short * fix(postgresql): allow functions to be used by the normal user * fix(postgresql): try to grant function privileges again * fix(docs): dbdocs set comments to empty string if no comments to show. * fix(docs): dbdocs generation failure needs to result in an error * docs(postgresql): test * docs(postgresql): make docs results check for any error properly * docs(postgresql): Fix finding the optional create table syntax plus add some debug logic * docs(postgresql): make comments optional at sub diagram level, and add debug logic * docs(postgresql): more debug * docs(postgresql): only print debug if match found * docs(postgresql): more debug * docs(postgresql): more debug * docs(postgresql): Make type of match capture * fix(docs): fixed diagram option reading, remove debug code * docs(postgresql): debug docs that dont generate * fix(docs): Fix removing excluded tables from includes * docs(postgresql): Includes/excludes lists still not calculated correctly * docs(postgresql): Make sure we auto include tables defined in a migration * docs(postgresql): fix excluded tables calculation * docs(postgresql): cleanup title generation * docs(postgresql): add debug to include generation * docs(postgresql): need schema wide exclude to generate include list properly * docs(postgresql): specify option flag multiple times when needed * fix(docs): missing comma * docs(postgresql): still fixing the include/exclude formatting * fix(docs): misnamed Readme.md * docs(postgresql): Fix comment embedding option for migration diagrams * fix(postgresql): Can't cleanup data when applying seed data during build * fix(postgresql): lint issues * fix(postgresql): dropping database between seed data tests * docs(bash): Remove duplicated comment * fix(cspell): Fix typo * docs(postgresql): doc cleanups * chore(rust): Match rust cargo config
1 parent 2cd566a commit da59921

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+5068
-455
lines changed

.config/dictionaries/project.dic

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Earthfiles
1111
errchkjson
1212
extldflags
1313
fontawesome
14+
fontconfig
1415
ginkgolinter
1516
gitops
1617
glightbox

.editorconfig

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[*.sh]
2+
# like -i=4
3+
indent_style = space
4+
indent_size = 4
5+
6+
# --language-variant
7+
shell_variant = bash
8+
binary_next_line = true
9+
# --case-indent
10+
switch_case_indent = true
11+
space_redirects = true
12+
keep_padding = false
13+
# --func-next-line
14+
function_next_line = false

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@ node_modules
1717
/earthly/docs/local
1818

1919
# Local Build Artefacts
20-
target/
20+
target/
21+
22+
# Python junk
23+
**/*.pyc

earthly/postgresql/.sqlfluff renamed to .sqlfluff

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[sqlfluff]
44
dialect = postgres
55
large_file_skip_char_limit = 0
6+
max_line_length = 120
67

78
[sqlfluff:indentation]
89
tab_space_size = 2

Earthfile

+19-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Set the Earthly version to 0.7
2-
VERSION 0.7
3-
FROM debian:stable-slim
2+
VERSION --global-cache 0.7
43

54
# cspell: words livedocs sitedocs
65

@@ -18,6 +17,13 @@ markdown-check-fix:
1817
check-spelling:
1918
DO ./earthly/cspell+CHECK
2019

20+
# check-bash - test all bash files lint properly according to shellcheck.
21+
check-bash:
22+
FROM alpine:3.18
23+
24+
DO ./earthly/bash+SHELLCHECK --src=.
25+
26+
2127
## -----------------------------------------------------------------------------
2228
##
2329
## Standard CI targets.
@@ -28,14 +34,24 @@ check-spelling:
2834
check:
2935
BUILD +check-spelling
3036
BUILD +check-markdown
37+
BUILD +check-bash
3138

39+
# Internal: Reference to our repo root documentation used by docs builder.
3240
repo-docs:
3341
# Create artifacts of extra files we embed inside the documentation when its built.
3442
FROM scratch
3543
#FROM alpine:3.18
3644

3745
WORKDIR /repo
3846
COPY --dir *.md LICENSE-APACHE LICENSE-MIT .
39-
#RUN ls -al /repo
47+
48+
SAVE ARTIFACT /repo repo
49+
50+
repo-config:
51+
# Create artifacts of config file we need to refer to in builders.
52+
FROM scratch
53+
54+
WORKDIR /repo
55+
COPY --dir .sqlfluff .
4056

4157
SAVE ARTIFACT /repo repo

actions/configure-runner/Earthfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION 0.7
1+
VERSION --global-cache 0.7
22

33
deps:
44
FROM node:20-bookworm

actions/discover/Earthfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION 0.7
1+
VERSION --global-cache 0.7
22

33
deps:
44
FROM node:20-bookworm

actions/install/Earthfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION 0.7
1+
VERSION --global-cache 0.7
22

33
deps:
44
FROM node:20-bookworm

actions/merge/Earthfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION 0.7
1+
VERSION --global-cache 0.7
22

33
deps:
44
FROM node:20-bookworm

actions/push/Earthfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION 0.7
1+
VERSION --global-cache 0.7
22

33
deps:
44
FROM node:20-bookworm

actions/run/Earthfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION 0.7
1+
VERSION --global-cache 0.7
22

33
deps:
44
FROM node:20-bookworm

cli/Earthfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION 0.7
1+
VERSION --global-cache 0.7
22
FROM golang:1.20-alpine3.18
33

44
# cspell: words onsi ldflags extldflags

docs/Earthfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION 0.7
1+
VERSION --global-cache 0.7
22

33
# Copy all the source we need to build the docs
44
src:
@@ -8,6 +8,8 @@ src:
88
# Now copy into that any artifacts we pull from the builds.
99
COPY --dir ../+repo-docs/repo includes
1010

11+
# Copy docs we build in the postgres example.
12+
COPY --dir ../examples/postgresql+build/docs src/appendix/examples/built_docs/postgresql
1113

1214
# Build the docs here.
1315
docs:

docs/src/appendix/earthly.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Like a `Dockerfile`, only a single `Earthfile` can exist per directory and it *m
7575
#### Sample Structure
7676

7777
```Earthfile
78-
VERSION 0.7 # This defines the "schema" that this Earthfile satisfies, much like the version of a Docker Compose file
78+
VERSION --global-cache 0.7 # This defines the "schema version" that this Earthfile satisfies
7979
8080
# A target, which is functionally equivalent to a `makefile` target.
8181
deps:
@@ -104,7 +104,7 @@ A target can be thought of as a grouping of image layers, similar to the way mul
104104
Each target then specifies one or more commands that create the image layers associated with that target.
105105

106106
```Earthfile
107-
VERSION 0.7
107+
VERSION --global-cache 0.7
108108
109109
deps:
110110
FROM golang:1.20-alpine3.18

docs/src/guides/docs.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ This folder already has an `Earthfile` in it, which contains all build process.
3939
<!-- markdownlint-enable max-one-sentence-per-line -->
4040

4141
```Earthfile
42-
VERSION 0.7
42+
VERSION --global-cache 0.7
4343
4444
# Copy all the source we need to build the docs
4545
src:

docs/src/guides/languages/bash.md

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
---
2+
icon: material/bash
3+
title: Bash Scripts
4+
tags:
5+
- Bash
6+
---
7+
8+
<!-- markdownlint-disable single-h1 -->
9+
# :material-bash: Bash Scripts
10+
<!-- markdownlint-enable single-h1 -->
11+
12+
## Introduction
13+
14+
<!-- markdownlint-disable max-one-sentence-per-line -->
15+
!!! Tip
16+
If you're just looking for a complete example,
17+
[click here](https://github.com/input-output-hk/catalyst-ci/blob/master/Earthfile).
18+
This guide will provide detailed instructions for how the example was built.
19+
<!-- markdownlint-enable max-one-sentence-per-line -->
20+
21+
This guide will get you started with using the Catalyst CI to build projects that include Bash scripts.
22+
By the end of the guide, we'll have an `Earthfile` that utilizes the Catalyst CI that can check your Bash scripts.
23+
24+
Bash is not considered a stand alone target, although bash scripts are used extensively across multiple targets.
25+
The Bash support consists solely of a single repo wide `check` target which validates:
26+
27+
* Are any of the `bash` shell scripts redundant.
28+
* This prevent maintenance issues where common scripts are copy/pasted rather than being properly organized.
29+
* Do the bash scripts pass `shellcheck` lints.
30+
* This forces us to follow a consistent style guide, and also checks for problematic Bash syntax.
31+
32+
To begin, clone the Catalyst CI repository:
33+
34+
## Adding Bash checks to your Repo that is already using Catalyst-CI
35+
36+
Bash script checking is to be added to a repo that is already using Catalyst CI.
37+
38+
All that needs to happen is the following be added to the `Earthfile` in the root of the repo.
39+
40+
```Earthfile
41+
# Internal: shell-check - test all bash files against our shell check rules.
42+
shell-check:
43+
FROM alpine:3.18
44+
45+
DO github.com/input-output-hk/catalyst-ci/earthly/bash:vx.y.z+SHELLCHECK --src=.
46+
47+
# check all repo wide checks are run from here
48+
check:
49+
FROM alpine:3.18
50+
51+
# Lint all bash files.
52+
BUILD +shell-check
53+
54+
```
55+
56+
<!-- markdownlint-disable max-one-sentence-per-line -->
57+
!!! Note
58+
It is expected that there may be multiple repo level `checks`.
59+
This pattern shown above allows for this by separating the individual checks into their own targets.
60+
The `check` target then just executed `BUILD` once for each check.
61+
<!-- markdownlint-enable max-one-sentence-per-line -->
62+
63+
### Common Scripts
64+
65+
It is not a good practice to copy bash scripts with common functionality.
66+
Accordingly, the *Utility* target `./utilities/scripts+bash-scripts` exists to provide a central location for common scripts.
67+
These are used locally to this repo and may be used by other repos using catalyst-ci.
68+
69+
These scripts are intended to be used inside Earthly builds, and not locally.
70+
71+
A common pattern to include these common scripts is the following:
72+
73+
```Earthfile
74+
# Copy our target specific scripts
75+
COPY --dir scripts /scripts
76+
77+
# Copy our common scripts so we can use them inside the container.
78+
DO ../../utilities/scripts+ADD_BASH_SCRIPTS
79+
```
80+
81+
<!-- markdownlint-disable max-one-sentence-per-line -->
82+
!!! Note
83+
Always source scripts using `source "/scripts/include/something.sh"`.
84+
This will ensure the scripts are properly located.
85+
bash has no concept of the directory a script is located and so relative
86+
source commands are unreliable.
87+
<!-- markdownlint-enable max-one-sentence-per-line -->
88+
89+
<!-- markdownlint-disable max-one-sentence-per-line -->
90+
!!! Note
91+
This is just an example, and you would adapt it to your specific requirements.
92+
<!-- markdownlint-enable max-one-sentence-per-line -->
93+
94+
### Running checks
95+
96+
From the root of the repo, you can check all bash scripts within the repo by running:
97+
98+
```sh
99+
earthly +check
100+
```
101+
102+
This will also run all other repo-wide checks that are in use.
103+
104+
### Build and test
105+
106+
Bash scripts should not have a `build` target.
107+
They can form part of the Build of other targets.
108+
109+
### Releasing
110+
111+
Bash scripts should not have a discreet `release` target.
112+
They can form part of the `release` of other targets.
113+
114+
### Publishing
115+
116+
Bash scripts should not have a discreet `publish` target.
117+
They can form part of the `publish` of other targets.
118+
119+
## Conclusion
120+
121+
You can see the final `Earthfile` [here](https://github.com/input-output-hk/catalyst-ci/blob/master/Earthfile).
122+
123+
This `Earthfile` will check the quality of the Bash files within the Catalyst-CI repo.

docs/src/guides/languages/go.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ You can choose to either delete the file and start from scratch, or read the gui
4646
### Installing dependencies
4747

4848
```Earthfile
49-
VERSION 0.7
49+
VERSION --global-cache 0.7
5050
5151
deps:
5252
# This target is used to install external Go dependencies.

docs/src/guides/languages/postgresql.md

+6-7
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ You can choose to either delete the file and start from scratch, or read the gui
4949
### Prepare base builder
5050

5151
```Earthfile
52-
VERSION 0.7
52+
VERSION --global-cache 0.7
5353
5454
builder:
5555
FROM ./../../earthly/postgresql+postgres-base
@@ -75,9 +75,14 @@ check:
7575
7676
DO ./../../earthly/postgresql+CHECK
7777
78+
build-sqlfluff:
79+
BUILD ./../../earthly/postgresql+sqlfluff-image
80+
7881
format:
7982
LOCALLY
8083
84+
RUN earthly +build-sqlfluff
85+
8186
DO ./../../earthly/postgresql+FORMAT --src=$(echo ${PWD})
8287
```
8388

@@ -86,12 +91,6 @@ At this step we can begin performing static checks against `*.sql` files.
8691
These checks are intended to verify the code is healthy and well formatted to a certain standard
8792
and done with the help of the `sqlfluff` tool which is already configured during the `+postgres-base` target.
8893

89-
<!-- markdownlint-disable max-one-sentence-per-line -->
90-
!!! Note
91-
Before perform formatting it is needed to build `sqlfluff-image` docker image using following command
92-
`earthly github.com/input-output-hk/catalyst-ci/earthly/postgresql+sqlfluff-image`
93-
<!-- markdownlint-enable max-one-sentence-per-line -->
94-
9594
To apply and fix some formatting issues you can run `+format` target which will picks up directory
9695
where your Earthly file lies in as a source dir for formatting and run `+FORMAT` UDC target.
9796
Under the hood `+FORMAT` UDC target runs `sqlfluff-image` docker image,

docs/src/guides/languages/python.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ or read the guide and follow along in the file.
4545
### Prepare base builder
4646

4747
```Earthfile
48-
VERSION 0.7
48+
VERSION --global-cache 0.7
4949
5050
builder:
5151
FROM ./../../earthly/python+python-base

docs/src/guides/languages/rust.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Also we will take a look how we are setup Rust projects and what configuration i
4949
### Prepare base builder
5050

5151
```Earthfile
52-
VERSION 0.7
52+
VERSION --global-cache 0.7
5353
5454
# Set up our target toolchains, and copy our files.
5555
builder:

docs/src/style/index.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Any `Earthfile` which does not adhere to this style guide will be rejected if no
1919
The following structure should be used to provide a consistent structure to `Earthfile`s:
2020

2121
```Earthfile
22-
VERSION 0.7 # Should be the same across the repository
22+
VERSION --global-cache 0.7 # Should be the same across the repository
2323
2424
deps:
2525
FROM <base image>
@@ -87,7 +87,7 @@ This target is made up of the commands that appear outside of an existing target
8787
For example:
8888

8989
```Earthfile
90-
VERSION 0.7
90+
VERSION --global-cache 0.7
9191
FROM ubuntu:latest # Apart of the base target
9292
WORKDIR /work # Apart of the base target
9393
```
@@ -104,7 +104,7 @@ As such, the base target should be avoided, and individual targets should be
104104
clear about their intentions:
105105

106106
```Earthfile
107-
VERSION 0.7
107+
VERSION --global-cache 0.7
108108
109109
deps:
110110
FROM ubuntu:latest

0 commit comments

Comments
 (0)