From 59cd5b4849a384f168740f0cd11072c99d4ea1cb Mon Sep 17 00:00:00 2001 From: Nikita Shupeyko Date: Tue, 27 Mar 2018 18:40:44 +0300 Subject: [PATCH] Celery code blocks are still generated even though Celery is not opted out for (#1587) * Celery jinja condition in .gitignore * Celery jinja conditions in Django Dockerfiles * Re-phrase Django Dockerfile requirements comments * Remove celery compose dirs through post_gen_project.py --- hooks/post_gen_project.py | 6 ++++++ {{cookiecutter.project_slug}}/.gitignore | 2 ++ .../compose/local/django/Dockerfile | 6 +++--- .../compose/production/django/Dockerfile | 6 +++--- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index 4c987cd1..2ad936a9 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -254,6 +254,11 @@ def remove_celery_envs(): os.remove(os.path.join('.envs', '.production', '.celery')) +def remove_celery_compose_dirs(): + shutil.rmtree(os.path.join('compose', 'local', 'django', 'celery')) + shutil.rmtree(os.path.join('compose', 'production', 'django', 'celery')) + + def main(): postgres_user = generate_postgres_user() set_flags_in_envs(postgres_user) @@ -318,6 +323,7 @@ def main(): remove_celery_app() if '{{ cookiecutter.use_docker }}'.lower() == 'y': remove_celery_envs() + remove_celery_compose_dirs() if '{{ cookiecutter.use_travisci }}'.lower() == 'n': remove_dottravisyml_file() diff --git a/{{cookiecutter.project_slug}}/.gitignore b/{{cookiecutter.project_slug}}/.gitignore index 52e8c444..f3f92da2 100644 --- a/{{cookiecutter.project_slug}}/.gitignore +++ b/{{cookiecutter.project_slug}}/.gitignore @@ -62,8 +62,10 @@ target/ # pyenv .python-version +{% if cookiecutter.use_celery == 'y' -%} # celery beat schedule file celerybeat-schedule +{%- endif %} # Environments .venv diff --git a/{{cookiecutter.project_slug}}/compose/local/django/Dockerfile b/{{cookiecutter.project_slug}}/compose/local/django/Dockerfile index c4338109..90e3b693 100644 --- a/{{cookiecutter.project_slug}}/compose/local/django/Dockerfile +++ b/{{cookiecutter.project_slug}}/compose/local/django/Dockerfile @@ -15,7 +15,7 @@ RUN apk update \ # https://docs.djangoproject.com/en/2.0/ref/django-admin/#dbshell && apk add postgresql-client -# Requirements have to be pulled and installed here, otherwise caching won't work +# Requirements are installed here to ensure they will be cached. COPY ./requirements /requirements RUN pip install -r /requirements/local.txt @@ -26,7 +26,7 @@ RUN chmod +x /entrypoint.sh COPY ./compose/local/django/start.sh /start.sh RUN sed -i 's/\r//' /start.sh RUN chmod +x /start.sh - +{% if cookiecutter.use_celery == "y" %} COPY ./compose/local/django/celery/worker/start.sh /start-celeryworker.sh RUN sed -i 's/\r//' /start-celeryworker.sh RUN chmod +x /start-celeryworker.sh @@ -34,7 +34,7 @@ RUN chmod +x /start-celeryworker.sh COPY ./compose/local/django/celery/beat/start.sh /start-celerybeat.sh RUN sed -i 's/\r//' /start-celerybeat.sh RUN chmod +x /start-celerybeat.sh - +{% endif %} WORKDIR /app ENTRYPOINT ["/entrypoint.sh"] diff --git a/{{cookiecutter.project_slug}}/compose/production/django/Dockerfile b/{{cookiecutter.project_slug}}/compose/production/django/Dockerfile index 2ded8253..e8d2e0fc 100644 --- a/{{cookiecutter.project_slug}}/compose/production/django/Dockerfile +++ b/{{cookiecutter.project_slug}}/compose/production/django/Dockerfile @@ -14,7 +14,7 @@ RUN apk update \ RUN addgroup -S django \ && adduser -S -G django django -# Requirements have to be pulled and installed here, otherwise caching won't work +# Requirements are installed here to ensure they will be cached. COPY ./requirements /requirements RUN pip install --no-cache-dir -r /requirements/production.txt \ && rm -rf /requirements @@ -28,7 +28,7 @@ COPY ./compose/production/django/entrypoint.sh /entrypoint.sh RUN sed -i 's/\r//' /entrypoint.sh RUN chmod +x /entrypoint.sh RUN chown django /entrypoint.sh - +{% if cookiecutter.use_celery == "y" %} COPY ./compose/production/django/celery/worker/start.sh /start-celeryworker.sh RUN sed -i 's/\r//' /start-celeryworker.sh RUN chmod +x /start-celeryworker.sh @@ -36,7 +36,7 @@ RUN chmod +x /start-celeryworker.sh COPY ./compose/production/django/celery/beat/start.sh /start-celerybeat.sh RUN sed -i 's/\r//' /start-celerybeat.sh RUN chmod +x /start-celerybeat.sh - +{% endif %} COPY . /app RUN chown -R django /app