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

Added webpack to the HQ deploy process #6284

Merged
merged 5 commits into from
May 10, 2024
Merged

Added webpack to the HQ deploy process #6284

merged 5 commits into from
May 10, 2024

Conversation

mjriley
Copy link
Contributor

@mjriley mjriley commented May 5, 2024

Associated ticket: https://dimagi.atlassian.net/browse/SAAS-15485

Adds support for running webpack while deploying HQ, if a webpack configuration file is found. This is not currently required by any live code, but allows us to test react and vue (and other javascript features) in the future

Environments Affected
Announce New Release
  • After merging, I will follow these instructions
    to announce a new commcare-cloud release.

tasks:
- import_role: {name: deploy_hq}
vars:
if_not_done: run_webpack
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think of adding the tasks in this file to staticfiles_collect.yml file? It would reduce deploy overhead to group them together since they are applied to the same set of hosts. This is doing the same kind of thing as other staticfiles collection tasks, so I think it makes sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is the primary motivation to reduce overhead or to create natural groups? From running this deploy process on staging, I don't think overhead should be a concern -- the webworkers task executed very quickly. The bottleneck is the compilejs18n command from staticfiles_collect.yml. If the motivation is instead to create natural groups, I'd argue that this grouping has the potential to create a lot of confusion. Webpack doesn't collect any static files. Instead, it is generally known as the step to compress/minify, and our dedicated "Compress static files" task lives outside of "Collect static files". I also wouldn't recommend combining tasks just because they use the same hosts. I suppressed a warning by including webworkers here, but in my head, this should really only be deployed to proxy servers.

If we wanted to split off a playbook dedicated to javascript tasks, that would make sense, but I think dedicated tasks for webpack make sense

Copy link
Contributor

Choose a reason for hiding this comment

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

The overhead I'm speaking of is SSH connections made by Ansible, not the time it takes to actually run webpack.

staticfiles_collect.yml is where we do other js-related build steps (example: build_requirejs), so I think it makes sense to put webpack in there too since that is the same type of task.

Copy link
Contributor Author

@mjriley mjriley May 9, 2024

Choose a reason for hiding this comment

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

I've updated the associated ticket with logs from 2 runs to compare what changes when webpack is run from the deploy_hq task vs from within staticfiles_collect. I don't believe there is any difference with respect to SSH connections. From what I can tell, ansible will create connections for every task, and it is thus advised to configure SSH to re-use connections.

I continue to believe that moving webpack to staticfiles_collect would be confusing. Collecting into static is django terminology. I think it's unintuitive that we're building requireJS in this playbook, and I don't think we should double down here. Webpack deserves its own task file because it is capable of much more than collecting, and those responsibilities may not align with the same hosts that collecting does. In addition, it is essentially in feature-flag status at the moment. Including it as I'm doing minimizes log output for runs that do not use webpack.

Copy link
Contributor

@millerdev millerdev May 9, 2024

Choose a reason for hiding this comment

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

Looks like there would be two extra SSH connections (Check if done: run_webpack and the corresponding Completed: run_webpack) when run_webpack.yml is included via a separate block in this file. Admittedly not much overhead, but it's something.

For me putting it together with other tasks doing similar things (currently in staticfiles_collect.yml) is the more important point since that's where people who are familiar with the existing structure would go to look for that type of task. I could see an argument for renaming staticfiles_collect.yml to something more generic that includes JS bundling. Adding another top-level block in this file seems overkill for a feature flagged experiment.

Copy link
Contributor

Choose a reason for hiding this comment

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

Noting that build_requirejs is the last task in staticfiles_collect.yml, I think because it depends collectstatic. Is there any chance (now or in the future) that webpack could also depend on collectstatic being run first?

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 looked at this, and I'm not entirely sure why requireJS runs after collectstatic. That said, webpack is creating artifacts that django will later serve, so those artifacts should be created before static assets are collected. I previously modified the webpack configuration such that webpack is able to follow django app paths, thus it looks for the location of files before collecting them into a single static folder

Copy link
Contributor

@millerdev millerdev left a comment

Choose a reason for hiding this comment

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

Approving since this is functional, although as noted in the comments, I disagree on adding a new tasks block in deploy_hq.yml.

@mjriley mjriley merged commit 57eb7a0 into master May 10, 2024
2 checks passed
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.

2 participants