Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
zip \
# && pecl install imagick-3.7.0 && docker-php-ext-enable imagick \ # https://github.com/Imagick/imagick/issues/689
&& pecl install -o -f redis && docker-php-ext-enable redis \
&& pecl install xdebug-3.4.0 && docker-php-ext-enable xdebug \
&& if [ -z "$CI" ]; then pecl install xdebug-3.4.0 && docker-php-ext-enable xdebug; fi \
&& apt-get -y autoremove && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*

# Install composer
Expand Down
89 changes: 89 additions & 0 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Acorn Development Container

This dev container provides a full WordPress development environment for working on Acorn, Acorn packages, and testing Sage themes.

## Quick Start

### VS Code (Recommended)
1. Open in VS Code with Dev Containers extension
2. Wait for container build and WordPress installation
3. Access site at http://localhost:8080

### Command Line
```bash
# Install devcontainer CLI
npm install -g @devcontainers/cli

# Start dev container
devcontainer up --workspace-folder .

# Execute commands in container
devcontainer exec --workspace-folder . wp --info
```

## Services

| Service | URL/Port | Purpose |
|---------|----------|---------|
| WordPress | http://localhost:8080 | Main application |
| Mailpit | http://localhost:8025 | Email testing UI |
| Database | localhost:3306 | MariaDB 10 |
| Redis | localhost:6379 | Object caching |

## Default Credentials

- **WordPress Admin**: `admin` / `password`
- **Database**: `database_name` / `database_user` / `database_password`

## Common Commands

```bash
# WordPress CLI
wp plugin list
wp theme activate sage
wp acorn optimize:clear

# Composer (Acorn)
cd /roots/acorn
composer test

# Build tools (themes)
cd /roots/app/public/content/themes/sage
bun install
bun run build
bun run dev
```

## Project Structure

- `/roots/acorn` - Your local Acorn repository
- `/roots/app` - WordPress installation (Bedrock)
- `/roots/app/public/content/themes/` - WordPress themes
- `/roots/app/public/content/plugins/` - WordPress plugins

## Features

- **PHP 8.4** with Xdebug configured
- **Composer** and **WP-CLI** pre-installed
- **Volta** for Node.js management
- **Bun** for fast JavaScript builds
- Auto-links themes/plugins based on `composer.json` type
- Git dirty prompt indicator

## Customization

**WordPress Site Title**: Defaults to "Acorn Testing". Override with:
```bash
WP_SITE_TITLE="My Custom Site"
```

**WordPress Repository**: Clones Bedrock by default. To use a different setup:
```bash
REPOSITORY_URL=https://github.com/your/repo.git
```

## Troubleshooting

- **Port conflicts**: Change ports in `.env` (e.g., `FORWARD_WEB_PORT=8081`)
- **Rebuild container**: `Dev Containers: Rebuild Container` in VS Code
- **Database issues**: Container includes automatic database reset on setup
29 changes: 29 additions & 0 deletions .devcontainer/destroy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

# Kill and remove all devcontainer containers (more aggressive)
echo "Force stopping all devcontainer containers..."
docker ps -q | xargs -r docker kill 2>/dev/null || true

echo "Removing all containers..."
docker ps -aq | xargs -r docker rm -f 2>/dev/null || true

# Remove all devcontainer volumes
echo "Removing all devcontainer volumes..."
docker volume ls -q | grep -E "acorn_devcontainer|devcontainer_acorn|devcontainer" | xargs -r docker volume rm -f 2>/dev/null || true

# Clean up any dangling resources
echo "Cleaning up dangling resources..."
docker system prune -f --volumes 2>/dev/null || true

# Wait a moment for ports to be released
sleep 2

# Check if anything is still running on port 8080
if lsof -i :8080 >/dev/null 2>&1; then
echo "Warning: Something is still running on port 8080"
lsof -i :8080
else
echo "Port 8080 is clear"
fi

echo "Devcontainer cleanup complete!"
9 changes: 3 additions & 6 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@
"userGid": "1000",
"upgradePackages": "true"
},
"ghcr.io/devcontainers/features/sshd:1": {},
"ghcr.io/devcontainers/features/git:1": {
"version": "latest"
}
"ghcr.io/devcontainers/features/sshd:1": {}
},
"initializeCommand": "[ ! -f '.devcontainer/.env' ] && cp '.devcontainer/config/app/.env.example' '.devcontainer/.env' || true",
"onCreateCommand": "sudo chmod +x ./${localWorkspaceFolderBasename}/.devcontainer/install.sh && ./${localWorkspaceFolderBasename}/.devcontainer/install.sh",
"postCreateCommand": "sudo chmod +x ./${localWorkspaceFolderBasename}/.devcontainer/setup.sh && ./${localWorkspaceFolderBasename}/.devcontainer/setup.sh",
"onCreateCommand": "chmod +x ./${localWorkspaceFolderBasename}/.devcontainer/install.sh && ./${localWorkspaceFolderBasename}/.devcontainer/install.sh",
"postCreateCommand": "chmod +x ./${localWorkspaceFolderBasename}/.devcontainer/setup.sh && ./${localWorkspaceFolderBasename}/.devcontainer/setup.sh",
"forwardPorts": [],
"containerEnv": {
"APP_SERVICE": "acorn.test",
Expand Down
66 changes: 0 additions & 66 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,36 +77,6 @@ services:
retries: 3
timeout: 5s

storage:
image: 'minio/minio:latest'
ports:
- '${FORWARD_MINIO_PORT:-9000}:9000'
- '${FORWARD_MINIO_CONSOLE_PORT:-8900}:8900'
environment:
MINIO_ACCESS_KEY: '${MINIO_ACCESS_KEY}'
MINIO_SECRET_KEY: '${MINIO_SECRET_KEY}'
volumes:
- 'storage:/data'
networks:
- acorn
healthcheck:
test:
[
'CMD',
'curl',
'-f',
'http://localhost:9000/minio/health/live'
]
retries: 3
timeout: 5s

browser:
image: 'selenium/standalone-chrome'
extra_hosts:
- 'host.docker.internal:host-gateway'
networks:
- acorn

mail:
image: 'axllent/mailpit:latest'
ports:
Expand All @@ -115,40 +85,6 @@ services:
networks:
- acorn

websocket:
image: 'quay.io/soketi/soketi:latest-16-alpine'
environment:
SOKETI_DEBUG: '${SOKETI_DEBUG:-1}'
SOKETI_METRICS_SERVER_PORT: '9601'
SOKETI_DEFAULT_APP_ID: '${PUSHER_APP_ID}'
SOKETI_DEFAULT_APP_KEY: '${PUSHER_APP_KEY}'
SOKETI_DEFAULT_APP_SECRET: '${PUSHER_APP_SECRET}'
ports:
- '${PUSHER_PORT:-6001}:6001'
- '${PUSHER_METRICS_PORT:-9601}:9601'
networks:
- acorn

search:
image: 'getmeili/meilisearch:latest'
ports:
- '${FORWARD_MEILISEARCH_PORT:-7700}:7700'
volumes:
- 'search:/meili_data'
networks:
- acorn
healthcheck:
test:
[
'CMD',
'wget',
'--no-verbose',
'--spider',
'http://localhost:7700/health'
]
retries: 3
timeout: 5s

networks:
acorn:
driver: bridge
Expand All @@ -157,5 +93,3 @@ volumes:
app:
database:
cache:
storage:
search:
8 changes: 4 additions & 4 deletions .devcontainer/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fi

REPOSITORY_URL="${REPOSITORY_URL:-'https://github.com/roots/bedrock.git'}"

sudo chown -R vscode:www-data /roots
sudo chown -R vscode:www-data /roots/app
cd /roots/app

# if composer.json already exists, exit early
Expand Down Expand Up @@ -91,18 +91,18 @@ else
&& composer require -d /roots/app $(cat "${WORKSPACE_FOLDER}/composer.json" | jq '.name' | tr -d '"') --no-interaction -W --ignore-platform-reqs
fi

composer remove -d /roots/app wpackagist-theme/twentytwentyfour
composer remove -d /roots/app wpackagist-theme/twentytwentyfive
composer require -d /roots/app roots/acorn-prettify -W

# Set filesystem permissions
sudo chown -R vscode:www-data /roots/app
sudo chown -R vscode:www-data /roots/app/public/content
sudo find /roots/app/ -type d -exec chmod g+s {} \;
sudo chmod g+w -R /roots/app

cd /roots

# wp-cli.yml file
cat <<WPCLI > /roots/wp-cli.yml
sudo tee /roots/wp-cli.yml > /dev/null <<WPCLI
path: /roots/app/public/wp
server:
docroot: /roots/app/public
Expand Down
26 changes: 21 additions & 5 deletions .devcontainer/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ volta install bun

WORKSPACE_FOLDER="${WORKSPACE_FOLDER:-"${PWD##*/}"}"

# WordPress site title - defaults to "Acorn Testing", can be overridden
WP_SITE_TITLE="${WP_SITE_TITLE:-"Acorn Testing"}"

# source our application env vars to be used here
. '/roots/app/.env';

Expand All @@ -31,12 +34,26 @@ if [ -f 'package.json' ]; then
fi

wp db reset --yes
wp core install --url="${WP_HOME}" --title="Roots Test" --admin_user="admin" --admin_email="[email protected]" --admin_password="password1" --skip-email
wp core install --url="${WP_HOME}" --title="${WP_SITE_TITLE}" --admin_user="admin" --admin_email="[email protected]" --admin_password="password" --skip-email

# Add sage if there are no themes
if [ ! "$(ls -d $(wp theme path --skip-plugins --skip-themes 2>/dev/null)/*/)" ]; then
composer require -d /roots/app roots/sage
# Add sage if it's not active
if ! wp theme status sage --skip-plugins --skip-themes 2>/dev/null | grep -q "^sage.*active"; then
# Only require sage if it doesn't exist
if ! wp theme is-installed sage --skip-plugins --skip-themes 2>/dev/null; then
# Remove existing Acorn to replace with version-aliased one
composer remove roots/acorn --no-update
# Add our local Acorn repository with version alias
composer config repositories.acorn '{"type": "path", "url": "/roots/acorn", "options": {"versions": {"roots/acorn": "5.0.x-dev"}}}'
# Install Sage v11 with our aliased Acorn
composer require "roots/sage:^11.0" "roots/acorn:5.0.x-dev" -W
fi
wp theme activate sage
# Build the Sage theme
cd $(wp theme path --skip-plugins --skip-themes 2>/dev/null)/sage
# Remove Sage's vendored Acorn to use Bedrock's version
composer remove roots/acorn --no-update
composer update --no-install
bun install && bun run build
fi

install_theme() {
Expand All @@ -55,5 +72,4 @@ find $(wp theme path --skip-plugins --skip-themes 2>/dev/null) -mindepth 1 -maxd
while read theme; do install_theme "$theme"; done

wp dotenv salts regenerate --skip-plugins --skip-themes 2>/dev/null || true
wp plugin activate soil --skip-plugins --skip-themes 2>/dev/null || true
wp rewrite structure '%postname%' --hard --skip-plugins --skip-themes 2>/dev/null
32 changes: 32 additions & 0 deletions .github/workflows/devcontainer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Publish Dev Container

on:
push:
branches: [main]
paths:
- '.devcontainer/**'
workflow_dispatch:

jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v4

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

- name: Build and push Dev Container
uses: devcontainers/[email protected]
with:
imageName: ghcr.io/roots/acorn-devcontainer
cacheFrom: ghcr.io/roots/acorn-devcontainer
push: always
24 changes: 12 additions & 12 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@ jobs:
uses: devcontainers/[email protected]
with:
configFile: .devcontainer/devcontainer.json
cacheFrom: ghcr.io/roots/acorn-devcontainer
push: never
runCmd: |
cd /roots/app
composer install
# ???
composer remove roots/acorn
composer require roots/acorn --no-interaction
composer require --dev nunomaduro/collision
composer require --dev spatie/laravel-ignition
# ???
# Wait for database to be ready
while ! mysqladmin ping -h"database" --silent; do
sleep 1
done
wp core install --url=http://web:8080 --title=Acorn --admin_user=admin --admin_password=admin [email protected] --skip-email --allow-root
# Ensure WordPress is installed
cd /roots/app
wp core install --url=http://web:8080 --title="Acorn Testing" --admin_user=admin --admin_password=password [email protected] --skip-email --allow-root
# Ensure Sage theme is activated
wp theme activate sage
# Clear optimization cache
wp acorn optimize:clear

# Run the routing integration tests
cd /roots/acorn
composer install
composer run-script test tests/Integration/Routing

- name: Verify routes
- name: Verify site is running
run: |
curl -s http://localhost:8080/test/ | grep "Howdy"
curl -I http://localhost:8080 | grep "200 OK"
2 changes: 1 addition & 1 deletion tests/Integration/Routing/RoutingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

$response = $client->request('GET', 'http://web:8080/non-existent-'.time());
expect($response->getStatusCode())->toBe(404);
expect((string) $response->getBody())->toContain('Page not found');
expect((string) $response->getBody())->toContain('Not Found');
expect((string) $response->getBody())->toHaveBodyClass('error404');
});

Expand Down
Loading
Loading