Skip to content

Commit 7bb11c1

Browse files
authored
duckdb odbc docker (#1187)
* add a duckdb docker image * Add DuckDB ODBC driver installation and configuration Installs DuckDB ODBC driver and configures system-wide ODBC settings to enable DuckDB database connectivity for SQLPage. * add duckdb odbc info to readme * Fix CI digest artifact matching * Temporarily publish docker images on branch * Allow docker publish on branch (fix) * Temporarily run CI on branch pushes * Disable branch publish; fix duckdb inspect tag * Temporarily enable CI push on branch * Fix minimal tag suffix in docker_push * Disable temporary branch CI push
1 parent 73377f4 commit 7bb11c1

5 files changed

Lines changed: 115 additions & 5 deletions

File tree

.github/workflows/ci.yml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,24 @@ jobs:
121121
- linux/amd64
122122
- linux/arm/v7
123123
- linux/arm64
124+
variant:
125+
- minimal
126+
- duckdb
127+
exclude:
128+
# DuckDB ODBC is not available for armv7
129+
- platform: linux/arm/v7
130+
variant: duckdb
124131
steps:
125132
- name: Checkout
126133
uses: actions/checkout@v4
127134
- id: suffix
128135
name: Cache name suffix
129-
run: echo "suffix=-$(tr '/' '-' <<< ${{ matrix.platform }})" >> "$GITHUB_OUTPUT"
136+
run: |
137+
suffix="-$(tr '/' '-' <<< "${{ matrix.platform }}")"
138+
if [[ "${{ matrix.variant }}" != "minimal" ]]; then
139+
suffix="${suffix}-${{ matrix.variant }}"
140+
fi
141+
echo "suffix=${suffix}" >> "$GITHUB_OUTPUT"
130142
- name: Docker meta
131143
id: meta
132144
uses: docker/metadata-action@v5
@@ -149,6 +161,7 @@ jobs:
149161
with:
150162
context: .
151163
platforms: ${{ matrix.platform }}
164+
target: ${{ matrix.variant }}
152165
labels: ${{ steps.meta.outputs.labels }}
153166
push: ${{ github.event_name != 'pull_request' }}
154167
tags: ${{ steps.meta.outputs.tags }}
@@ -169,7 +182,7 @@ jobs:
169182
uses: actions/upload-artifact@v4
170183
if: github.event_name != 'pull_request'
171184
with:
172-
name: digests${{ steps.suffix.outputs.suffix }}
185+
name: digests-${{ matrix.variant }}${{ steps.suffix.outputs.suffix }}
173186
path: /tmp/digests/*
174187
if-no-files-found: error
175188
retention-days: 1
@@ -179,11 +192,16 @@ jobs:
179192
if: github.event_name != 'pull_request'
180193
needs:
181194
- docker_build
195+
strategy:
196+
matrix:
197+
variant:
198+
- minimal
199+
- duckdb
182200
steps:
183201
- name: Download digests
184202
uses: actions/download-artifact@v4
185203
with:
186-
pattern: digests*
204+
pattern: digests-${{ matrix.variant }}*
187205
merge-multiple: true
188206
path: /tmp/digests
189207
- name: Set up Docker Buildx
@@ -193,6 +211,7 @@ jobs:
193211
uses: docker/metadata-action@v5
194212
with:
195213
images: ${{ env.REGISTRY_IMAGE }}
214+
flavor: suffix=${{ matrix.variant != 'minimal' && format('-{0}', matrix.variant) || '' }}
196215
- name: Login to Docker Hub
197216
uses: docker/login-action@v3
198217
with:

Dockerfile

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ RUN /usr/local/bin/build-dependencies.sh
1515
COPY . .
1616
RUN /usr/local/bin/build-project.sh
1717

18-
FROM busybox:glibc
18+
# Default minimal image (busybox-based)
19+
FROM busybox:glibc AS minimal
1920
RUN addgroup --gid 1000 --system sqlpage && \
2021
adduser --uid 1000 --system --no-create-home --ingroup sqlpage sqlpage && \
2122
mkdir -p /etc/sqlpage && \
@@ -30,4 +31,37 @@ COPY --from=builder /tmp/sqlpage-libs/* /lib/
3031
USER sqlpage
3132
COPY --from=builder --chown=sqlpage:sqlpage /usr/src/sqlpage/sqlpage/sqlpage.db sqlpage/sqlpage.db
3233
EXPOSE 8080
33-
CMD ["/usr/local/bin/sqlpage"]
34+
CMD ["/usr/local/bin/sqlpage"]
35+
36+
# DuckDB ODBC image (debian-based with DuckDB ODBC driver)
37+
FROM debian:trixie-slim AS duckdb
38+
39+
ARG TARGETARCH
40+
ENV SQLPAGE_WEB_ROOT=/var/www
41+
ENV SQLPAGE_CONFIGURATION_DIRECTORY=/etc/sqlpage
42+
ENV DATABASE_URL="Driver=/opt/duckdb_odbc/libduckdb_odbc.so;Database=/var/lib/sqlpage/duckdb.db"
43+
44+
COPY scripts/install-duckdb-odbc.sh scripts/setup-sqlpage-user.sh /usr/local/bin/
45+
46+
RUN apt-get update && apt-get install -y --no-install-recommends \
47+
ca-certificates \
48+
curl \
49+
unzip \
50+
adduser \
51+
odbcinst \
52+
unixodbc \
53+
&& /usr/local/bin/install-duckdb-odbc.sh "$TARGETARCH" \
54+
&& apt-get purge -y --auto-remove curl unzip \
55+
&& rm -rf /var/lib/apt/lists/*
56+
57+
RUN /usr/local/bin/setup-sqlpage-user.sh
58+
59+
COPY --from=builder /usr/src/sqlpage/sqlpage.bin /usr/local/bin/sqlpage
60+
61+
USER sqlpage
62+
WORKDIR /var/www
63+
EXPOSE 8080
64+
CMD ["/usr/local/bin/sqlpage"]
65+
66+
# Default stage
67+
FROM minimal

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,17 @@ To run on a server, you can use [the docker image](https://hub.docker.com/r/lova
175175
We provide compiled binaries only for the x86_64 architecture, but provide docker images for other architectures, including arm64 and armv7. If you want to run SQLPage on a Raspberry Pi or
176176
a cheaper ARM cloud instance, using the docker image is the easiest way to do it.
177177

178+
#### DuckDB ODBC Docker Image
179+
180+
A DuckDB-enabled variant is available with pre-installed DuckDB ODBC drivers:
181+
182+
- Use the `-duckdb` suffix: `lovasoa/sqlpage:main-duckdb` or `lovasoa/sqlpage:latest-duckdb`
183+
- Comes pre-configured to connect to DuckDB at `/var/lib/sqlpage/duckdb.db`
184+
- To use a custom database location, set `DATABASE_URL`:
185+
- `docker run -e DATABASE_URL="Driver=DuckDB;Database=/path/to/your.db" -p 8080:8080 lovasoa/sqlpage:main-duckdb`
186+
- To persist your DuckDB database, mount a volume:
187+
- `docker run -v ./data:/var/lib/sqlpage lovasoa/sqlpage:main-duckdb`
188+
178189
### On Mac OS, with homebrew
179190

180191
An alternative for Mac OS users is to use [SQLPage's homebrew package](https://formulae.brew.sh/formula/sqlpage).

scripts/install-duckdb-odbc.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
set -eux
3+
4+
TARGETARCH="${1:-amd64}"
5+
DUCKDB_VERSION="${2:-v1.4.3.0}"
6+
7+
# Determine the correct DuckDB ODBC package for the architecture
8+
case "$TARGETARCH" in
9+
amd64) odbc_zip="duckdb_odbc-linux-amd64.zip" ;;
10+
arm64) odbc_zip="duckdb_odbc-linux-arm64.zip" ;;
11+
*) echo "Unsupported TARGETARCH: $TARGETARCH" >&2; exit 1 ;;
12+
esac
13+
14+
# Download and install DuckDB ODBC driver
15+
curl -fsSL -o /tmp/duckdb_odbc.zip "https://github.com/duckdb/duckdb-odbc/releases/download/${DUCKDB_VERSION}/${odbc_zip}"
16+
mkdir -p /opt/duckdb_odbc
17+
unzip /tmp/duckdb_odbc.zip -d /opt/duckdb_odbc
18+
rm /tmp/duckdb_odbc.zip
19+
20+
# Configure ODBC driver in odbcinst.ini
21+
cat >> /etc/odbcinst.ini << EOF
22+
23+
[DuckDB]
24+
Description=DuckDB ODBC Driver
25+
Driver=/opt/duckdb_odbc/libduckdb_odbc.so
26+
Setup=/opt/duckdb_odbc/libduckdb_odbc.so
27+
UsageCount=1
28+
EOF
29+
30+
# Configure default DuckDB data source in odbc.ini
31+
cat >> /etc/odbc.ini << EOF
32+
33+
[DuckDB]
34+
Driver=DuckDB
35+
Database=/var/lib/sqlpage/duckdb.db
36+
EOF

scripts/setup-sqlpage-user.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
set -eux
3+
4+
# Create sqlpage user and group
5+
addgroup --gid 1000 --system sqlpage
6+
adduser --uid 1000 --system --no-create-home --ingroup sqlpage sqlpage
7+
8+
# Create and configure directories
9+
mkdir -p /etc/sqlpage /var/lib/sqlpage /var/www
10+
chown -R sqlpage:sqlpage /etc/sqlpage /var/lib/sqlpage /var/www

0 commit comments

Comments
 (0)