fix(Docker): #PRWLR-4781 fix docker environment issues and celery worker container connection (#37)

* build(Dockerfile): PRWLR-4781 remove versions from dockerfile deps

* fix(Docker): PRWLR-4781 fix celery worker container and apply dev fixtures by default

* build(docker-compose): PRWLR-4781 set default django settings to production in worker service
This commit is contained in:
Víctor Fernández Poyatos
2024-09-09 15:52:06 +02:00
committed by GitHub
parent ec67fc12e0
commit c3346ff605
6 changed files with 21 additions and 6 deletions
+4 -2
View File
@@ -2,7 +2,8 @@ FROM python:3.12-alpine AS build
LABEL maintainer="https://github.com/prowler-cloud/api"
RUN apk --no-cache add gcc=13.2.1_git20240309-r0 python3-dev=3.12.3-r1 musl-dev=1.2.5-r0 linux-headers=6.6-r0 curl-dev=8.9.0-r0
# hadolint ignore=DL3018
RUN apk --no-cache add gcc python3-dev musl-dev linux-headers curl-dev
RUN apk --no-cache upgrade && \
addgroup -g 1000 prowler && \
@@ -32,7 +33,8 @@ WORKDIR /home/prowler/backend
FROM build AS dev
USER 0
RUN apk --no-cache add curl=8.9.0-r0 vim=9.1.0414-r0
# hadolint ignore=DL3018
RUN apk --no-cache add curl vim
USER prowler
+2
View File
@@ -86,6 +86,8 @@ services:
build:
dockerfile: Dockerfile
image: prowler-worker
environment:
- DJANGO_SETTINGS_MODULE=config.django.production
env_file:
- path: ./.env
required: false
+13 -2
View File
@@ -6,6 +6,16 @@ apply_migrations() {
poetry run python manage.py migrate --database admin
}
apply_fixtures() {
echo "Applying Django fixtures..."
for fixture in api/fixtures/*.json; do
if [ -f "$fixture" ]; then
echo "Loading $fixture"
poetry run python manage.py loaddata "$fixture" --database admin
fi
done
}
start_dev_server() {
echo "Starting the development server..."
poetry run python manage.py runserver 0.0.0.0:"${DJANGO_PORT:-8080}"
@@ -17,13 +27,14 @@ start_prod_server() {
}
start_worker() {
echo "Starting the development worker..."
poetry run python -m celery -A config.celery worker -l "${DJANGO_LOGGING_LEVEL:-info}"
echo "Starting the worker..."
poetry run python -m celery -A config.celery worker -l "${DJANGO_LOGGING_LEVEL:-info}" -E
}
case "$1" in
dev)
apply_migrations
apply_fixtures
start_dev_server
;;
prod)
+2 -2
View File
@@ -1,7 +1,7 @@
from config.env import env
VALKEY_HOST = env("VALKEY_HOST", default="valkey-db")
VALKEY_PORT = env("VALKEY_PORT", default="6479")
VALKEY_HOST = env("VALKEY_HOST", default="valkey")
VALKEY_PORT = env("VALKEY_PORT", default="6379")
VALKEY_DB = env("VALKEY_DB", default="0")
CELERY_BROKER_URL = f"redis://{VALKEY_HOST}:{VALKEY_PORT}/{VALKEY_DB}"