Skip to content

Commit 73e79db

Browse files
committed
Consolidated sqlite-lib service into sqlite.
1 parent f5b0fc2 commit 73e79db

File tree

3 files changed

+54
-54
lines changed

3 files changed

+54
-54
lines changed

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ MYSQL_VERSION=8.0
55
ORACLE_VERSION=23.5.0.0
66
POSTGRESQL_VERSION=14
77
POSTGIS_VERSION=3.1
8-
SQLITE_VERSION=3.31.0
8+
SQLITE_VERSION=
99
SQLITE_CFLAGS="-DSQLITE_ENABLE_DESERIALIZE \
1010
-DSQLITE_ENABLE_JSON1 \
1111
-DSQLITE_MAX_VARIABLE_NUMBER=32766"

README.md

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Tooling and test execution support for [Django][0] :unicorn:
3636
3. Build the image:
3737

3838
```console
39-
$ docker compose build sqlite
39+
$ docker compose build base
4040
```
4141

4242
4. Run the tests:
@@ -66,7 +66,6 @@ $ docker compose run --rm mysql
6666
$ docker compose run --rm oracle
6767
$ docker compose run --rm postgres
6868
$ docker compose run --rm sqlite
69-
$ docker compose run --rm sqlite-lib
7069
```
7170

7271
Each of the above commands will run the test suite for a different supported
@@ -205,14 +204,13 @@ The versions of various backend services can be switched by setting these enviro
205204
| `ORACLE_VERSION` | `23.5.0.0` | Version of Oracle container image to use |
206205
| `POSTGRESQL_VERSION` | `14` | Version of PostgreSQL container image to use |
207206
| `POSTGIS_VERSION` | `3.1` | Version of PostGIS extension to use |
208-
| `SQLITE_VERSION` | `3.31.0` | Version of SQLite to compile and use |
207+
| `SQLITE_VERSION` | | Version of SQLite to compile and use |
209208

210209
> [!NOTE]
211210
>
212-
> Using a specific SQLite version requires compiling it from source. To
213-
> customize the `CFLAGS` used for the compilation, you can set the
214-
> `SQLITE_CFLAGS` environment variable. See the [`.env`][10] file for its
215-
> default value. For more details, see [SQLite Versions](#SQLite-Versions).
211+
> If left unspecified, the SQLite version provided by Debian will be used.
212+
> Using a specific SQLite version requires compiling it from source. For more
213+
> details, see [SQLite Versions](#SQLite-Versions).
216214
217215
### Python Versions
218216

@@ -304,19 +302,24 @@ dynamically using `LD_PRELOAD`. There are a few caveats as a result:
304302
different flags, some tests may fail.
305303
306304
We currently work around the above caveats by setting the simplest `CFLAGS`
307-
value that allows all the tests to pass. In the future, the Django codebase may
308-
be more robust when tested against the different SQLite configurations and these
309-
workarounds may no longer be necessary.
305+
value that allows all the tests to pass. To customize the `CFLAGS` used for the
306+
compilation, you can set the `SQLITE_CFLAGS` environment variable. See the
307+
[`.env`][10] file for its default value.
310308
311-
Running the tests against a specific SQLite version must be done using the
312-
`sqlite-lib` container instead of `sqlite`.
313-
314-
```console
315-
$ docker compose run --rm sqlite-lib
309+
```
310+
SQLITE_VERSION=3.48.0 SQLITE_CFLAGS="-DSQLITE_OMIT_JSON -DSQLITE_MAX_VARIABLE_NUMBER=999" docker compose run --build --rm sqlite
316311
```
317312
318-
This is done to avoid compiling SQLite when you are not testing against a
319-
specific version.
313+
> [!NOTE]
314+
>
315+
> The `--build` argument is necessary if you've changed `SQLITE_CFLAGS` since
316+
> the last run, as it's not part of the image tag. You can also rebuild the
317+
> image separately by running `docker compose build sqlite`, optionally with
318+
> `--no-cache` to ignore the cached build.
319+
320+
In the future, the Django codebase may be more robust when tested against
321+
different SQLite configurations and the `CFLAGS` workaround may no longer be
322+
necessary.
320323
321324
### Other Versions
322325

compose.yml

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -82,36 +82,6 @@ x-postgresql-base: &postgresql-base
8282
-c wal_level=minimal
8383
# 13+: -c wal_keep_size=0
8484

85-
x-sqlite-lib-base: &sqlite-lib-base
86-
image: django-docker-box:${PYTHON_IMPLEMENTATION}-${PYTHON_VERSION}-sqlite${SQLITE_VERSION}
87-
pull_policy: never
88-
build:
89-
context: .
90-
dockerfile_inline: |
91-
FROM django-docker-box:${PYTHON_IMPLEMENTATION}-${PYTHON_VERSION}
92-
SHELL ["/bin/bash", "-o", "errexit", "-o", "nounset", "-o", "pipefail", "-o", "xtrace", "-c"]
93-
# Only compile SQLite and set LD_PRELOAD if a version is specified.
94-
RUN <<EOF
95-
if [[ "${SQLITE_VERSION}" ]]; then
96-
export CFLAGS="${SQLITE_CFLAGS}"
97-
git clone --depth 1 --branch version-${SQLITE_VERSION} \
98-
https://github.com/sqlite/sqlite.git /tmp/sqlite
99-
cd /tmp/sqlite
100-
./configure
101-
make
102-
cp .libs/libsqlite3.so /tmp/
103-
rm -rf /tmp/sqlite
104-
fi
105-
EOF
106-
SHELL ["/bin/bash", "-c"]
107-
ENV LD_PRELOAD=${SQLITE_VERSION:+/tmp/libsqlite3.so}
108-
args:
109-
- PYTHON_IMPLEMENTATION=${PYTHON_IMPLEMENTATION}
110-
- PYTHON_VERSION=${PYTHON_VERSION}
111-
- SQLITE_VERSION=${SQLITE_VERSION}
112-
- SQLITE_CFLAGS=${SQLITE_CFLAGS}
113-
additional_contexts: *additional-contexts
114-
11585
x-memcached: &memcached-base
11686
image: memcached:alpine
11787
deploy:
@@ -169,6 +139,10 @@ volumes:
169139

170140
services:
171141

142+
# Base service to allow building the image with `docker compose build base`.
143+
base:
144+
<<: *base
145+
172146
# Services: Databases
173147

174148
mariadb-db:
@@ -313,18 +287,41 @@ services:
313287
- DATABASE_ENGINE=django.db.backends.postgresql
314288
- DATABASE_HOST=postgresql-db
315289

316-
sqlite: &sqlite-base
290+
sqlite:
317291
<<: *base
292+
image: django-docker-box:${PYTHON_IMPLEMENTATION}-${PYTHON_VERSION}-sqlite${SQLITE_VERSION}
293+
pull_policy: never
294+
build:
295+
context: .
296+
dockerfile_inline: |
297+
FROM django-docker-box:${PYTHON_IMPLEMENTATION}-${PYTHON_VERSION}
298+
SHELL ["/bin/bash", "-o", "errexit", "-o", "nounset", "-o", "pipefail", "-o", "xtrace", "-c"]
299+
# Only compile SQLite and set LD_PRELOAD if a version is specified.
300+
RUN <<EOF
301+
if [[ "${SQLITE_VERSION}" ]]; then
302+
export CFLAGS="${SQLITE_CFLAGS}"
303+
git clone --depth 1 --branch version-${SQLITE_VERSION} \
304+
https://github.com/sqlite/sqlite.git /tmp/sqlite
305+
cd /tmp/sqlite
306+
./configure
307+
make
308+
cp .libs/libsqlite3.so /tmp/
309+
rm -rf /tmp/sqlite
310+
fi
311+
EOF
312+
SHELL ["/bin/bash", "-c"]
313+
ENV LD_PRELOAD=${SQLITE_VERSION:+/tmp/libsqlite3.so}
314+
args:
315+
- PYTHON_IMPLEMENTATION=${PYTHON_IMPLEMENTATION}
316+
- PYTHON_VERSION=${PYTHON_VERSION}
317+
- SQLITE_VERSION=${SQLITE_VERSION}
318+
- SQLITE_CFLAGS=${SQLITE_CFLAGS}
319+
additional_contexts: *additional-contexts
318320
depends_on:
319321
<<: *depends-on-caches
320322
environment:
321323
- DATABASE_ENGINE=django.db.backends.sqlite3
322324

323-
sqlite-lib:
324-
<<:
325-
- *sqlite-lib-base
326-
- *sqlite-base
327-
328325
# Commands: Tests: GIS
329326

330327
mariadb-gis:

0 commit comments

Comments
 (0)