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

Migrate client-admin from gulp to webpack #1242

Merged
merged 40 commits into from Dec 2, 2022

Conversation

patcon
Copy link
Contributor

@patcon patcon commented Dec 6, 2021

Addresses #90

This is a work-in-progress, but could use some feedback on approach :)

Current status:

  • removed gulp
  • replaced gulp with webpack build
  • since gulp gone, upgraded Node from v11.15.0 to v14.14.0
  • npm run build:dev exists for unminified/uncompressed builds into dist/
  • npm run build:prod exists for minified/compressed builds (as required for file-server)
  • bundle analysis possible with npm run analyze
  • removed extraneous files
  • removed deploy for s3 (I can bring this back, as I know how to do it with webpack from Demo: client-admin using razzle with customizations #515)
  • figure out what's wrong with e2e test on CI
    • all admin tests were failing
    • 2 embed/integration tests failing
  • Figure out why bundlesize jumped from 175 kb => 210 kb ish
  • local dev server working with webpack-dev-server
  • Update README

The tests should pass with this 🎉 🤞

Open Questions

  1. Is it alright to abandon S3 deploy code from gulp? My understanding is that production deploy is now done with docker-compose, right?

EDIT: I have feature parity for "webpack-based s3 deploy" code already written, so it's just a matter of copy-pasting it in here if we want to keep it

@metasoarous metasoarous changed the title Migrate client-admin from gulp to webpage Migrate client-admin from gulp to webpack Dec 7, 2021
@patcon
Copy link
Contributor Author

patcon commented Dec 7, 2021

Hm. The admin interface is working fine when I do a docker build locally, but failing when run in CI. Not sure what's up.

@patcon patcon self-assigned this Dec 7, 2021
@patcon patcon marked this pull request as draft December 7, 2021 01:05
@metasoarous metasoarous added this to In progress in Polis Development via automation Dec 7, 2021
@brendanarnold
Copy link
Contributor

Thanks @metasoarous I havn't actually run this code yet - I'm working on getting a fork of pol.is up and running and I have the participant and admin code compiling and running OK so I can try with these changes in - I'll let you know how I get on.

"build:webpack_unminified": "npm run clean && NODE_ENV=development webpack --config webpack.config.unminified.js",
"build": "npm run build:webpack",
"build-debug": "npm run build:webpack_unminified",
"deploy:prod": "node gulpfile.js deploy_TO_PRODUCTION",
Copy link
Contributor

Choose a reason for hiding this comment

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

I did a test merge of this into the compdemocracy/dev branch, but I ran into this error when trying build with docker compose due to the removal of deploy:prod:

Step 11/42 : RUN npm run deploy:prod
 ---> Running in e2442f4e8746
npm ERR! missing script: deploy:prod
npm ERR! 
npm ERR! Did you mean this?
npm ERR!     build:prod

I see that client-admin/Dockerfile has been updated to use build:prod instead of deploy:prod, but it looks like when I am building it must be running either Dockerfile or file-server/Dockerfile, which both use deploy:prod and still reference node:11.15.0-alpine.

From looking at the docker-compose.yml file I think that it might be the file-server/Dockerfile that is making client-admin instead of client-admin/Dockerfile. I might just be doing something wrong when I build it, but it still might be good to remove gulp from the sections of Dockerfile and file-server/Dockerfile that relate to building client-admin so that they are all consistent

Copy link
Member

Choose a reason for hiding this comment

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

The problem is that there is some duplication of efforts in the client build process, as you note, between the file-server/Dockerfile and the individual client Dockerfiles. We duplicated this work into the client-server/Dockerfile to avoid issues with Dockerfiles referencing each other in certain build environments (Heroku, podman). I think we want to try and consolidate these if possible, potentially via multi-stage builds, but we shouldn't hang this PR up on that. We should however continue to keep all of the Dockerfiles up to date, and switch everything over to build:prod (vs deploy:prod). So, thanks for catching this.

@@ -16,7 +16,7 @@ COPY . .
COPY fs_config.template.json fs_config.json

RUN mkdir /app/build
COPY --from=admin /app/build/ /app/build
COPY --from=admin /app/dist/ /app/build
Copy link
Member

Choose a reason for hiding this comment

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

@patcon Let's please keep the app/build path. I realize the way things were set up was kind of weird in that by default things were going to dist, unless you specified build in the LOCAL_OUPUT_PATH, but we should stick with the ultimate paths which were in use at the Docker level (app/build).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, should be some small changes in webpack config and maybe places like gitignore (sorry, forget lots of what's done here atm)

@metasoarous
Copy link
Member

metasoarous commented Oct 11, 2022

Hey @patcon. Are you still interested in pushing this PR forward? Getting rid of gulp and upgrading node environment remains high priority for us, and there are an increasing number of issues blocked on it, so I want to try to get this resolved.

From what I can tell, here's what we need to merge:

  • Right now, the PR is out of date, and needs to be rebased or merged onto edge.
  • We'd like to go straight to Node 18 if possible; Node 14 leaves us with duplicate review work down the road.
  • Ideally, apply the same treatment to the report client.
  • Get output paths in line with what has previously been expected.
  • Generally respond to any of the line comments above which need to be addressed.

I'm also curious why you moved a number of files into a public folder. Unless there is a good reason for this, please also revert these changes.

Thanks again

@patcon
Copy link
Contributor Author

patcon commented Oct 13, 2022

I'm open to this! Thanks for the poke @metasoarous

We'd like to go straight to Node 18 if possible; Node 14 leaves us with duplicate review work down the road.

That's likely quite a lot of further work, as many more deps will need to be tweaked, which will probably require other changes to codebase and maybe even substituted packages, and we'll probably want more tests for that. I worry I won't have time for the level of work that will entail, as it will be much more than just resolving a few merge conflicts imho

I could offer maybe 1-2h of exploration, but if it takes more than that, I'd ask that we merge without (or someone else runs with this PR).

If it's not simple, might you consider merging this smaller v14 node bump, just enough to use webpack, and push the other major upgrade into a separate upgrade cascade?

I'm also curious why you moved a number of files into a public folder. Unless there is a good reason for this, please also revert these changes.

Context: public is a standard known place in react projects (and many other JS frameworks) in which to keep files that are not built into the react app, but instead served statically, usually just copied into build dir. Nothing from that dir will be compiled by webpack, so it signals to developers that "hey, no need to look in here. these are static files that webpack doesn't build from". It's a nice assurance that is lost when webpack doesn't have that place. I suspect it also means exceptions must be added to keep content hashes from being added.

Might you reconsider a request to let it in? I believe it adds value, is a widely-understood convention, and not using it would make things slightly more confusing and explicit. I suspect if you did a straw poll with react devs, they'd all recommend using a public/ dir (and i suppose that as something easily done with an @mention here or quick twitter msg 🙂 ).

@patcon
Copy link
Contributor Author

patcon commented Oct 13, 2022

Ideally, apply the same treatment to the report client.

I'd request that this be another PR, as a matter of respect to the time I've already spent 🙏

@metasoarous
Copy link
Member

metasoarous commented Oct 19, 2022

Thanks for getting back on this @patcon. All fair points.

If you could then please:

Thanks again!

@patcon
Copy link
Contributor Author

patcon commented Oct 19, 2022

Woooo excited to find time for this. Thanks man

@metasoarous
Copy link
Member

Hey @patcon. Any updates on this?

We have a number of other issues blocked on it, so I'd like to get a sense of whether you're still keen to push through to completion. If you're not able to right now, that's fine; I can pick it up from here, but wanted to give you the opportunity to wrap it up first.

Please let me know either way when you get a chance.

Thanks!

@patcon
Copy link
Contributor Author

patcon commented Nov 16, 2022

Hey Chris, sorry, been busy with some event stuff. I'm going to give myself until this weekend, after which I should officially release this back to you and stop blocking. Would that work?

@metasoarous
Copy link
Member

Hey Pat. That's fine. Thanks for letting me know.

@patcon patcon removed their assignment Nov 23, 2022
@compdemocracy compdemocracy deleted a comment from patcon Nov 24, 2022
Polis Development automation moved this from In progress to Reviewer approved Dec 2, 2022
@metasoarous metasoarous merged commit 6316a22 into compdemocracy:edge Dec 2, 2022
Polis Development automation moved this from Reviewer approved to Done Dec 2, 2022
@patcon patcon deleted the admin-webpack branch December 5, 2022 12:33
@patcon
Copy link
Contributor Author

patcon commented Dec 5, 2022

This is so rad! Thanks so much for digging this out of my 80%-hole @metasoarous :)

brendanarnold added a commit to DFE-Digital/polis-whitelabel that referenced this pull request Dec 11, 2022
* Migrate client-admin from gulp to webpack (compdemocracy#1242)

* First-pass gulp-to-webpack conversion.

* Update webpack-cli, and create prod/dev logic.

* Messy: leave uncompressed files in dev mode build.

* Shut off compression in dev mode more elegantly.

* Get docker build working.

* Fixed bundlewatch path to find client-admin files.

* Get rid of old webpack build scripts.

* Don't minify for dev build.

* Removed dep pkgs for s3 deploy.

* Added ability to use bundle analyzer plugin.

* Removed all unneeded files.

* Fixed up eslint issue with upgraded packages.

* Fixed bundlewatch CI script.

* Keep new client-admin bundle consistently named.

* Try running e2e tests against sslip.io instead of localhost.

* Escape the domainWhitelist strings as it was done before.

* Revert "Try running e2e tests against sslip.io instead of localhost."

This reverts commit 46722d0.

* Oops. Inversed the boolean for configs.

* Trying to debug index_admin.html issue.

* Added upterm for remote debugging.

* Ensure upterm runs on failures.

* Added publicPath to make script link absolute.

* Drop the embed.html test file into new home.

* Ensuring dev mode builds and dev server use same simplifications.

* Set up all routes to point to index.html. Added mention of future proxy.

* Removed debugging step from github actions.

* Tiny fixups to clean up PR.

* Only write headerJson files during prod build.

* Migrate from dist to more build as before.

* Removed unneeded config vars.

* Cleaned up webpack dev-mode logic.

* Went back to using dist folder to fix bundle-analyzer bug.

* Updated client-admin README. Removed badges. Removed deployment references.

* Cleaned up ignorefiles.

* Mention where builds happen.

* Use build instead of dist for client-admin build output

* switch to npm run build:prod in file-server/Dockerfile

* inject compiled js in html body for client-admin

* add/update webpack versions

Co-authored-by: Christopher Small <metasoarous@gmail.com>

* Adding farsi translation (compdemocracy#1560)

* Adding farsi translation

* Update client-participation/js/strings.js

Co-authored-by: Patrick Connolly <patrick.c.connolly@gmail.com>

Co-authored-by: Colin Megill <colinmegill@gmail.com>
Co-authored-by: Patrick Connolly <patrick.c.connolly@gmail.com>

* German language editing (compdemocracy#1552)

* Bump node from 11.15.0-alpine to 18.9.0-alpine in /client-admin (compdemocracy#1523)

Bumps node from 11.15.0-alpine to 18.9.0-alpine.

---
updated-dependencies:
- dependency-name: node
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump node from 11.15.0-alpine to 18.9.0-alpine in /client-report (compdemocracy#1525)

Bumps node from 11.15.0-alpine to 18.9.0-alpine.

---
updated-dependencies:
- dependency-name: node
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump moment from 2.29.1 to 2.29.4 in /client-report (compdemocracy#1514)

Bumps [moment](https://github.com/moment/moment) from 2.29.1 to 2.29.4.
- [Release notes](https://github.com/moment/moment/releases)
- [Changelog](https://github.com/moment/moment/blob/develop/CHANGELOG.md)
- [Commits](moment/moment@2.29.1...2.29.4)

---
updated-dependencies:
- dependency-name: moment
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump ws from 7.4.2 to 7.5.7 in /client-admin (compdemocracy#1395)

Bumps [ws](https://github.com/websockets/ws) from 7.4.2 to 7.5.7.
- [Release notes](https://github.com/websockets/ws/releases)
- [Commits](websockets/ws@7.4.2...7.5.7)

---
updated-dependencies:
- dependency-name: ws
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump got and nodemon in /server (compdemocracy#1539)

Removes [got](https://github.com/sindresorhus/got). It's no longer used after updating ancestor dependency [nodemon](https://github.com/remy/nodemon). These dependencies need to be updated together.


Removes `got`

Updates `nodemon` from 2.0.7 to 2.0.20
- [Release notes](https://github.com/remy/nodemon/releases)
- [Commits](remy/nodemon@v2.0.7...v2.0.20)

---
updated-dependencies:
- dependency-name: got
  dependency-type: indirect
- dependency-name: nodemon
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump y18n from 3.2.1 to 3.2.2 in /client-report (compdemocracy#932)

Bumps [y18n](https://github.com/yargs/y18n) from 3.2.1 to 3.2.2.
- [Release notes](https://github.com/yargs/y18n/releases)
- [Changelog](https://github.com/yargs/y18n/blob/master/CHANGELOG.md)
- [Commits](https://github.com/yargs/y18n/commits)

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump minimist from 1.2.5 to 1.2.6 in /client-admin (compdemocracy#1384)

Bumps [minimist](https://github.com/substack/minimist) from 1.2.5 to 1.2.6.
- [Release notes](https://github.com/substack/minimist/releases)
- [Commits](https://github.com/substack/minimist/compare/1.2.5...1.2.6)

---
updated-dependencies:
- dependency-name: minimist
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Update de_de.js

Checked german language (native speaker). Corrected some inconsistencies and grammar errors.

* Update de_de.js

* Update de_de.js

* Revert "Bump node from 11.15.0-alpine to 18.9.0-alpine in /client-admin (compdemocracy#1523)"

This reverts commit 0d1242f.

* Revert "Bump node from 11.15.0-alpine to 18.9.0-alpine in /client-report (compdemocracy#1525)"

This reverts commit 54ed279.

* Revert "Bump moment from 2.29.1 to 2.29.4 in /client-report (compdemocracy#1514)"

This reverts commit 4e7dd51.

* Revert "Bump ws from 7.4.2 to 7.5.7 in /client-admin (compdemocracy#1395)"

This reverts commit 0224f8e.

* Revert "Bump got and nodemon in /server (compdemocracy#1539)"

This reverts commit 0c18e1e.

* Revert "Bump minimist from 1.2.5 to 1.2.6 in /client-admin (compdemocracy#1384)"

This reverts commit 0e8263b.

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Christopher Small <metasoarous@gmail.com>

* Update CHANGELOG

* Remove boolean, DISABLE_PLANS and DISABLE_INTERCOM

* Tidied up package.json

* Remove advice on cache clear - not needed for NPM > 5

* Rebuilt package-lock for e2e to fix tests

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Patrick Connolly <patrick.c.connolly@gmail.com>
Co-authored-by: Christopher Small <metasoarous@gmail.com>
Co-authored-by: Hadjar Homaei <hadjar@gmail.com>
Co-authored-by: Colin Megill <colinmegill@gmail.com>
Co-authored-by: SvenSt-BIE <115692202+SvenSt-BIE@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Comment on lines -147 to -189
gulp.task("configureForProduction", function (callback) {
devMode = false;
destRootBase = "dist";

console.log("getGitHash begin");
// NOTE using callback instead of returning a promise since the promise isn't doing the trick - haven't tried updating gulp yet.
getGitHash()
.then(function (hash) {
var d = new Date();
var tokenParts = [
d.getFullYear(),
d.getMonth() + 1,
d.getDate(),
d.getHours(),
d.getMinutes(),
d.getSeconds(),
];

if (hash) {
hash = hash.toString().match(/[A-Za-z0-9]+/)[0];
tokenParts.push(hash);
}

var unique_token = tokenParts.join("_");
destRootRest = [staticFilesPrefix, unique_token].join("/");
versionString = unique_token;

console.log(
"done setting destRoot: " +
destRoot() +
" destRootRest: " +
destRootRest +
" destRootBase: " +
destRootBase
);
callback(null);
})
.catch(function (err) {
console.error("getGitHash err");
console.error(err);
callback(true);
});
});
Copy link
Member

Choose a reason for hiding this comment

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

We actually needed this part of the routine for caching to work properly

Copy link
Contributor

Choose a reason for hiding this comment

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

Webpack takes care of 'cache busting' Javascript import for you - in webpack.config.js line 32 it uses a 'magic' string [chunkhash:8] to generate a random 8 character string and puts that in the output filename. In the HtmlWebpackPlugin it is injected into the HTML body when it is processed - some earlier discussion into this is at https://github.com/compdemocracy/polis/pull/1242/files#r776461657

"/dist/admin_bundle.js",
"/" + [destRootRest, "js", "admin_bundle.js"].join("/")
);
html = html.replace("NULL_VERSION", versionString);
Copy link
Member

Choose a reason for hiding this comment

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

I don't know if we needed this or not

Copy link
Contributor

Choose a reason for hiding this comment

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

This value is written but never read in the codebase so presumably it is a human readable version. There is some argument to be said that maybe this should be displayed visually so we know which version of the front-end we are looking at. In polis-whitelabel I actually mapped this to the package.json version with the view of later setting up formal releases.

Copy link
Member

Choose a reason for hiding this comment

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

That's what I thought, but thanks for doing some legwork to confirm!

We've been thinking about displaying version string as you suggest, and are interested in any ideas about it you might have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

None yet

5 participants