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

Adding a docker-based dev env #40934

Open
wants to merge 24 commits into
base: trunk
Choose a base branch
from
Open

Adding a docker-based dev env #40934

wants to merge 24 commits into from

Conversation

kraftbj
Copy link
Contributor

@kraftbj kraftbj commented Jan 9, 2025

Testing moving development commands to within docker to avoid local variances or require specific versions of things to be installed locally.

Proposed changes:

  • Adds a new js-package for a new jetpack cli.
  • Adds a docker setup for a new dev env.

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

None yet.

Does this pull request change what data or activity we track or use?

No.

Testing instructions:

Testing the new CLI

  • Ensure you have Docker Desktop (Mac, if applicable), git, and node installed.
  • On Mac, it seems you have to go to the Docker Desktop settings->Resources->Proxy->check "Manual Proxy Configuation" [otherwise the wordpress container can't reach wordpress.org, haven't dug into that]. Restart Docker if applicable.
  • npm i -g @automattic/jetpack-cli
  • cd /tmp (or somewhere else without Jetpack)
  • jp -v (confirm it is installed, 1.0.0-beta1 is the current version)
  • jp --help -- it should report it can't find a monorepo checkout and invite you to use jp init
  • jp init -- follow prompts
  • cd jetpack (or whatever dir)
  • git checkout try/dev-in-docker to get on this branch.
  • jp --help -- this should pull the new dev container (I manually pushed it to docker hub for the sake of testing)
  • jp build plugins/jetpack --with-deps (does it work?)
  • jp docker up -d -- the CLI output will not be the expected "visit localhost". it'll say it's done before it's ready (need to fix).
  • Visit localhost ensure it is the WP install.
  • jp docker install -- should run the usual install process, localhost should show a regular site.
  • jp docker down

Testing the existing setup.

  • In a working dev environment, e.g. jetpack commands work.
  • Do nothing else.
  • Run jetpack --help, jetpack build plugins/jetpack --with-deps
  • Run jetpack docker up -d
  • etc
  • NOTE: You can switch to the new CLI in your existing checkout if you delete the node_modules dir. If you want to go back and forth between the two, you'll need to nuke the node_modules each time you switch.
    Does everything still work as expected? If not, does clearing the docker containers/images resolve it? Please note that.

The intent of the PR as this point is create a new, rough, beta way to dev within docker without impacting the existing jetpack commands running locally for devs who have things working. I hope to quickly iterate to the dev-in-docker is a reliable way for anyone to jump into, but the local way of doing it should still work too (and for the foreseeable future).

Known issue: Git Hooks do not work on a fresh install using only jp for dev. It'll commit, push, etc without running the hooks.

Copy link
Contributor

github-actions bot commented Jan 9, 2025

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WordPress.com Simple site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin, and enable the try/dev-in-docker branch.

    • For jetpack-mu-wpcom changes, also add define( 'JETPACK_MU_WPCOM_LOAD_VIA_BETA_PLUGIN', true ); to your wp-config.php file.
  • To test on Simple, run the following command on your sandbox:

    bin/jetpack-downloader test jetpack try/dev-in-docker
    
    bin/jetpack-downloader test jetpack-mu-wpcom-plugin try/dev-in-docker
    

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions github-actions bot added [Tools] Development CLI The tools/cli to assist during JP development. Actions GitHub actions used to automate some of the work around releases and repository management Docker RNA [JS Package] Jetpack Cli labels Jan 9, 2025
Copy link
Contributor

github-actions bot commented Jan 9, 2025

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Choose a review path based on your changes:
    • A. Team Review: add the "[Status] Needs Team Review" label
      • For most changes, including minor cross-team impacts.
      • Example: Updating a team-specific component or a small change to a shared library.
    • B. Crew Review: add the "[Status] Needs Review" label
      • For significant changes to core functionality.
      • Example: Major updates to a shared library or complex features.
    • C. Both: Start with Team, then request Crew
      • For complex changes or when you need extra confidence.
      • Example: Refactor affecting multiple systems.
  3. Get at least one approval before merging.

Still unsure? Reach out in #jetpack-developers for guidance!

@github-actions github-actions bot added the [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! label Jan 9, 2025
.github/workflows/build-docker-monorepo.yml Dismissed Show resolved Hide resolved
.github/workflows/build-docker-monorepo.yml Dismissed Show dismissed Hide dismissed
.github/workflows/build-docker-monorepo.yml Dismissed Show dismissed Hide dismissed
.github/workflows/build-docker-monorepo.yml Dismissed Show dismissed Hide dismissed
.github/workflows/build-docker-monorepo.yml Dismissed Show dismissed Hide dismissed
@kraftbj

This comment was marked as outdated.

@jeherve
Copy link
Member

jeherve commented Jan 10, 2025

I wanted to test this from a fresh computer, so I tried to start from a computer running Ubuntu, where nothing was installed yet.

Unfortunately, I run into an error when I run BUILD_LOCAL=1 jp build plugins/jetpack --with-deps:

ERROR: permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Head "http://%2Fvar%2Frun%2Fdocker.sock/_ping": dial unix /var/run/docker.sock: connect: permission denied

I'm not sure what's causing this, and I'm not familiar enough with Ubuntu to debug this I'm afraid.

Copy link
Contributor

@anomiex anomiex left a comment

Choose a reason for hiding this comment

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

Gave it a quick once-over.

projects/js-packages/jetpack-cli/bin/jp.js Outdated Show resolved Hide resolved
projects/js-packages/jetpack-cli/bin/jp.js Outdated Show resolved Hide resolved
NODE_VERSION: versionVars.NODE_VERSION,
PNPM_VERSION: versionVars.PNPM_VERSION,
COMPOSE_PROJECT_NAME: projectName,
PORT_WORDPRESS: args.includes( '--type=e2e' ) ? '8889' : '80',
Copy link
Contributor

Choose a reason for hiding this comment

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

This will work for most people, so maybe it's fine, but I do note it will blow up if something else is already running on localhost port 80.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nod, I believe this is the same as the existing jetpack docker, except the existing command accepts an optional port arg

Copy link
Contributor

Choose a reason for hiding this comment

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

More importantly, the existing command allows overriding the default via tools/docker/.env, while your code here overrides tools/docker/.env.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh, you're totally right. The .env should now work after 5e8d778

projects/js-packages/jetpack-cli/composer.json Outdated Show resolved Hide resolved
tools/docker/bin/monorepo-entrypoint.sh Outdated Show resolved Hide resolved
@@ -49,3 +49,16 @@ services:
environment:
- HOST_PORT=${PORT_WORDPRESS:-80}
- COMPOSE_PROJECT_NAME=$COMPOSE_PROJECT_NAME

monorepo:
Copy link
Contributor

Choose a reason for hiding this comment

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

This breaks normal use of jetpack docker up.

$ jetpack docker up -d
WARNING: The HOST_CWD variable is not set. Defaulting to a blank string.
ERROR: build path /tools/docker either does not exist, is not accessible, or is not a valid URL.
Command exited with status 1

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 believe this should work now after e098e69

Copy link
Contributor

Choose a reason for hiding this comment

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

$ jetpack docker up
ERROR: build path /usr/local/src/automattic/jetpack/tools/docker/tools/docker either does not exist, is not accessible, or is not a valid URL.
Command exited with status 1

Fixing that will, for me, likely still run into https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1087370. Although we probably don't need to consider me personally as a blocker.

But even for everyone else that it does work for, it'll mean that jetpack docker up will unnecessarily build that image to start an instance of the container which will then immediately exit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nod, thanks. I'll dig into it more than the quick-looking fix.

tools/docker/Dockerfile.monorepo Outdated Show resolved Hide resolved
@kraftbj kraftbj added [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Status] In Progress and removed [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! labels Jan 10, 2025
.github/workflows/build-docker-monorepo.yml Dismissed Show dismissed Hide dismissed
@kraftbj
Copy link
Contributor Author

kraftbj commented Jan 10, 2025

In addition to testing on my two production Apple Silicon (M1, M2) devices, I tested it on a clear Intel Mac using brew install node and downloading Docker Desktop. I only tested the new version on the clean machine since the intent here is to make it fast for someone new to start.

@kraftbj kraftbj changed the title DNM: Adding a docker-based dev env Adding a docker-based dev env Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Actions GitHub actions used to automate some of the work around releases and repository management Docker Docs [JS Package] Jetpack Cli RNA [Status] In Progress [Tests] Includes Tests [Tools] Development CLI The tools/cli to assist during JP development. [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants