Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved support for different project layouts. #92

Closed

Conversation

StuartMacKay
Copy link
Contributor

The current project layout assumes manage.py wsgi.py and the requirements
file can be found in the root directory of the project. You can override
this by editing paths in roles/web/defaults/main.yml but this means digging
around in the internals of the project. It would be much nice if all the
user editable parts were restricted to the env_var directory.

The solution was to a "Project layout" section in env_vars/base.yml where
the paths, relative to the root of the project can be defined. Since the
requirements are often environment specific the relative path was also
defined in env_vars/vagrant.yml and env_vars/development.yml so it can
be overridden as needed.

In roles/web/defaults/main.yml the definition for reuirements_file was
changed to use the relative path and a new variable, django_path, was
added, allowing the location of manage.py and wsgi.py to be decoupled
from project_path. This gives more flexibility if the user still needs
to go in and edit this file to match their project layout.

NOTE: the changes to roles/web/defaults/main.yml are sufficient to support
different layouts but creating the relative paths is useful so only the
env_vars files need to be edited.

The current project layout assumes manage.py wsgi.py and the requirements
file can be found in the root directory of the project. You can override
this by editing paths in roles/web/defaults/main.yml but this means digging
around in the internals of the project. It would be much nice if all the
user editable parts were restricted to the env_var directory.

The solution was to a "Project layout" section in env_vars/base.yml where
the paths, relative to the root of the project can be defined. Since the
requirements are often environment specific the relative path was also
defined in env_vars/vagrant.yml and env_vars/development.yml so it can
be overridden as needed.

In roles/web/defaults/main.yml the definition for reuirements_file was
changed to use the relative path and a new variable, django_path, was
added, allowing the location of manage.py and wsgi.py to be decoupled
from project_path. This gives more flexibility if the user still needs
to go in and edit this file to match their project layout.

NOTE: the changes to roles/web/defaults/main.yml are sufficient to support
different layouts but creating the relative paths is useful so only the
env_vars files need to be edited.
@cypreess
Copy link

cypreess commented Apr 4, 2018

+1

I was just going to commit something similar

Ps. Why are those tests failing?

@StuartMacKay
Copy link
Contributor Author

StuartMacKay commented Jun 6, 2018

From the log output it appears that the following task: TASK [web : Create (or retain) the application log file] timed out. The path to the application log directory is defined as: application_log_dir: "{{ virtualenv_path }}/logs" and this PR did not change anything in this area so it is likely that the build failed because of some other error rather than due to a change in the PR. Since I don't have write access to the project on Travis I'll close this PR and reopen it to trigger a new build and see if the error occurs again.

@StuartMacKay
Copy link
Contributor Author

Reopened to trigger build on Travis.

@StuartMacKay StuartMacKay reopened this Jun 6, 2018
@StuartMacKay
Copy link
Contributor Author

Build errored out once more as a result of a timeout. Closing and re-opening once more.

@StuartMacKay StuartMacKay reopened this Jun 6, 2018
@YPCrumble
Copy link
Collaborator

@StuartMacKay yeah that's definitely what happened regarding the tests. Molecule v2 is out so it's possible that addressing #78 might make it run faster. In general though this requires configuring a server twice to ensure idempotence so it's going to be a long process no matter what.

Looks like they're both passing now 👍

# requirements.txt can be found in the root directory of the project.
# Override this value in env_vars/vagrant.yml and/or env_vars/development.yml
# if you have different requirements for each environment.
requirements_relative_file: ./requirements_local.txt
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@StuartMacKay shouldn't this be requirements.txt? requirements_local.txt is specific to the Vagrant box I believe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had requirements.txt previously but the tests failed as a result. They are expecting django-debug-toolbar to be installed and that is defined in requirements_local.txt. See https://travis-ci.org/jcalazan/ansible-django-stack/builds/388667191


# Uncomment and change this if you have specific requirements when
# running the app on the Vagrant VM.
# requirements_relative_file: "./requirements_local.txt"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@StuartMacKay same issue here - shouldn't this be uncommented?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the commented out variables to development.yml and vagrant.yml so that you'd have the option to override the default in base.yml for local development.

To run the playbook I have a JSON file with all the variables I need and pass it on the command line using --extra-vars="@.json". That neatly solves the problem with Ansible vast and complicated precedence rules.

As a result I am not sure that having extra definitions that can be selectively uncommented make any sense. I'm happy with any change you want here.

@YPCrumble
Copy link
Collaborator

@StuartMacKay I'm working on a fix to #78 which I'm hoping will help with the TravisCI suite failing. I added in particular this question on StackOverflow as it seems the copy command is always what's hanging the test suite up. The issue is also happening on my local machine so I don't think it's a TravisCI issue.

Will come back to this once that's done. cc @jcalazan

@StuartMacKay
Copy link
Contributor Author

There are only really four points of contact between this project and a django application:

  1. The location of the requirements file
  2. The settings module, e.g. "project.settings.prod"
  3. The WSGI module, e.g. "project.wsgi"
  4. The path to MEDIA_ROOT, STATIC_ROOT directories.

All of these are easily overridden by passing in extra vars on the command line when running the playbooks:

ansible-playbook -i myapp site.yml --extra-vars="@myapp.json" 

As a result changes in this PR are not really required and I am closing it.

@StuartMacKay StuartMacKay deleted the django-project-layout branch November 8, 2020 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants