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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
67296ba
Adding a docker-based dev env
kraftbj Jan 9, 2025
4391224
New CLI works with docker now -- commands will run on the local host …
kraftbj Jan 9, 2025
40d5719
Remove unneeded Docker from the dev container and put the pnpm store …
kraftbj Jan 10, 2025
5510974
Confusing the different monorepo containers, let's use the right one
kraftbj Jan 10, 2025
d244c27
No tests yet
kraftbj Jan 10, 2025
6fbd418
Try to fix the e2e tests
kraftbj Jan 10, 2025
5fe1007
Merge remote-tracking branch 'origin/trunk' into try/dev-in-docker
kraftbj Jan 10, 2025
f3ba0e7
Ensure docker is available within the container for interacting with …
kraftbj Jan 10, 2025
2c460cd
Switch logic to all docker commands run in the container, except for …
kraftbj Jan 10, 2025
0db9170
Add notification system for updates
kraftbj Jan 10, 2025
308d456
We're never expecting to have PHP tests
kraftbj Jan 10, 2025
e098e69
Ensure traditional jetpack docker up works
kraftbj Jan 10, 2025
06a24a4
Simplify
kraftbj Jan 10, 2025
409396b
Build for arm64 and amd64 when we're doing that
kraftbj Jan 10, 2025
5e8d778
Support .env for custom vars
kraftbj Jan 10, 2025
0dd5ba8
Transverse the dir tree without assuming unix dir structure
kraftbj Jan 10, 2025
3f5a875
Remove prepull. Possibly other issues, can't repro
kraftbj Jan 10, 2025
91a0a0d
Update .github/workflows/build-docker-monorepo.yml
kraftbj Jan 10, 2025
a8266cf
add qemu
kraftbj Jan 10, 2025
b68ff2b
Merge branch 'try/dev-in-docker' of github.com:Automattic/jetpack int…
kraftbj Jan 10, 2025
71f3eab
Only spin up monorepo via the executable package entry
kraftbj Jan 10, 2025
c4ca2f0
Separate docker-compose.yml
kraftbj Jan 10, 2025
c20cb23
Add new docker-composer :)
kraftbj Jan 11, 2025
4a74468
First attempt at some documentation updates
kraftbj Jan 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions .github/workflows/build-docker-monorepo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Build Monorepo Docker
on:
push:
branches: [ 'trunk' ]
paths:
- 'tools/docker/Dockerfile.monorepo'
- 'tools/docker/bin/monorepo'
- '.github/versions.sh'
- '.github/workflows/build-docker-monorepo.yml'
pull_request:
paths:
- 'tools/docker/Dockerfile.monorepo'
- 'tools/docker/bin/monorepo'
- '.github/versions.sh'
- '.github/workflows/build-docker-monorepo.yml'
concurrency:
group: build-docker-monorepo-${{ github.event_name }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
name: Build and publish Jetpack Monorepo Environment
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
timeout-minutes: 60

steps:
- uses: actions/checkout@v4

- name: Set up qemu
uses: docker/setup-qemu-action@v3
Dismissed Show dismissed Hide dismissed
with:
platforms: arm64

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
github-advanced-security[bot] marked this conversation as resolved.
Dismissed
Show resolved Hide resolved

- name: Log in to Docker Hub
uses: docker/login-action@v3
Dismissed Show dismissed Hide dismissed
with:
username: matticbot
password: ${{ secrets.DOCKER_HUB_MATTICBOT_TOKEN }}

- name: Log in to GitHub Packages
uses: docker/login-action@v3
Dismissed Show dismissed Hide dismissed
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Fetch build args
id: buildargs
run: |
source .github/versions.sh
source .github/files/gh-funcs.sh

gh_set_output php-version "$PHP_VERSION"
gh_set_output composer-version "$COMPOSER_VERSION"
gh_set_output node-version "$NODE_VERSION"
gh_set_output pnpm-version "$PNPM_VERSION"

if [[ "$GITHUB_EVENT_NAME" == "push" ]]; then
gh_set_output tags "type=raw,latest"
gh_set_output images $'automattic/jetpack-monorepo\nghcr.io/automattic/jetpack-monorepo'
elif [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then
gh_set_output tags "type=ref,event=pr"
gh_set_output images "ghcr.io/automattic/jetpack-monorepo"
else
echo "Unknown GITHUB_EVENT_NAME $GITHUB_EVENT_NAME"
exit 1
fi

- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
Dismissed Show dismissed Hide dismissed
with:
flavor: latest=false
tags: ${{ steps.buildargs.outputs.tags }}
images: ${{ steps.buildargs.outputs.images }}
labels: |
org.opencontainers.image.title=Jetpack Monorepo Environment
org.opencontainers.image.description=Environment for building and testing the Jetpack Monorepo.
org.opencontainers.image.documentation=${{ github.server_url }}/${{ github.repository }}/blob/trunk/tools/docker/README.md

- name: Build and push Docker image
uses: docker/build-push-action@v6
Dismissed Show dismissed Hide dismissed
with:
context: tools/docker
file: tools/docker/Dockerfile.monorepo
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/arm64,linux/amd64
build-args: |
PHP_VERSION=${{ steps.buildargs.outputs.php-version }}
COMPOSER_VERSION=${{ steps.buildargs.outputs.composer-version }}
NODE_VERSION=${{ steps.buildargs.outputs.node-version }}
PNPM_VERSION=${{ steps.buildargs.outputs.pnpm-version }}
1 change: 1 addition & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ jobs:
CONFIG_KEY: ${{ secrets.E2E_CONFIG_KEY }}
SUITE: ${{ matrix.suite }}
PROJECT_NAME: ${{ matrix.project }}
HOST_CWD: ${{ github.workspace }}
run: |
echo "::group::Decrypt config"
pnpm run config:decrypt
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,6 @@ phpcs.xml
# VS Code setting files
*.code-workspace
/.vscode/settings.json

.pnpm-debug.log
.pnpm-error.log
27 changes: 14 additions & 13 deletions docs/monorepo.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,20 @@ All projects should be compatible with PHP versions WordPress supports. That's c

First time working with the monorepo? We got you covered.

For the first time only:
Install the Jetpack CLI:

* From the root of the repo, run `pnpm install && pnpm jetpack cli link` (if you want the `jetpack` CLI tool installed globally) or `pnpm install` (if you don't).
* That’s it. You won’t need to do that again unless you nuke your node_modules directory.
```bash
npm install -g @automattic/jetpack-cli
```

Once you’ve done that, it’s easy: run `jetpack` (or `pnpm jetpack`) while anywhere in the Jetpack repo. To explore on your own, run `jetpack --help` to see the available commands.
Once installed, you can run `jp` anywhere in the Jetpack repo. Run `jp --help` to see all available commands.

## Jetpack Generate Wizard

Starting a new project? Great! Let the Jetpack Generate Wizard help jumpstart the files you need. To get started:

* Make sure you're checked out to the branch you want.
* Use the CLI command `jetpack generate` to start the process.
* Use the CLI command `jp generate` to start the process.
* The wizard will walk you through the steps of starting a new package, plugin, or Github action.

### Accepted Arguments
Expand All @@ -69,7 +70,7 @@ The wizard accepts a few arguments to speed things up:
* `[project type]` - Accepted values: `package`, `plugin`, `github-action`
* `--name`, `--n` - The name of your project (no spaces)

Example: `jetpack generate plugin --name my_cool_plugin` will generate plugin files for a plugin called `my_cool_plugin` under `../jetpack/projects/plugins`
Example: `jp generate plugin --name my_cool_plugin` will generate plugin files for a plugin called `my_cool_plugin` under `../jetpack/projects/plugins`

### What's Included

Expand Down Expand Up @@ -456,29 +457,29 @@ The body is separated from the headers by a blank line, and is the text that act

The changelogger tool can be used via [Jetpack's CLI tool](#first-time). You may use the following command to generate changelog entries for each project that needs one:

`jetpack changelog add`
`jp changelog add`

**Does it matter what the change file is named?** Starting the file name with `.` should not be used. Also consider avoiding names that have extensions like `.php` or `.js` to avoid confusing other tools.

**What if a change is so trivial that it doesnt need a changelog entry?** The change file is still required. If you specify the significance as patch, changelogger will allow the body section to be empty so as to not generate an entry in the changelog. In this case, use the Comment header instead, for example:
**What if a change is so trivial that it doesn't need a changelog entry?** The change file is still required. If you specify the significance as "patch", changelogger will allow the body section to be empty so as to not generate an entry in the changelog. In this case, use the "Comment" header instead, for example:

```
```bash
Significance: patch
Type: compat
Comment: Update composer.lock, no need for a changelog entry
```

**Adding the first PR to a project after a release?** If a PR is the first to Jetpack after a release, version numbers may need to be bumped. This also applies to the first semantic versioning minor or major change to any projects that use semantic versioning.
**Adding the first PR to a project after a release?** If a PR is the first to Jetpack after a release, version numbers may need to be bumped. This also applies to the first semantic versioning "minor" or "major" change to any projects that use semantic versioning.

The Linting / Changelogger validity GitHub Actions check will help in making sure that all these version numbers are in sync with the version inferred from the changelog and change files. You can also check this locally with `tools/changelogger-validate-all.sh`.
The "Linting / Changelogger validity" GitHub Actions check will help in making sure that all these version numbers are in sync with the version inferred from the changelog and change files. You can also check this locally with `tools/changelogger-validate-all.sh`.

Within a single project, changloggers `version next` command can tell you the next version, and the monorepo script `tools/project-version.sh` can be used to check and update the version numbers.
Within a single project, changlogger's `version next` command can tell you the next version, and the monorepo script `tools/project-version.sh` can be used to check and update the version numbers.

## New Projects

To begin,
* For Automatticians, drop us a line in #jetpack-crew to discuss your needs, just to be sure we don't have something already. For others, it would probably be best to open an issue to discuss it.
* Use the `jetpack generate` command to create a skeleton project.
* Use the `jp generate` command to create a skeleton project.
* Create your project based on the skeleton and submit a PR as usual.

Once we're sure that the project will be created and what its name will be, someone (you or the Crew team) does the following:
Expand Down
137 changes: 57 additions & 80 deletions docs/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,116 +2,93 @@

## Overview

This guide is designed to get you up and running working with the Jetpack Monorepo quickly following recommended and supported guidelines.
This guide will get you up and running with Jetpack development as quickly as possible using our recommended tools.

**This guide assumes you are using MacOS or a Linux machine and are an Automattician**. For more detailed information, including setting up local dev environments for all contributors, running unit tests, best coding practices, and more, you can use the [full Development Environment guide here](development-environment.md#clone-the-repository).
**Prerequisites**: You'll need:
- Node.js installed (any recent LTS version)
- Git installed and configured
- Docker installed and running

## Installation

### Using the installation script

To speed up the installation process, you may use our monorepo installation script. To do so:

- Clone the Jetpack Monorepo:
- Using a public SSH key ([recommended](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account)): `git clone [email protected]:Automattic/jetpack.git`
- Or use HTTPS: `git clone https://github.com/Automattic/jetpack.git`
- Note that the monorepo should not be cloned into the WordPress plugins directory. If you plan on not using the provided Docker environment, read the [full Development Environment guide here](development-environment.md#clone-the-repository) to find out how to add symlinks.
- `cd` into the cloned `jetpack` folder.
- Run `tools/install-monorepo.sh` from the monorepo root.
- You can use the [environment checker script](#check-if-your-environment-is-ready-for-jetpack-development) to confirm that all required tools are installed.
1. Install the Jetpack CLI:
```bash
npm install -g @automattic/jetpack-cli
```

Once the installation is complete, continue onto the section [Running Jetpack locally](#running-jetpack-locally).
2. Initialize Jetpack:
```bash
jp init
```

### Installing manually
This will:
- Clone the Jetpack monorepo to your chosen location
- Guide you through the next steps to get started

Prior to installation, we recommend using [`Homebrew`](https://brew.sh/) to manage installations and [`nvm`](https://github.com/nvm-sh/nvm/) to manage Node.js versions. If you don't already have those installed, you can do so by copy/pasting each of the following commands and running them in your terminal:
## Development Workflow

- Homebrew: `/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"`
- nvm: `curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash`
Build and test your changes:
```bash
# Build a specific project with dependencies
jp build plugins/jetpack --deps

The Jetpack Monorepo requires various software to be installed on your machine.
# Or watch for changes
jp watch plugins/jetpack

- Clone the Jetpack Monorepo:
- Using a public SSH key ([recommended](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account)): `git clone [email protected]:Automattic/jetpack.git`
- Or use HTTPS: `git clone https://github.com/Automattic/jetpack.git`
- Note that the monorepo should not be cloned into the WordPress plugins directory. If you plan on not using the provided Docker environment, read the [full Development Environment guide here](development-environment.md#clone-the-repository) to find out how to add symlinks.
- This software needs to be installed or updated system-wide:
- Bash (will need to be updated from default Mac version): `brew install bash`
- jq (JSON processor used in scripts): `brew install jq`
- To install or update the following software, cd into the Jetpack directory that was created when cloning the repo: `cd jetpack`:
- Node.js (used for build process and our CLI): `nvm install && nvm use`
- PNPM (a Node.js package manager): `npm install -g pnpm`
- PHP (the language at the core of the WordPress ecosystem): `source .github/versions.sh && brew install php@$PHP_VERSION`
- Composer (our PHP package manager): `brew install composer`
- Jetpack CLI (an internal tool that assists with development): `pnpm install && pnpm jetpack cli link`
- [You can read more about using the CLI here](https://github.com/Automattic/jetpack/blob/trunk/tools/cli/README.md).
# Run tests
jp test
```

### Check if your environment is ready for Jetpack development
## Testing with Docker

We provide a script to help you in assessing if everything's ready on your system to contribute to Jetpack.
Jetpack includes a testing environment using Docker. To start testing:

```sh
tools/check-development-environment.sh
1. Start the testing environment:
```bash
jp docker up -d
```

Running the script will tell you if you have your environment already set up and what you need to do in order to get it ready for Jetpack development:
2. Install WordPress (first time only):
```bash
jp docker install
```

- All green `YES` or `OK` messages mean you're ready to start
- Red `NO` messages mean something is wrong or missing, and a link will be provided to help you with a fix.
- Yellow messages indicate something optional is broken or missing.
3. Visit http://localhost to see your site!

## Running Jetpack locally
## Testing WordPress.com Features

After everything is installed, you're ready to run Jetpack locally! While there are other supported methods of doing this, we recommend and support using Docker containers.
To test features requiring a WordPress.com connection:

To setup Docker:
- Install Docker:
- Mac: `brew install --cask docker` (This will take a while!)
- Linux: `brew install docker`
- `open -a Docker` (or open the app from your Applications folder) to open the GUI application. You will likely need to enter your device password and accept their terms for a first time setup.
- Copy the settings file from within the monorepo root: `cp tools/docker/default.env tools/docker/.env`
- Open `tools/docker/.env` and make any modifications you'd like.
- It's strongly recommend you at least change `WP_ADMIN_PASSWORD` to something more secure.
- Start the Docker container using `jetpack docker up -d` (this may take some time for the first setup)
- Install WordPress in your Docker container using `jetpack docker install`
- Open up http://localhost to see your site!
### For Automatticians:
Use Jurassic Tube:
```bash
jp docker jt-up
```

For more in depth Docker instructions, follow the [Docker environment for Jetpack Development guide](../tools/docker/README.md).
### For External Contributors:
Use ngrok:
```bash
jp docker ngrok-up
```

## Setting up Jurassic Tube

In order to test features that require a WordPress.com connection and other network related Jetpack features, you'll need a test site that can create local HTTP tunnels. If you're an Automattician, we recommend using Jurassic Tube.

Note: This is for Automattician use only. For other methods, check out [ngrok](../tools/docker/README.md#using-ngrok-with-jetpack) or [another similar service](https://alternativeto.net/software/ngrok/).

**Warning: This creates a tunnel to your local machine which should not be trusted as secure. If it is compromised, so is your computer and everything it has access to. Only `jetpack docker jt-up` when needed for testing things that require the site to be publicly accessible, and `jetpack docker jt-down` when completed.**
**Warning: This creates a tunnel to your local machine which should not be trusted as secure. If it is compromised, so is your computer and everything it has access to. Only `jp docker jt-up` when needed for testing things that require
the site to be publicly accessible, and `jp docker jt-down` when completed.**

- Visit the [jurassic.tube](https://jurassic.tube/) homepage to create a subdomain
- Make sure you've run `pnpm install && pnpm jetpack cli link`
- Make sure Docker is running `jetpack docker up -d`
- Make sure you've run `npm install -g @automattic/jetpack-cli`
- Make sure Docker is running `jp docker up -d`
- Stand on the monorepo root in your terminal and run `mkdir tools/docker/bin/jt`
- Stop and restart the docker env: `jetpack docker stop && jetpack docker up -d`
- Stop and restart the docker env: `jp docker stop && jp docker up -d`
- Download and run the installation script: `curl "https://jurassic.tube/get-installer.php?env=jetpack" -o tools/docker/bin/jt/installer.sh && chmod +x tools/docker/bin/jt/installer.sh && tools/docker/bin/jt/installer.sh`
- Set your username: `jetpack docker jt-config username [your-username-here e.g david]`
- Set your subdomain: `jetpack docker jt-config subdomain [your-subdomain-here e.g. spaceman]`
- Now, you can start your site with `jetpack docker jt-up`
- Set your username: `jp docker jt-config username [your-username-here e.g david]`
- Set your subdomain: `jp docker jt-config subdomain [your-subdomain-here e.g. spaceman]`
- Now, you can start your site with `jp docker jt-up`
- Your site should be available at `https://custom-subdomain.jurassic.tube`

## Development Workflow

Once you have a local copy of Jetpack and all development tools installed, you can start developing.

1. Make sure the plugin you're developing is activated on your WordPress site.
2. [Build your project](development-environment.md#building-your-project) using `jetpack build [type/project]` and including its dependencies, such as `jetpack build plugins/jetpack --deps`
3. Access the plugin's dashboard in your browser.

By default the development build above will run once and if you change any of the files, you need to run `jetpack build` again to see the changes on the site. If you want to avoid that, you can run a continuous build that will rebuild anytime it sees any changes on your local filesystem. To run it, use:

```sh
jetpack watch
```
### Running Tests

To run PHP, JS, and coverage tests, you can use the Jetpack CLI: `jetpack test` and then choose the project and type of test you'd like to run.

That's all!
That's all! For more detailed information, see the [Development Environment guide](development-environment.md).
Loading
Loading