-
Notifications
You must be signed in to change notification settings - Fork 132
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
Docker & CI build: improve speed by leveraging caching #4545
Conversation
@@ -3,6 +3,8 @@ on: | |||
push: | |||
branches: | |||
- v2 | |||
# todo: remove |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be removed before merging!
5023ad2
to
0352591
Compare
.github/workflows/dev-pipeline.yml
Outdated
publish-npm: | ||
if: github.ref == 'refs/heads/v2' | ||
# todo: re-add this before merging! | ||
# if: github.ref == 'refs/heads/v2' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be removed before merging!
.github/workflows/dev-pipeline.yml
Outdated
PUBLISHED_PACKAGES: ${{ steps.log-parse.outputs.published-packages }} | ||
shell: bash | ||
# todo: re-add this before merging! | ||
# - name: Publish shared components to npm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be removed before merging!
c228f58
to
93620c3
Compare
- use 1.4 syntax to support `COPY --link` commands - set NODE_ENV=production - remove $WORK build arg
…ching - If e.g. `test` has been added in a command/step, removing it in a subsequent command/step does not have a positive effect on the image size. Rather, we add it .dockerignore to stop adding it in the first place. - node_modules/.cache & /tmp/Relay* are populated by Webpack plugins.
app/server.js reads .entrypoints.main.assets in order to generate an appropriate manifest and `preload` tags, but it doesn't need the rest. This is why we turn all stats off via `all: false` and then selectively turn `entrypoints` on. Before, stats.json was 82mb, now it is ~9kb.
Even if a commit has changed `yarn.lock`, we can use an old `.yarn/cache` directory, so that we don't have to fetch 99% of all dependencies again.
This reverts 32bbfa8, which reverts 3f6e105, which apparently failed because of an unrelated problem[1]. [1] https://github.com/HSLdevcom/digitransit-ui/actions/runs/4762670497/jobs/8469259999
This probably improves favicons-webpack-plugin's performance, as node_modules won't be resolved for resolving the path.
This speeds up the webpack build within the Docker image build significantly.
b17bb1f
to
abfbfd8
Compare
Still missing:
Mount.yarn/cache
intonode-modules
the Docker build.node-modules
stage, and check if it is actually faster than building from scratch. – much faster, I didn't expect thatyarn build
is a lot slower than before. 🤔 ( ~5m before, 10-20m after) – due to the upgradedfavicons-webpack-plugin
--immutable
toyarn install
causes the build to fail, as currently both onv3
andimprove-ci-speed
, the checked-inyarn.lock
does not reflect the workspace packages' versions. cc @vesameskanenProposed Changes
This PR changes the
Dockerfile
& GitHub Actions dev pipeline to be faster.While an un-cached (different
yarn.lock
and/or differentdigitransit-*/**
and/or different commit hash) build is slightly slower, a cached one is is much faster.Review
For an unknown reason,
[email protected]
crashed during the Docker build, andfavicons-webpack-plugin@^4
froze, so I usedfavicons-webpack-plugin@^3
.When looking at the changes, I recommend to review each commit individually, as I tried to make them as atomic and sensible as possible. Some of them also contain explanations.
Unfortunately, because the GitHub Actions system seems to lack support for YAML anchors, I added a lot of duplicated code in
.github/workflows/dev-pipeline.yml
. The benefit of the repeated "use cache if exists, otherwise rebuild" patterns is that each step is effectively idempotent – it works regardless of wether the cache is available and if a previous step populated it –, with the downside being very repetitive code. Once YAML anchors are supported, we could DRY it a lot.