[PATCH v3 5/6] ci: add tests for sqlite3

You-Sheng Yang vicamo at gmail.com
Thu Dec 9 04:48:17 AEDT 2021


You-Sheng Yang <vicamo at gmail.com> 於 2021年12月9日 週四 上午1:02寫道:
>
> Signed-off-by: You-Sheng Yang <vicamo at gmail.com>
> ---
>  .github/workflows/ci.yaml  |  8 ++++----
>  docker-compose-sqlite3.yml | 19 +++++++++++++++++++
>  tools/docker/Dockerfile    |  1 +
>  tools/docker/entrypoint.sh | 19 +++++++++++++------
>  4 files changed, 37 insertions(+), 10 deletions(-)
>  create mode 100644 docker-compose-sqlite3.yml
>
> diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
> index 6e9033d..0818aca 100644
> --- a/.github/workflows/ci.yaml
> +++ b/.github/workflows/ci.yaml
> @@ -24,11 +24,11 @@ jobs:
>      strategy:
>        matrix:
>          python: [3.6, 3.7, 3.8, 3.9]
> -        db: [postgres, mysql]
> +        db: [postgres, mysql, sqlite3]
>      env:
>        DATABASE_TYPE: "${{ matrix.db }}"
>        DATABASE_HOST: "127.0.0.1"
> -      DATABASE_NAME: patchwork
> +      DATABASE_NAME: ${{ matrix.db != 'sqlite3' && 'patchwork' || '/dev/shm/patchwork.test.db.sqlite3' }}
>        DATABASE_USER: patchwork
>        DATABASE_PASSWORD: password
>        MYSQL_ROOT_PASSWORD: root
> @@ -115,9 +115,9 @@ jobs:
>      runs-on: ubuntu-latest
>      strategy:
>        matrix:
> -        db: [postgres, mysql]
> +        db: [postgres, mysql, sqlite3]
>      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' }}
>      steps:
>        - name: Checkout source code
>          uses: actions/checkout at v2
> 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 71167e0..d9d0905 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 d1bad82..96a59ed 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_PASSWORD=${DATABASE_PASSWORD:-password}
>
>  case "${DATABASE_TYPE:-}" in
>  postgres)
> +    export DATABASE_NAME=${DATABASE_NAME:-patchwork}
>      export PGPORT=${DATABASE_PORT}
>      export PGPASSWORD=${DATABASE_PASSWORD}
>      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_PASSWORD}" )
>      ;;
>  esac
> @@ -22,11 +26,14 @@ esac
>  # functions
>
>  test_database() {
> -    if [ ${DATABASE_TYPE} = "postgres" ]; then
> -        echo ';' | psql "${psql_args[@]}" "${DATABASE_NAME}" 2> /dev/null
> -    else
> -        echo ';' | mysql "${mysql_args[@]}" "${DATABASE_NAME}" 2> /dev/null
> -    fi
> +    case "${DATABASE_TYPE}" in
> +    "postgres")
> +        echo ';' | psql "${psql_args[@]}" "${DATABASE_NAME}" 2> /dev/null ;;
> +    "mysql")
> +        echo ';' | mysql "${mysql_args[@]}" "${DATABASE_NAME}" 2> /dev/null ;;
> +    "sqlite3")
> +        echo ';' | sqlite3 "${DATABASE_NAME}" > /dev/null 2> /dev/null ;;

So DATABASE_NAME shall not be empty if not specified.

> +    esac
>  }
>
>  # the script begins!
> --
> 2.32.0
>


More information about the Patchwork mailing list