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

feat(assets): Adds component page and Tailwind support to CL #4931

Merged

Conversation

leohentschker
Copy link
Contributor

TLDR: Adds tailwind support to CourtListener

  1. Adds a new target to the Dockerfile that enables building CSS
  2. Adds the django-tailwind and django_browser_reload (in dev only) extensions
  3. Adds in a private component page to preview contents
    image

@leohentschker leohentschker marked this pull request as draft January 15, 2025 22:23
@leohentschker leohentschker changed the title Fresh PR with component page and tailwind enablement (Draft) PR with component page and tailwind enablement Jan 15, 2025
@leohentschker
Copy link
Contributor Author

FYI @ERosendo -- draft PR here, I'll work through the CI failures and get things working!

@ERosendo ERosendo self-requested a review January 16, 2025 22:05
@ERosendo ERosendo self-assigned this Jan 16, 2025
Comment on lines 73 to 77
FROM python-base AS tailwind-reload
CMD python /opt/courtlistener/manage.py tailwind install --no-input && \
python /opt/courtlistener/manage.py tailwind start --no-input

FROM python-base as web-dev
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to remove these lines. In #3134, we moved from a multi stage dockefile to a single image containing a helper script (docker-entrypoint.sh) that can be used to launch the different processes depending for different types of containers.

cl-django:
container_name: cl-django
build:
context: "${CL_BASE_DIR:-../../}"
dockerfile: "./docker/django/Dockerfile"
target: web-dev
Copy link
Contributor

@ERosendo ERosendo Jan 16, 2025

Choose a reason for hiding this comment

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

We can remove the target field. The combination of the command key and the ENTRYPOINT instruction within the Dockerfile effectively manages the execution of our various services.

cl/package.json Outdated
Comment on lines 13 to 20
"scripts": {
"start": "npm run dev",
"build": "npm run build:clean && npm run build:tailwind",
"build:clean": "rimraf ../static/css/tailwind_styles.css",
"build:tailwind": "cross-env NODE_ENV=production tailwindcss --config ./simple_pages/static_src/tailwind.config.js -i ./simple_pages/static_src/src/input.css -o ./assets/static-global/css/tailwind_styles.css --minify",
"dev": "cross-env NODE_ENV=development tailwindcss --config ./simple_pages/static_src/tailwind.config.js -i ./simple_pages/static_src/src/input.css -o ./assets/static-global/css/tailwind_styles.css -w",
"tailwindcss": "node ./node_modules/tailwindcss/lib/cli.js"
},
Copy link
Contributor

Choose a reason for hiding this comment

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

I really liked what you did here.

I noticed that Django-tailwind often introduces an extra package.json and node_modules folder, which can sometimes complicate things. I appreciate your effort to streamline this by centralizing the commands within our existing package.json.

We were also considering moving input.css and tailwind.config.js to the assets folder for better organization. However, we encountered some errors when using the Django-tailwind commands.

can you please move these Tailwind-related files from the simple_pages folder to the assets folder and update the commands accordingly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call, done!

Comment on lines 3 to 4
// TODO: Convert this to a glob pattern
'simple_pages/templates/components.html',
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's try using the global patterns from the beginning. I believe this will enhance our collaborative workflow. Since these patterns are general, this file won't require frequent updates with each new Tailwind component or page added in PR.

These are the patterns we use in the Big Cases Bot project:

module.exports = {
    content: [
        /**
         * HTML. Paths to Django template files that will contain Tailwind CSS classes.
         */

        /*  Templates within theme app (<tailwind_app_name>/templates), e.g. base.html. */
        '../templates/**/*.html',

        /*
         * Main templates directory of the project (BASE_DIR/templates).
         * Adjust the following line to match your project structure.
         */
        '../../templates/**/*.html',

        /*
         * Templates in other django apps (BASE_DIR/<any_app_name>/templates).
         * Adjust the following line to match your project structure.
         */
        '../../**/templates/**/*.html',
        '../../**/templates/**/*.svg',
    ],
}

We might need to take another look at those patterns after we consider the changes in https://github.com/freelawproject/courtlistener/pull/4931/files#r1919396611

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! I believe this is still working.

@ERosendo
Copy link
Contributor

Since there's no code currently added to the docker-entrypoint.sh file, here's a suggestion for what you could include as the tailwind-reload entry:

...
'web-dev')
    python /opt/courtlistener/manage.py migrate
    python /opt/courtlistener/manage.py createcachetable
    exec python /opt/courtlistener/manage.py runserver 0.0.0.0:8000
    ;;
+'tailwind-reload')
+   npm ci --prefix ./cl
+   exec npm run start --prefix ./cl --loglevel=verbose
+   ;;

Copy link
Contributor

@ERosendo ERosendo left a comment

Choose a reason for hiding this comment

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

Hey @leohentschker, I've added some initial comments to your code. I believe that addressing these should resolve the current CI failures.

Please let me know when you're ready for another review.

@ERosendo ERosendo linked an issue Jan 17, 2025 that may be closed by this pull request
@mlissner
Copy link
Member

Looking good. Nice to see this advancing!

@leohentschker
Copy link
Contributor Author

Great on it @ERosendo ! Will have a PR for review for tomorrow AM.

@leohentschker leohentschker force-pushed the DEV-add-tailwind-support-to-cl branch from b2ea241 to a159b34 Compare January 23, 2025 14:08
@leohentschker
Copy link
Contributor Author

TLDR: Turn complete on feedback from @ERosendo , a few questions remaining before I would feel comfortable merging this in

  • How do styles get built and served in prod? Anything I could be pointed to / should we seek to address that in this PR (I also did some digging and don't see how this works on webpack)? My thought would be to add in an additional compose service for the prod build and add this as a requirement for cl-django.
  • Are we comfortable mirroring how we specified the webpack command in docker-compose instead of adding to the docker-entrypoint.sh file?
  • Let me know if I should make a fresh PR with collapsed changes post approval for git cleanliness

@ERosendo ERosendo marked this pull request as ready for review January 23, 2025 14:59
@ERosendo ERosendo changed the title (Draft) PR with component page and tailwind enablement PR with component page and tailwind enablement Jan 23, 2025
@ERosendo ERosendo changed the title PR with component page and tailwind enablement feat(assets): Adds component page and Tailwind support to CL Jan 23, 2025
@ERosendo
Copy link
Contributor

ERosendo commented Jan 23, 2025

@leohentschker I've updated the PR to resolve the merge conflict. I'll review your code shortly.

Thank you for addressing the comments and making the necessary changes.

@ERosendo
Copy link
Contributor

Let me know if I should make a fresh PR with collapsed changes post approval for git cleanliness

We can squash the changes in this PR into a single commit

@ERosendo
Copy link
Contributor

@mlissner Here's a gif showing hot-reloading and Tailwind in action in CL:

Screen Recording 2025-01-23 at 1 24 32 PM

Thanks @leohentschker

Copy link
Contributor

@elisa-a-v elisa-a-v left a comment

Choose a reason for hiding this comment

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

I tested it and the hot reload is very responsive and fast, and works both when changing the templates and when modifying the tailwind.config.js file, so that's pretty handy.

The only (very minor!) thing is I personally don't like it when the browser refreshes automatically because I've found myself needing to compare the same page in two different versions side-by-side, so I like to have control over when I see the new changes, but that's just personal preference. If y'all prefer it this way I say :shipit:

All in all, I love this, thank you @leohentschker ! this will be sooo useful in the upcoming weeks 🙌🏽

@ERosendo ERosendo enabled auto-merge (squash) January 23, 2025 21:24
@ERosendo ERosendo merged commit 8133a33 into freelawproject:main Jan 23, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Add tailwind to dev and prod environments for CourtListener
4 participants