Hello,
I am a bit new to this, so apologies if this question is something basic but I have been unable to get a concrete answer.
I am trying to set up CircleCI with a Django app, python3, and I cannot figure out how to configure the test database credentials for circleci.
The app is deployed on Heroku and I have the database credentials referenced as environmental variables in settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': env('DATABASE_NAME'),
'USER': env('DATABASE_USER'),
'PASSWORD': env('DATABASE_PASSWORD'),
'HOST': env('DATABASE_HOST'),
'PORT': env('DATABASE_PORT'),
}
}
My config.yml for circleci:
version: 2.1
jobs:
tests:
docker:
- image: circleci/python:3.7
environment:
DATABASE_URL: postgresql://root@localhost/circle_test?sslmode=disable
- image: circleci/postgres:9.6.2
environment:
POSTGRES_USER: root
POSTGRES_DB: circle_test
steps:
- checkout
- run: sudo chown -R circleci:circleci /usr/local/bin
- run: sudo chown -R circleci:circleci /usr/local/lib/python3.7/site-packages
- restore_cache:
key: deps9-{{ .Branch }}-{{ checksum "requirements.txt" }}
- run:
name: Install Dependencies
command: |
pip3 install --user -r requirements.txt
- save_cache:
key: deps9-{{ .Branch }}-{{ checksum "requirements.txt" }}
paths:
- ".venv"
- "/usr/local/bin"
- "/usr/local/lib/python3.7/site-packages"
- run: python3 manage.py test
workflows:
main:
jobs:
- tests
I am not sure what is supposed to be used for the environmental variables for the test DB, and I can’t seem to find a concrete answer in the docs.
I am getting django.core.exceptions.ImproperlyConfigured: Set the DATABASE_NAME environment variable" does not exist
in my builds. The circleci/postgres:9.6.2-alpine
step is failing, but I don’t know how to configure what the test database credentials should be. The postgres container build is failing as expected.
I’ve also tried adding what I think are the default values:
jobs:
tests:
docker:
- image: circleci/python:3.7
environment:
DATABASE_NAME: circle_test
DATABASE_URL: postgresql://root@localhost/circle_test?sslmode=disable
DATABASE_USER: root
DATABASE_PASSWORD: ''
DATABASE_PORT: 5432
DATABASE_HOST: postgresql://root@localhost/circle_test?sslmode=disable
- image: circleci/postgres:9.6.2
environment:
DATABASE_NAME: circle_test
DATABASE_USER: root
DATABASE_URL: postgresql://root@localhost/circle_test?sslmode=disable
DATABASE_PASSWORD: ''
DATABASE_PORT: 5432
DATABASE_HOST: postgresql://root@localhost/circle_test?sslmode=disable
and get django.db.utils.OperationalError: could not translate host name "postgresql://root@localhost/circle_test?sslmode=disable" to address: Name or service not known