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

Demo a local daemonized cache with turborepo #475

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

NullVoxPopuli
Copy link
Owner

@NullVoxPopuli NullVoxPopuli commented Apr 28, 2022

Uses: https://github.com/fox1t/turborepo-remote-cache

  • many options
    • docker
    • run from git (javascript/typescript/node)
    • local storage
    • s3

Start the daemon with pnpm run daemon (or pnpm exec pm2 start turborepo-remote-cache).

  • pm2 is a process/daemon manager.
  • check status with pnpm exec pm2 ls

This PR demonstrates running from source (storing locally) because I didn't feel like re-figuring out docker installation or deal with s3 credentials.

For real usage, if using a local daemon, the booting of the daemon should be abstracted in the scripts themselves. This is done here. This way, starting the daemon is not a separate command folks have to remember.

Two ways to test that this works:

with just one repo (easiest)

This demo doesn't represent distributed usage, but would demonstrate how you can save time in larger monorepos when you delete node_modules, and start from scratch. (but in this case, you don't need to actually re-build everything)

  1. clone this repo, checkout local-daemoned-cache
  2. run pnpm install
  3. run pnpm run build -- these will all be "cache miss"
  4. delete node_modules/.cache
  5. run pnpm run build -- these will all be "cache hit", as they are re-downloaded from the cache daemon. Without the daemon all packages will be "cache miss"
with git worktrees (more realistic)

You will need two terminals

In Terminal 1

  1. clone this repo, checkout local-daemoned-cache
  2. run git worktree add -b daemon-2 ../tmp-limber-work-tree
  3. run pnpm install
  4. run set -a; source ./.env.turbo to load the environment variables
  5. if pnpm run daemon:status shows the daemon as stopped, run pnpm run daemon
  6. run pnpm run build -- these will all be "cache miss", but will store the built assets in the build cache

In Terminal 2

  1. cd to tmp-limber-work-tree
  2. run pnpm install
  3. run set -a; source ./.env.turbo to load the environment variables
  4. run pnpm run build -- this should show "FULL TURBO", as the cache was hit for all packages

You can verify built assets exist now by ls -la **/*/dist/
and verify again via git clean -Xfd, pnpm install, pnpm run build -> FULL TURBO -> dist assets all exist again.

@github-actions
Copy link
Contributor

github-actions bot commented Apr 28, 2022

@github-actions github-actions bot temporarily deployed to pull request April 28, 2022 00:14 Inactive
@github-actions github-actions bot temporarily deployed to pull request May 1, 2022 23:12 Inactive
@github-actions github-actions bot temporarily deployed to pull request May 6, 2022 02:13 Inactive
@github-actions github-actions bot temporarily deployed to pull request May 6, 2022 02:17 Inactive
@github-actions github-actions bot temporarily deployed to pull request May 6, 2022 02:29 Inactive
@github-actions github-actions bot temporarily deployed to pull request May 6, 2022 02:46 Inactive
@@ -0,0 +1,5 @@
{
"teamId": "team_my-fake-but-local-team",
Copy link
Owner Author

Choose a reason for hiding this comment

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

per the docs, the teamId must begin with team_

@@ -21,6 +25,7 @@
},
"devDependencies": {
"concurrently": "^7.0.0",
"pm2": "^5.2.0",
Copy link
Owner Author

Choose a reason for hiding this comment

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

"daemon": "pm2 start ./launch-daemon.sh",
"daemon:status": "pm2 ls",
"daemon:stop": "pm2 stop ./launch-daemon.sh",
"reset": "git clean -Xfd && pnpm install",
Copy link
Owner Author

@NullVoxPopuli NullVoxPopuli May 6, 2022

Choose a reason for hiding this comment

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

reset, before I learned rm -rf node_modules/.cache was sufficient for testing turbo's cache

@github-actions github-actions bot temporarily deployed to pull request May 7, 2022 11:07 Inactive
@github-actions github-actions bot temporarily deployed to pull request May 19, 2022 13:46 Inactive
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.

1 participant