Skip to content

Commit 7ea4bde

Browse files
authored
feat(postgres): Reduce Postgres image size (#420)
* remove uneeded stuff, move java only for the docs step * wip * wip * wip * wip
1 parent 2569686 commit 7ea4bde

File tree

2 files changed

+30
-38
lines changed

2 files changed

+30
-38
lines changed

earthly/postgresql/Earthfile

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,46 +10,14 @@ IMPORT ../java AS java
1010
postgres-base:
1111
FROM postgres:16.4-bookworm
1212

13-
ARG SCHEMASPY_VERSION=6.2.4
14-
ARG POSTGRESQL_JDBC_VERSION=42.7.4
15-
1613
WORKDIR /root
1714

1815
# Install necessary packages
1916
# Expand this list as needed, rather than adding more tools in later containers.
2017
RUN apt-get update && apt-get install -y \
21-
bash \
22-
build-essential \
23-
clang \
24-
cmake \
25-
colordiff \
26-
findutils \
27-
fontconfig \
28-
fonts-liberation2 \
29-
graphviz \
30-
libssl-dev \
31-
mold \
32-
openssl \
33-
pkgconf \
34-
python3-pip \
3518
python3-rich \
36-
python3-psycopg \
37-
ripgrep \
38-
wget \
39-
pipx \
4019
&& rm -rf /var/lib/apt/lists/*
4120

42-
# Use the cached java installation from the java Earthfile
43-
DO java+COPY_DEPS
44-
45-
# Install SQLFluff - Check
46-
ENV PATH="/root/.local/bin:${PATH}"
47-
RUN pipx install sqlfluff==3.1.1 && sqlfluff version
48-
49-
# Install SchemaSpy and required Postgresql JDBC driver
50-
RUN wget -O /bin/postgresql.jar https://jdbc.postgresql.org/download/postgresql-${POSTGRESQL_JDBC_VERSION}.jar
51-
RUN wget -O /bin/schemaspy.jar https://github.com/schemaspy/schemaspy/releases/download/v${SCHEMASPY_VERSION}/schemaspy-${SCHEMASPY_VERSION}.jar
52-
5321
# Get refinery
5422
COPY rust-tools+tool-refinery/refinery /bin
5523

@@ -68,6 +36,17 @@ postgres-base:
6836
SAVE ARTIFACT /scripts /scripts
6937
SAVE ARTIFACT /templates /templates
7038

39+
sqlfluff-base:
40+
FROM +postgres-base
41+
42+
RUN apt-get update && apt-get install -y \
43+
colordiff \
44+
pipx
45+
46+
# Install SQLFluff - Check
47+
ENV PATH="/root/.local/bin:${PATH}"
48+
RUN pipx install sqlfluff==3.1.1 && sqlfluff version
49+
7150
# Common build setup steps.
7251
# Arguments:
7352
# sqlfluff_cfg - REQUIRED - Location of repos .sqlfluff configuration file.
@@ -115,9 +94,22 @@ DOCS:
11594

11695
ARG migrations=./migrations
11796
ARG refinery_toml=./refinery.toml
97+
ARG SCHEMASPY_VERSION=6.2.4
98+
ARG POSTGRESQL_JDBC_VERSION=42.7.4
11899

119100
FROM +postgres-base
120101

102+
RUN apt-get update && apt-get install -y \
103+
graphviz \
104+
wget
105+
106+
# Use the cached java installation from the java Earthfile
107+
DO java+COPY_DEPS
108+
109+
# Install SchemaSpy and required Postgresql JDBC driver
110+
RUN wget -O /bin/postgresql.jar https://jdbc.postgresql.org/download/postgresql-${POSTGRESQL_JDBC_VERSION}.jar
111+
RUN wget -O /bin/schemaspy.jar https://github.com/schemaspy/schemaspy/releases/download/v${SCHEMASPY_VERSION}/schemaspy-${SCHEMASPY_VERSION}.jar
112+
121113
USER postgres:postgres
122114
WORKDIR /docs
123115

@@ -133,7 +125,7 @@ DOCS:
133125
# Linter checks for sql files
134126
CHECK:
135127
FUNCTION
136-
128+
137129
RUN /scripts/std_checks.py
138130

139131
# Format sql files

examples/postgresql/Earthfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ IMPORT ../../ AS cat-ci
1111
builder:
1212
DO postgresql-ci+BUILDER
1313

14-
# MUST Manually copy the .sqlfluff config used in the repo because the FUNCTION
15-
# above can not be passed a reference to a local target as an argument.
16-
COPY cat-ci+repo-config/repo/.sqlfluff .
17-
1814
# check if the sql files are properly formatted and pass lint quality checks.
1915
# CI target : true
2016
check:
21-
FROM +builder
17+
FROM postgresql-ci+sqlfluff-base
18+
19+
# MUST Manually copy the .sqlfluff config used in the repo because the FUNCTION
20+
# above can not be passed a reference to a local target as an argument.
21+
COPY cat-ci+repo-config/repo/.sqlfluff .
2222

2323
# Now you can run the script without the file not found error
2424
DO postgresql-ci+CHECK

0 commit comments

Comments
 (0)