[PATCH 3/4] ci: add tests for sqlite3
You-Sheng Yang
vicamo at gmail.com
Tue Dec 7 19:49:15 AEDT 2021
Signed-off-by: You-Sheng Yang <vicamo at gmail.com>
---
.github/workflows/ci.yaml | 9 +++----
docker-compose-sqlite3.yml | 19 +++++++++++++++
tools/docker/Dockerfile | 1 +
tools/docker/entrypoint.sh | 49 +++++++++++++++++++++++++-------------
4 files changed, 58 insertions(+), 20 deletions(-)
create mode 100644 docker-compose-sqlite3.yml
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index 04c67cb..9edec88 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -24,7 +24,7 @@ jobs:
strategy:
matrix:
python: [3.6, 3.7, 3.8, 3.9]
- db: [postgres, mysql]
+ db: [postgres, mysql, sqlite3]
env:
DATABASE_NAME: patchwork
DATABASE_USER: patchwork
@@ -88,7 +88,8 @@ jobs:
run: tox
env:
DATABASE_TYPE: "${{ matrix.db }}"
- DATABASE_HOST: "127.0.0.1"
+ DATABASE_HOST: ${{ matrix.db != 'sqlite3' && '127.0.0.1' || '' }}
+ DATABASE_NAME: ${{ matrix.db != 'sqlite3' && env.DATABASE_NAME || '/dev/shm/patchwork.test.db.sqlite3' }}
docs:
name: Build docs
runs-on: ubuntu-latest
@@ -116,7 +117,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
- db: [postgres, mysql]
+ db: [postgres, mysql, sqlite3]
steps:
- name: Checkout source code
uses: actions/checkout at v2
@@ -128,7 +129,7 @@ jobs:
python-version: 3.9
- name: Bring up docker-compose service
env:
- COMPOSE_FILE: ${{ matrix.db == 'mysql' && 'docker-compose.yml' || 'docker-compose-pg.yml' }}
+ COMPOSE_FILE: ${{ matrix.db == 'mysql' && 'docker-compose.yml' || (matrix.db == 'postgres' && 'docker-compose-pg.yml') || 'docker-compose-sqlite3.yml' }}
run: |
docker-compose build --build-arg UID=$(id -u) --build-arg GID=$(id -g)
docker-compose up --detach
diff --git a/docker-compose-sqlite3.yml b/docker-compose-sqlite3.yml
new file mode 100644
index 0000000..d4c6659
--- /dev/null
+++ b/docker-compose-sqlite3.yml
@@ -0,0 +1,19 @@
+version: "3"
+services:
+ web:
+ build:
+ context: .
+ dockerfile: ./tools/docker/Dockerfile
+ args:
+ - UID
+ - GID
+ command: python3 manage.py runserver 0.0.0.0:8000
+ volumes:
+ - .:/home/patchwork/patchwork/
+ ports:
+ - "8000:8000"
+ environment:
+ - UID
+ - GID
+ - DATABASE_TYPE=sqlite3
+ - DATABASE_NAME=/home/patchwork/patchwork/tools/docker/db/db.sqlite3
diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile
index fe0cd59..18f1e4c 100644
--- a/tools/docker/Dockerfile
+++ b/tools/docker/Dockerfile
@@ -38,6 +38,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
libssl-dev \
mysql-client \
postgresql-client \
+ sqlite3 \
tzdata \
zlib1g-dev \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
diff --git a/tools/docker/entrypoint.sh b/tools/docker/entrypoint.sh
index 6be90b9..343f644 100755
--- a/tools/docker/entrypoint.sh
+++ b/tools/docker/entrypoint.sh
@@ -3,18 +3,22 @@ set -euo pipefail
export DATABASE_HOST=${DATABASE_HOST:-}
export DATABASE_PORT=${DATABASE_PORT:-}
-export DATABASE_NAME=${DATABASE_NAME:-patchwork}
export DATABASE_USER=${DATABASE_USER:-patchwork}
export DATABASE_PASS=${DATABASE_PASS:-password}
case "${DATABASE_TYPE:-}" in
postgres)
+ export DATABASE_NAME=${DATABASE_NAME:-patchwork}
export PGPORT=${DATABASE_PORT}
export PGPASSWORD=${DATABASE_PASS}
psql_args=( ${DATABASE_HOST:+--host=${DATABASE_HOST}} "--username=${DATABASE_USER}" )
;;
+sqlite3)
+ export DATABASE_NAME=${DATABASE_NAME:-}
+ ;;
*)
export DATABASE_TYPE=mysql
+ export DATABASE_NAME=${DATABASE_NAME:-patchwork}
mysql_args=( ${DATABASE_HOST:+--host=${DATABASE_HOST}} ${DATABASE_PORT:+--port=${DATABASE_PORT}} "--user=${DATABASE_USER}" "--password=${DATABASE_PASS}" )
mysql_root_args=( ${DATABASE_HOST:+--host=${DATABASE_HOST}} ${DATABASE_PORT:+--port=${DATABASE_PORT}} "--user=root" "--password=${MYSQL_ROOT_PASSWORD:-}" )
;;
@@ -23,19 +27,25 @@ esac
# functions
test_db_connection() {
- if [ ${DATABASE_TYPE} = "postgres" ]; then
- echo ';' | psql "${psql_args[@]}" 2> /dev/null > /dev/null
- else
- mysqladmin "${mysql_root_args[@]}" ping > /dev/null 2> /dev/null
- fi
+ case "${DATABASE_TYPE}" in
+ "postgres")
+ echo ';' | psql "${psql_args[@]}" 2> /dev/null > /dev/null ;;
+ "mysql")
+ mysqladmin "${mysql_root_args[@]}" ping > /dev/null 2> /dev/null ;;
+ "sqlite3")
+ echo ';' | sqlite3 "${DATABASE_NAME}" > /dev/null 2> /dev/null ;;
+ esac
}
test_database() {
- if [ ${DATABASE_TYPE} = "postgres" ]; then
- echo 'DESCRIBE patchwork_project;' | psql "${psql_args[@]}" "${DATABASE_NAME}" 2> /dev/null
- else
- echo 'DESCRIBE patchwork_project;' | mysql "${mysql_args[@]}" "${DATABASE_NAME}" 2> /dev/null
- fi
+ case "${DATABASE_TYPE}" in
+ "postgres")
+ echo 'DESCRIBE patchwork_project;' | psql "${psql_args[@]}" "${DATABASE_NAME}" 2> /dev/null ;;
+ "mysql")
+ echo 'DESCRIBE patchwork_project;' | mysql "${mysql_args[@]}" "${DATABASE_NAME}" 2> /dev/null ;;
+ "sqlite3")
+ echo 'SELECT 0 FROM patchwork_project;' | sqlite3 "${DATABASE_NAME}" > /dev/null 2> /dev/null ;;
+ esac
}
reset_data_mysql() {
@@ -55,12 +65,19 @@ CREATE DATABASE ${DATABASE_NAME} WITH ENCODING = 'UTF8';
EOF
}
+reset_data_sqlite3() {
+ rm -f "${DATABASE_NAME}"
+}
+
reset_data() {
- if [ x${DATABASE_TYPE} = x"postgres" ]; then
- reset_data_postgres
- else
- reset_data_mysql
- fi
+ case "${DATABASE_TYPE}" in
+ "postgres")
+ reset_data_postgres ;;
+ "mysql")
+ reset_data_mysql ;;
+ "sqlite3")
+ reset_data_sqlite3 ;;
+ esac
# load initial data
python manage.py migrate #> /dev/null
--
2.32.0
More information about the Patchwork
mailing list