Skip to content

Commit 896c65d

Browse files
authored
Merge pull request #248 from launchql/anmol/docker-update
docker: add new way to build and push docker images,
2 parents 7206425 + b55db9c commit 896c65d

File tree

14 files changed

+363
-139
lines changed

14 files changed

+363
-139
lines changed

.github/workflows/docker.yaml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Docker
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- v1
8+
- release/*
9+
paths:
10+
- "docker/**"
11+
- ".github/workflows/docker.yaml"
12+
pull_request:
13+
branches:
14+
- main
15+
- v1
16+
paths:
17+
- "docker/**"
18+
- ".github/workflows/docker.yaml"
19+
types: [opened, reopened, synchronize, ready_for_review]
20+
workflow_dispatch:
21+
inputs:
22+
process:
23+
description: 'Process to build (pgvector | node-sqitch | postgis)'
24+
type: choice
25+
required: true
26+
options:
27+
- pgvector
28+
- node-sqitch
29+
- postgis
30+
- pgvector-postgis
31+
default: pgvector
32+
version:
33+
description: 'Specific version to build (must exist in version.yaml)'
34+
type: string
35+
required: true
36+
37+
concurrency:
38+
group: ${{ github.workflow }}-${{ github.ref }}-docker
39+
cancel-in-progress: true
40+
41+
jobs:
42+
build-push:
43+
if: github.event_name != 'pull_request' || !github.event.pull_request.draft
44+
runs-on: ubuntu-latest
45+
46+
permissions:
47+
contents: read
48+
packages: write
49+
50+
defaults:
51+
run:
52+
working-directory: docker
53+
54+
strategy:
55+
matrix:
56+
process: [pgvector, node-sqitch, postgis, pgvector-postgis]
57+
max-parallel: 3
58+
59+
env:
60+
REPO: ghcr.io/${{ github.repository_owner }}
61+
PLATFORMS: linux/amd64,linux/arm64
62+
63+
steps:
64+
- name: Checkout
65+
uses: actions/checkout@v4
66+
67+
- name: Set up QEMU
68+
uses: docker/setup-qemu-action@v3
69+
70+
- name: Set up Docker Buildx
71+
uses: docker/setup-buildx-action@v3
72+
73+
- name: Login to GHCR
74+
if: github.event_name != 'pull_request'
75+
uses: docker/login-action@v3
76+
with:
77+
registry: ghcr.io
78+
username: ${{ github.actor }}
79+
password: ${{ secrets.GITHUB_TOKEN }}
80+
81+
- name: Build (no push)
82+
if: github.event_name == 'pull_request'
83+
run: |
84+
make \
85+
PROCESS=${{ matrix.process }} \
86+
REPO_NAME=$REPO \
87+
PLATFORMS="$PLATFORMS" \
88+
build-process
89+
90+
- name: Build and push (all versions)
91+
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
92+
run: |
93+
make \
94+
PROCESS=${{ matrix.process }} \
95+
REPO_NAME=$REPO \
96+
PLATFORMS="$PLATFORMS" \
97+
build-push-process

docker/Makefile

Lines changed: 87 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,93 @@
1-
.PHONY: all push-all node-sqitch pgvector clean
1+
.PHONY: all push-all build-all build-push-all build-process build-push-process \
2+
build-process-version build-push-process-version pgvector node-sqitch postgis clean
23

3-
all:
4-
$(MAKE) -C node-sqitch build
5-
$(MAKE) -C pgvector build
4+
REPO_NAME?=pyramation
5+
PLATFORMS?=linux/arm64
66

7-
push-all:
8-
$(MAKE) -C node-sqitch push
9-
$(MAKE) -C pgvector push
7+
# default process if none specified (can be overridden: `make PROCESS=postgis build-process`)
8+
PROCESS?=pgvector
109

11-
node-sqitch:
12-
$(MAKE) -C node-sqitch build
10+
# Convenience: list of known processes
11+
PROCESSES:=pgvector node-sqitch postgis pgvector-postgis
12+
13+
CONTAINER_NAME?=$(PROCESS)
14+
15+
## build-process builds docker image(s) for $(PROCESS) using base+versions from version.yaml
16+
## It will build one image per version listed in $(PROCESS)/version.yaml and tag as <repo>/<process>:<version>
17+
build-process:
18+
@echo "==> Building process: $(PROCESS)"
19+
@BASE=$$(sed -n 's/^[[:space:]]*base:[[:space:]]*//p' $(PROCESS)/version.yaml | head -n1); \
20+
VERSIONS=$$(sed -n '/^[[:space:]]*versions:/,$$p' $(PROCESS)/version.yaml | sed -n 's/^[[:space:]]*-[[:space:]]*//p'); \
21+
if [ -z "$$BASE" ] || [ -z "$$VERSIONS" ]; then \
22+
echo "Error: Could not parse base or versions from $(PROCESS)/version.yaml" 1>&2; \
23+
exit 1; \
24+
fi; \
25+
for v in $$VERSIONS; do \
26+
$(MAKE) --no-print-directory BASE=$$BASE VERSION=$$v build-process-version || exit $$?; \
27+
done
28+
29+
build-all:
30+
@for p in $(PROCESSES); do \
31+
$(MAKE) --no-print-directory PROCESS=$$p build-process || exit $$?; \
32+
done
33+
34+
build-push-process:
35+
@echo "==> Building+Pushing process: $(PROCESS)"
36+
@BASE=$$(sed -n 's/^[[:space:]]*base:[[:space:]]*//p' $(PROCESS)/version.yaml | head -n1); \
37+
VERSIONS=$$(sed -n '/^[[:space:]]*versions:/,$$p' $(PROCESS)/version.yaml | sed -n 's/^[[:space:]]*-[[:space:]]*//p'); \
38+
if [ -z "$$BASE" ] || [ -z "$$VERSIONS" ]; then \
39+
echo "Error: Could not parse base or versions from $(PROCESS)/version.yaml" 1>&2; \
40+
exit 1; \
41+
fi; \
42+
for v in $$VERSIONS; do \
43+
$(MAKE) --no-print-directory BASE=$$BASE VERSION=$$v build-push-process-version || exit $$?; \
44+
done
45+
46+
build-push-all:
47+
@for p in $(PROCESSES); do \
48+
$(MAKE) --no-print-directory PROCESS=$$p build-push-process || exit $$?; \
49+
done
1350

51+
# Build only a specific VERSION for $(PROCESS). Intended for internal use by build-process.
52+
# Usage (internal): $(MAKE) BASE=<base> VERSION=<version> build-process-version
53+
build-process-version:
54+
@test -n "$(BASE)" || { echo "Error: BASE is required"; exit 1; }
55+
@test -n "$(VERSION)" || { echo "Error: VERSION is required"; exit 1; }
56+
@echo " -> $(BASE):$(VERSION) => $(REPO_NAME)/$(PROCESS):$(VERSION) (build)"
57+
@docker buildx build \
58+
--platform $(PLATFORMS) \
59+
--build-arg BASE=$(BASE) \
60+
--build-arg BASE_VERSION=$(VERSION) \
61+
-t $(REPO_NAME)/$(PROCESS):$(VERSION) \
62+
$(PROCESS)
63+
64+
# Build+push only a specific VERSION for $(PROCESS). Intended for internal use by build-push-process.
65+
# Usage (internal): $(MAKE) BASE=<base> VERSION=<version> build-push-process-version
66+
build-push-process-version:
67+
@test -n "$(BASE)" || { echo "Error: BASE is required"; exit 1; }
68+
@test -n "$(VERSION)" || { echo "Error: VERSION is required"; exit 1; }
69+
@echo " -> $(BASE):$(VERSION) => $(REPO_NAME)/$(PROCESS):$(VERSION) (push)"
70+
@docker buildx build \
71+
--platform $(PLATFORMS) \
72+
--build-arg BASE=$(BASE) \
73+
--build-arg BASE_VERSION=$(VERSION) \
74+
-t $(REPO_NAME)/$(PROCESS):$(VERSION) \
75+
--push \
76+
$(PROCESS)
77+
78+
# Aliases
79+
all: build-all
80+
push-all: build-push-all
81+
82+
# Convenience per-process targets
1483
pgvector:
15-
$(MAKE) -C pgvector build
84+
$(MAKE) PROCESS=pgvector build-process
85+
86+
node-sqitch:
87+
$(MAKE) PROCESS=node-sqitch build-process
88+
89+
postgis:
90+
$(MAKE) PROCESS=postgis build-process
1691

17-
# Git cleanup (repo-level only)
18-
clean:
19-
@git reset --hard
20-
@git ls-files --other --exclude-standard | xargs rm -f
92+
pgvector-postgis:
93+
$(MAKE) PROCESS=pgvector-postgis build-process

docker/node-sqitch/Dockerfile

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
FROM node:20.12.0-alpine3.19 AS sqitch-build
1+
ARG BASE=node
2+
ARG BASE_VERSION=20.12.0-alpine3.19
3+
FROM ${BASE}:${BASE_VERSION} AS sqitch-build
24

5+
LABEL org.opencontainers.image.source="https://github.com/launchql/launchql"
36

47
# Install system dependencies.
58
WORKDIR /work
@@ -46,7 +49,11 @@ RUN apk del .build-deps
4649
################################################################################
4750
# Copy to the final image without all the build stuff.
4851

49-
FROM node:20.12.0-alpine3.19 AS sqitch
52+
ARG BASE=node
53+
ARG BASE_VERSION=20.12.0-alpine3.19
54+
FROM ${BASE}:${BASE_VERSION} AS sqitch
55+
56+
LABEL org.opencontainers.image.source="https://github.com/launchql/launchql"
5057

5158
# Install runtime system dependencies and remove unnecesary files.
5259
RUN mkdir -p /usr/share/man/man1 /usr/share/man/man7 \
@@ -82,4 +89,4 @@ ENV LESS=-R LC_ALL=C.UTF-8 LANG=C.UTF-8 SQITCH_EDITOR=vi SQITCH_PAGER=less
8289
# for gyp and such
8390
RUN apk update && apk add --no-cache bash git python3-dev make g++
8491

85-
ENTRYPOINT ["/bin/sh"]
92+
ENTRYPOINT ["/bin/sh"]

docker/node-sqitch/Makefile

Lines changed: 0 additions & 39 deletions
This file was deleted.

docker/node-sqitch/version.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
base: node
2+
versions:
3+
- 20.12.0-alpine3.19

docker/pgvector-postgis/Dockerfile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
ARG BASE=postgres
2+
ARG BASE_VERSION=14
3+
FROM ${BASE}:${BASE_VERSION}
4+
5+
LABEL org.opencontainers.image.source="https://github.com/launchql/launchql"
6+
ARG BASE
7+
ARG BASE_VERSION
8+
ENV BASE_VERSION=${BASE_VERSION}
9+
10+
# Debian-based: install both pgvector and postgis from PGDG per-PG-major
11+
RUN set -eux; \
12+
export DEBIAN_FRONTEND=noninteractive; \
13+
apt-get update; \
14+
apt-get install -y --no-install-recommends ca-certificates curl gnupg dirmngr; \
15+
update-ca-certificates || true; \
16+
CODENAME=$(. /etc/os-release && echo "$VERSION_CODENAME"); \
17+
install -d -m 0755 /usr/share/keyrings; \
18+
curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor -o /usr/share/keyrings/postgresql.gpg; \
19+
echo "deb [signed-by=/usr/share/keyrings/postgresql.gpg] https://apt.postgresql.org/pub/repos/apt ${CODENAME}-pgdg main" > /etc/apt/sources.list.d/pgdg.list; \
20+
apt-get update; \
21+
PG_MAJOR=$(pg_config --version | sed 's/^PostgreSQL \([0-9]\+\).*/\1/'); \
22+
apt-get install -y --no-install-recommends \
23+
postgresql-${PG_MAJOR}-postgis-3 \
24+
postgresql-${PG_MAJOR}-postgis-3-scripts \
25+
postgis \
26+
postgresql-${PG_MAJOR}-pgvector \
27+
make \
28+
bash; \
29+
rm -rf /var/lib/apt/lists/*
30+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
base: postgres
2+
versions:
3+
- 14.19
4+
- 15.14
5+
- 16.10
6+
- 17.6
7+
- 18.0
8+

docker/pgvector/Dockerfile

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1-
FROM pyramation/postgis:13.3-alpine
1+
ARG BASE=postgres
2+
ARG BASE_VERSION=14
3+
FROM ${BASE}:${BASE_VERSION}
24

3-
# Install PGVector extension
4-
RUN apk add --no-cache --virtual .build-deps \
5-
git \
6-
build-base \
7-
postgresql-dev \
8-
&& git clone --branch v0.5.1 https://github.com/pgvector/pgvector.git \
9-
&& cd pgvector \
10-
&& make && make install \
11-
&& cd .. && rm -rf pgvector \
12-
&& apk del .build-deps
5+
LABEL org.opencontainers.image.source="https://github.com/launchql/launchql"
6+
ARG BASE
7+
ARG BASE_VERSION
8+
ENV BASE_VERSION=${BASE_VERSION}
9+
10+
# Debian-based install: use PGDG per-PG-major package
11+
RUN set -eux; \
12+
export DEBIAN_FRONTEND=noninteractive; \
13+
apt-get update; \
14+
apt-get install -y --no-install-recommends ca-certificates curl gnupg dirmngr; \
15+
update-ca-certificates || true; \
16+
CODENAME=$(. /etc/os-release && echo "$VERSION_CODENAME"); \
17+
install -d -m 0755 /usr/share/keyrings; \
18+
curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor -o /usr/share/keyrings/postgresql.gpg; \
19+
echo "deb [signed-by=/usr/share/keyrings/postgresql.gpg] https://apt.postgresql.org/pub/repos/apt ${CODENAME}-pgdg main" > /etc/apt/sources.list.d/pgdg.list; \
20+
apt-get update; \
21+
PG_MAJOR=$(pg_config --version | sed 's/^PostgreSQL \([0-9]\+\).*/\1/'); \
22+
apt-get install -y --no-install-recommends \
23+
postgresql-${PG_MAJOR}-pgvector \
24+
make \
25+
bash; \
26+
rm -rf /var/lib/apt/lists/*

docker/pgvector/Dockerfile.alpine

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
ARG BASE=postgres
2+
ARG BASE_VERSION=13.3-alpine
3+
FROM ${BASE}:${BASE_VERSION}
4+
5+
LABEL org.opencontainers.image.source="https://github.com/launchql/launchql"
6+
ARG BASE
7+
ARG BASE_VERSION
8+
ARG PGVECTOR_REF="v0.8.1"
9+
ENV BASE_VERSION=${BASE_VERSION}
10+
ENV PGVECTOR_REF=${PGVECTOR_REF}
11+
12+
# Alpine build (kept as a backup variant)
13+
RUN set -eux; \
14+
: "${BASE_VERSION:?BASE_VERSION not set}"; \
15+
apk add --no-cache --virtual .build-deps git build-base bash make curl ca-certificates; \
16+
LLVM_CFG=$(pg_config --configure | tr ' ' '\n' | sed -n 's/^LLVM_CONFIG=\(.*\)$/\1/p' | tr -d '\"\'\'' ); \
17+
[ -n "${LLVM_CFG}" ] || { echo "Server not built with LLVM (LLVM_CONFIG missing)" >&2; exit 1; }; \
18+
LLVM_VER=$(echo "${LLVM_CFG}" | sed -E 's#.*/llvm-?([0-9]+)/.*#\1#'); \
19+
[ -n "${LLVM_VER}" ] || { echo "Could not determine LLVM version from: ${LLVM_CFG}" >&2; exit 1; }; \
20+
apk add --no-cache --virtual .clang \
21+
"clang${LLVM_VER}" \
22+
"llvm${LLVM_VER}" \
23+
"llvm${LLVM_VER}-libs" \
24+
"llvm${LLVM_VER}-linker-tools"; \
25+
git clone --quiet --depth 1 --branch "${PGVECTOR_REF}" https://github.com/pgvector/pgvector.git; \
26+
cd pgvector && make && make install; \
27+
cd .. && rm -rf pgvector; \
28+
apk del .clang .build-deps
29+

0 commit comments

Comments
 (0)