Skip to content

Commit

Permalink
Use two databases in testing #224
Browse files Browse the repository at this point in the history
Signed-off-by: Jono Yang <[email protected]>
  • Loading branch information
JonoYang committed Jan 15, 2024
1 parent b5a3c47 commit 7a19e4c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 35 deletions.
67 changes: 32 additions & 35 deletions .github/workflows/purldb-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,45 @@ name: PurlDB Tests CI
on: [push, pull_request]

env:
#POSTGRES_DB: packagedb
POSTGRES_DB: packagedb
POSTGRES_USER: packagedb
POSTGRES_PASSWORD: packagedb
POSTGRES_INITDB_ARGS: --encoding=UTF-8 --lc-collate=en_US.UTF-8 --lc-ctype=en_US.UTF-8
POSTGRES_MULTIPLE_DATABASES: scancodeio packagedb

jobs:
build:
runs-on: ubuntu-20.04

# services:
# postgres:
# image: postgres:13
# env:
# POSTGRES_DB: ${{ env.POSTGRES_DB }}
# POSTGRES_USER: ${{ env.POSTGRES_USER }}
# POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }}
# POSTGRES_INITDB_ARGS: ${{ env.POSTGRES_INITDB_ARGS }}
# POSTGRES_MULTIPLE_DATABASES: scancodeio:scancodeio:scancodeio
# options: >-
# --health-cmd pg_isready
# --health-interval 10s
# --health-timeout 5s
# --health-retries 5
# ports:
# - 5432:5432
# volumes:
# - ${{ github.workspace }}/etc/multiple-databases:/docker-entrypoint-initdb.d
services:
postgres1:
image: postgres:13
env:
POSTGRES_DB: ${{ env.POSTGRES_DB }}
POSTGRES_USER: ${{ env.POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }}
POSTGRES_INITDB_ARGS: ${{ env.POSTGRES_INITDB_ARGS }}
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

postgres2:
image: postgres:13
env:
POSTGRES_DB: scancodeio
POSTGRES_USER: scancodeio
POSTGRES_PASSWORD: scancodeio
POSTGRES_INITDB_ARGS: ${{ env.POSTGRES_INITDB_ARGS }}
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5433:5432

strategy:
max-parallel: 4
Expand All @@ -46,20 +57,6 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Set up Postgres 13
working-directory: .
run: |
docker run \
--name postgres \
-p 5432:5432 \
-e POSTGRES_USER=${{ env.POSTGRES_USER }} \
-e POSTGRES_PASSWORD=${{ env.POSTGRES_PASSWORD }} \
-e POSTGRES_INITDB_ARGS="${{ env.POSTGRES_INITDB_ARGS }}" \
-e POSTGRES_MULTIPLE_DATABASES="scancodeio packagedb" \
-v ${{ github.workspace }}/etc/multiple-databases:/docker-entrypoint-initdb.d \
-d \
postgres:13
- name: Install dependencies
working-directory: .
run: |
Expand All @@ -68,7 +65,7 @@ jobs:
- name: Run tests
working-directory: .
run: |
make envfile
make envfile_testing
sudo mkdir /etc/scancodeio
sudo cp .env /etc/scancodeio
make test
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ envfile:
@mkdir -p $(shell dirname ${ENV_FILE}) && touch ${ENV_FILE}
@echo SECRET_KEY=\"${GET_SECRET_KEY}\" > ${ENV_FILE}

envfile_testing:
@echo "-> Create the .env file and generate a secret key"
@if test -f ${ENV_FILE}; then echo ".env file exists already"; exit 1; fi
@mkdir -p $(shell dirname ${ENV_FILE}) && touch ${ENV_FILE}
@echo SECRET_KEY=\"${GET_SECRET_KEY}\" >> ${ENV_FILE}
@echo SCANCODEIO_DB_PORT=\"5433\" >> ${ENV_FILE}

isort:
@echo "-> Apply isort changes to ensure proper imports ordering"
${VENV}/bin/isort .
Expand Down

0 comments on commit 7a19e4c

Please sign in to comment.