ehmatthes / django-simple-deploy

A reusable Django app that configures your project for deployment
BSD 3-Clause "New" or "Revised" License
307 stars 26 forks source link

Refactor simple_deploy.py #281

Closed ehmatthes closed 8 months ago

ehmatthes commented 10 months ago

The Fly refactoring work in #269 is going well. It's pointing to some simple_deploy refactoring that I want to keep separate from that issue, because it will affect all platforms.

ehmatthes commented 9 months ago

Documentation update

ehmatthes commented 9 months ago

Testing update

I've been avoiding starting unit tests because I called integration tests unit tests already, and I called e2e tests integration tests. I don't need to wait for renaming those to start actual unit tests.

ehmatthes commented 9 months ago

Working notes

ehmatthes commented 9 months ago

All functions

ehmatthes commented 9 months ago

Writing output

ehmatthes commented 9 months ago

_inspect_project()

ehmatthes commented 9 months ago

Unit testing git status checks

(cont. from above)

ehmatthes commented 9 months ago

Test suite issues

All tests pass in isolation, but suite fails. ie, test_sdlogs_exists() fails. Jumping to the temp dir shows this:

% cd ../../pytest-current/blog_project0    
eric@Erics-Mac-Studio blog_project0 % git status
On branch main
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
    modified:   .gitignore
    modified:   blog/settings.py
    modified:   blog/wsgi.py
    modified:   requirements.txt

Untracked files:
  (use "git add <file>..." to include in what will be committed)
    .dockerignore
    Dockerfile
    fly.toml

no changes added to commit (use "git add" and/or "git commit -a")

That's a bunch of cruft from previous tests that passed:

platform_agnostic_tests/test_git_status_checks.py::test_clean_git_status[req_txt] PASSED                    [  3%]
platform_agnostic_tests/test_git_status_checks.py::test_unacceptable_settings_change[req_txt] PASSED        [  6%]
platform_agnostic_tests/test_git_status_checks.py::test_unacceptable_file_changed[req_txt] PASSED           [ 10%]
platform_agnostic_tests/test_git_status_checks.py::test_sdlogs_exists[req_txt] FAILED                       [ 13%]
ehmatthes commented 9 months ago

More test suite notes

ehmatthes commented 9 months ago

New tests

ehmatthes commented 9 months ago

Git status checks

From a unit test run, this output is failing the git status check:

% git status --porcelain
 M .gitignore
(b_env) eric@Erics-MacBook-Air blog_project0 % git diff --unified=0
diff --git a/.gitignore b/.gitignore
index 9c96d1b..4279ffb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,0 +9,3 @@ db.sqlite3
+
+# Ignore logs from simple_deploy.
+simple_deploy_logs/
ehmatthes commented 9 months ago

Move call to prep_automate_all()

Right now, prep_automate_all() is called from simple_deploy. The only thing after it is adding simple_deploy as a requirement. This is a bunch of complexity with little benefit. The only benefit was not adding simple_deploy as a requirement until after prepping automate-all. But we've already added a log file. People can use Git to undo changes if they decide to abandon simple_deploy.

ehmatthes commented 9 months ago

Final handle() cleanup

ehmatthes commented 9 months ago

_add_poetry_pkg()

ehmatthes commented 9 months ago

Misc cleanup

ehmatthes commented 9 months ago

Parking lot: git status checks

I saw one issue around newlines, with a diff that included a + and - of the same line. I'm not sure if that would be a common thing, or if that was a weird one-off issue. Keep this out for now, but keep it here in case it comes up again.

def test_clean_diff():
    diff_output = dedent(
        """\
        diff --git a/blog/settings.py b/blog/settings.py
        index 6d40136..6395c5a 100644
        --- a/blog/settings.py
        +++ b/blog/settings.py
        @@ -39,0 +40 @@ INSTALLED_APPS = [
        +    'simple_deploy',
        @@ -134 +135 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
        -LOGIN_URL = 'users:login'
        \\ No newline at end of file
        +LOGIN_URL = 'users:login'"""
    )

    cleaned_diff = sd_utils._clean_diff(diff_output.splitlines())
    assert cleaned_diff == ["+    'simple_deploy',"]
def _clean_diff(diff_lines):
    ...
    # Ignore changes that relate to newlines, like this:
    #     -LOGIN_URL = 'users:login'            <-- this line
    #     \\ No newline at end of file
    #     +LOGIN_URL = 'users:login'"""         <--- and this line
    # Remove the + or -, and find any lines that are repeated.
    changes = [l[1:] for l in lines]
    changes_to_remove = [c for c in changes if changes.count(c) == 2]
    lines = [l for l in lines if l[1:] not in changes_to_remove]
ehmatthes commented 9 months ago

Move remaining platform-specific work to platform-specific module

The only platform-specific work that's still being done in simple_deploy is confirming the user wants to use a platform that only has preliminary support. But that work can be done after platform-agnostic work is done. This means all platform-specific work is done entirely in the platform-specific deployer module.

ehmatthes commented 9 months ago

fly automate_all test

ehmatthes commented 9 months ago

Manual run: fly automate_all