-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDockerfile.sql-overlay
More file actions
72 lines (63 loc) · 2.99 KB
/
Dockerfile.sql-overlay
File metadata and controls
72 lines (63 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# Thin overlay for SQL-only changes
#
# This Dockerfile creates a thin layer on top of an existing HAF image
# that only updates the PostgreSQL extension SQL files. This is used
# when only SQL files changed (no C++ code changes), allowing fast
# builds (~30 seconds) without full recompilation.
#
# Usage:
# # First generate the extension SQL files
# ./scripts/generate_extension_sql.sh "$GIT_SHA" extension_sql/
#
# # Then build the thin overlay
# docker build -f Dockerfile.sql-overlay \
# --build-arg BASE_IMAGE=registry.gitlab.syncad.com/hive/haf:abc12345 \
# --build-arg GIT_SHA=def67890 \
# --build-arg BASE_COMMIT=abc12345... \
# -t registry.gitlab.syncad.com/hive/haf:def67890 .
#
# The resulting image has:
# - All binaries from the base image (unchanged)
# - Updated extension SQL files for the new commit
# - Updated HAF_COMMIT label/env
ARG BASE_IMAGE
FROM ${BASE_IMAGE}
ARG GIT_SHA
ARG BASE_COMMIT
# POSTGRES_VERSION is inherited from base image's ENV — no ARG needed
USER root
# Copy pre-generated extension SQL files to temp dir first, then move using
# ENV-based path (COPY can only resolve ARG, not inherited ENV)
COPY extension_sql/ /tmp/extension_sql/
RUN cp -r /tmp/extension_sql/* /usr/share/postgresql/${POSTGRES_VERSION}/extension/ \
&& rm -rf /tmp/extension_sql
# Create symlink for the shared library (.so file)
# The base image has libhfm-<BASE_COMMIT>.so, but the new control file references
# libhfm-<GIT_SHA>.so. We create a symlink so both names work.
# Fallback: if no commit-hashed .so exists, look for any libhfm*.so (older images).
RUN cd /usr/lib/postgresql/${POSTGRES_VERSION}/lib && \
if [ -n "${BASE_COMMIT}" ] && [ "${BASE_COMMIT}" != "${GIT_SHA}" ]; then \
BASE_SO=$(ls libhfm-${BASE_COMMIT}*.so 2>/dev/null | head -1) && \
if [ -z "${BASE_SO}" ]; then \
BASE_SO=$(ls libhfm*.so 2>/dev/null | head -1); \
fi && \
if [ -n "${BASE_SO}" ]; then \
ln -sf "${BASE_SO}" "libhfm-${GIT_SHA}.so" && \
echo "Created symlink: libhfm-${GIT_SHA}.so -> ${BASE_SO}"; \
else \
echo "ERROR: No libhfm*.so found in base image - cannot create overlay" && exit 1; \
fi; \
fi
# Fix permissions on extension files (match original Dockerfile)
RUN chmod 644 /usr/share/postgresql/${POSTGRES_VERSION}/extension/hive_fork_manager*.sql \
/usr/share/postgresql/${POSTGRES_VERSION}/extension/hive_fork_manager.control \
/usr/share/postgresql/${POSTGRES_VERSION}/extension/update.sql 2>/dev/null || true && \
chmod 755 /usr/share/postgresql/${POSTGRES_VERSION}/extension/hive_fork_manager_update_script_generator.sh 2>/dev/null || true
# Switch back to hived (default user in HAF images)
USER hived
WORKDIR /home/hived
# Update labels and environment to reflect the new commit
LABEL io.hive.image.revision="${GIT_SHA}"
LABEL io.hive.image.sql_overlay="true"
LABEL io.hive.image.sql_overlay.description="Thin overlay with updated SQL extension files"
ENV HAF_COMMIT=${GIT_SHA}