6👍
The SECRET_KEY
variable will be available to all your CI jobs, as configured. However, I don’t see any references to it in your Docker Compose file to pass it to one or more of your services. For the web service to use it, you’d map it in like the other variables you already have.
web:
build: .
command: /usr/local/bin/gunicorn writer.wsgi:application -w 2 -b :8000
environment:
SECRET_KEY: ${SECRET_KEY}
DEBUG: ${DEBUG}
…
As for creating the database, you should wrap up whatever you currently run interactively in the postgres container in a SQL file or shell script, and then bind-mount it into the container’s initialization scripts directory under /docker-entrypoint-initdb.d
. See the Initialization scripts section of the postgres image’s description for more details.
6👍
In my experience the best way to pass environment variables to a container docker is creating an environment file, which works to development environment and production environment:
You must create an environment file on GitLab CI/CD, following the next steps, on your project GitLab you must go to:
settings
> CI/CD
> Variables
on that you must create a ENV_FILE
Demo image
Next on your build stage in .gitlab-ci.yml
copy the ENV_FILE to local process
.gitlab-ci.yml
build:
stage: build
script:
- cp $ENV_FILE .env
- echo "Building the app"
- docker-compose build
your Dockerfile
should be stay normally so it doesn’t have to change
Dockerfile
FROM python:3.8.6-slim
# Rest of setup goes here...
COPY .env .env
- Django/Celery multiple queues on localhost – routing not working
- How to access form data in `FormView.get_success_url()`
- How to resolve the "psycopg2.errors.UndefinedTable: relation "auth_user" does not exist" when running django unittests on Travis
- Setting default value for integer field in django models
- Django Rest Framework: Output in JSON to the browser by default
0👍
In order for compose variable substitution to work, when the user is not added to docker group, you must add the -E flag to sudo.
script:
- sudo -E docker-compose build
- Redirect from Generic View DetailView in Django
- Django signals for new entry only
- Does Django cache related ForeignKey and ManyToManyField fields once they're accessed?
- How to make Django's "DATETIME_FORMAT" active?