Hello guys working with pipeline that suppose to run tox (that runs tests, flake, black...). As you can see in my code snipped. I am creating postgres service. Additionally I try to run everything on container "harbor.com/my-base-container-with-code-base" that is very important for all repos in matrix to be able to run tests. And also test needs to connect to postgre database service which has db setup. So far I know that service is probably working fine. And container is also working. But I am not sure they connect to each other. I suspect that when source setup.sh and source setup_tests.sh that postgres service is still not starting? Not sure. Below code I will also post a error that I have. So think those options of postgre should cover the waiting till it start buts..... posting errors too. Maybe some of you had similar issues or has a good knowkedge if this?
run_tox_tests:
name: ${{ matrix.project_name }} app tests
runs-on: ubuntu-latest
container:
image: harbor.com/my-base-container-with-code-base
credentials:
username: stackoverflew
password: ${{ secrets.SOMEPW }}
services:
postgres:
image: postgres:14-alpine
env:
POSTGRES_USER: ${{ secrets.testPgUser }}
POSTGRES_PASSWORD: ${{ secrets.testPgPw }}
POSTGRES_DB: ${{ secrets.testPgDb }}
POSTGRES_HOST: ${{ secrets.testPgHost }}
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
needs: [set_variables]
strategy:
matrix: ${{fromJson(needs.set_variables.outputs.build_data)}}
steps:
- uses: actions/checkout@v2
with:
repository: ${{ matrix.project_repo }}
token: ${{ secrets.AUTH_REPO_TOKEN}}
# - uses: "actions/setup-python@v2"
# with:
# python-version: 3.8
- name: Install dependencies
env:
TEST_PGDATABASE: ${{ secrets.testPgDb }}
TEST_PGHOST: ${{ secrets.testPgHost }}
TEST_PGUSER: ${{ secrets.testPgUser }}
TEST_PGPASSWORD: ${{ secrets.testPgPw }}
run: |
yarn start &
sleep 10 &&
curl http://postgres:5432 &&
yarn test
python -m pip install --upgrade pip tox
python -m pip install tox-docker
# python -m pip install tox tox-gh-actions
# pip install alembic
pip install -r requirements.txt
chmod +x setup.sh
chmod +x setup_tests.sh
./setup.sh
./setup_tests.sh
- name: Run tox
run: tox
- name: Upload Code coverage
uses: codecov/codecov-action@v3
with:
directory: .tox/htmlcov/
some of the error:
.
.
.
.
.
.
.
.
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Cannot assign requested address
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
.
.
.
.
.sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Cannot assign requested address
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
(Background on this error at: https://sqlalche.me/e/14/e3q8)
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1799, in _execute_context
self.dialect.do_executemany(
File "/usr/local/lib/python3.8/site-packages/sqlalchemy/dialects/***ql/psycopg2.py", line 951, in do_executemany
context._psycopg2_fetched_rows = xtras.execute_values(
File "/usr/local/lib/python3.8/site-packages/psycopg2/extras.py", line 1270, in execute_values
cur.execute(b''.join(parts))
psycopg2.errors.UndefinedTable: relation "test_table" does not exist
LINE 1: INSERT INTO test_table (account_name, account_number, c...
^
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "test_db/models.py", line 127, in <module>
create_session()
File "test_db/models.py", line 123, in create_session
session.commit()
.
.
.
cur.execute(b''.join(parts))
sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedTable) relation "test_table" does not exist
LINE 1: INSERT INTO test_table (account_name, account_number, c...
so what happens is at first it has problems connecting then we have an insert problem.
Heres a content of setup.sh
mkdir migrations/versions
alembic revision --autogenerate -m "Generate test data"
alembic upgrade heads
python test_db/models.py
What it does, it creates a migrations that suppose to create table "test_table" as you can see in errors and also it performs an insert. On local machine I do these exact steps I have empty db setup on localhost, I run this script and then I run tox and it seems to do the job, trying to understand what the problem might be to do those steps on github action