Skip to content

Commit ad80bce

Browse files
Tsvetan StoychevTsvetan Stoychev
authored andcommitted
Automate local WordPress setup
1 parent 0f5747f commit ad80bce

6 files changed

Lines changed: 104 additions & 14 deletions

File tree

‎.env.example‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Local Docker development defaults. Copy to .env to override them.
2+
WORDPRESS_PORT=8080
3+
WORDPRESS_DB_HOST=db:3306
4+
WORDPRESS_DB_NAME=wordpress
5+
WORDPRESS_DB_USER=wordpress
6+
WORDPRESS_DB_PASSWORD=wordpress
7+
WORDPRESS_DB_ROOT_PASSWORD=root
8+
9+
WP_URL=http://localhost:8080
10+
WP_TITLE=Basicrum Local
11+
WP_ADMIN_USER=admin
12+
WP_ADMIN_PASSWORD=basicrum-dev-password
13+
WP_ADMIN_EMAIL=admin@example.test

‎.gitignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
*.swp
55
*.swo
66

7+
# Local Docker configuration
8+
/.env
9+
710
# Composer
811
/plugins/basicrum/vendor/
912

‎Makefile‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ COMPOSE ?= docker compose
22
PHP_SERVICE = php
33
WP_SERVICE = wordpress
44
DB_SERVICE = db
5+
WPCLI_SERVICE = wpcli
56
PLUGIN_DIR = plugins/basicrum
67
PLUGIN_WORKDIR = /workspace
78
TEST_DB_NAME = wordpress_test
@@ -10,12 +11,13 @@ TEST_DB_PASS = root
1011
TEST_DB_HOST = db
1112
WP_TEST_VERSION ?= latest
1213

13-
.PHONY: help build up down restart logs shell composer-install lint lint-fix lint-php unit integration-setup integration test package clean
14+
.PHONY: help build up down restart logs shell composer-install wp-install lint lint-fix lint-php integration-setup integration test package clean
1415

1516
help:
1617
@echo "Targets:"
1718
@echo " build Build or rebuild local Docker images"
18-
@echo " up Start WordPress and MySQL for local development"
19+
@echo " up Start and provision local WordPress with Basicrum active"
20+
@echo " wp-install Install WordPress and activate Basicrum if needed"
1921
@echo " down Stop containers"
2022
@echo " restart Restart containers"
2123
@echo " logs Tail logs from WordPress and MySQL"
@@ -34,7 +36,12 @@ build:
3436
$(COMPOSE) build $(PHP_SERVICE)
3537

3638
up:
39+
$(MAKE) composer-install
40+
$(MAKE) wp-install
41+
42+
wp-install:
3743
$(COMPOSE) up -d $(DB_SERVICE) $(WP_SERVICE)
44+
$(COMPOSE) run --rm $(WPCLI_SERVICE) sh /tools/setup-wordpress.sh
3845

3946
down:
4047
$(COMPOSE) down
@@ -77,4 +84,4 @@ package:
7784
clean:
7885
$(COMPOSE) down -v
7986
rm -f basicrum.zip
80-
rm -rf release
87+
rm -rf release

‎README.md‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,16 @@ make lint
2525
make package
2626
```
2727

28-
The WordPress development site is exposed at `http://localhost:8080`.
28+
### Local WordPress
29+
30+
`make up` installs Composer dependencies, starts the stack, provisions
31+
WordPress on a new database, and activates Basicrum. The development site is at
32+
`http://localhost:8080/wp-admin/`.
33+
34+
Default local administrator credentials are `admin` /
35+
`basicrum-dev-password`. Copy `.env.example` to `.env` to override the
36+
port, database, site, or administrator values. `make down` preserves the
37+
site data; `make clean` resets it.
2938

3039
## Plugin Source
3140

‎docker-compose.yml‎

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ services:
44
container_name: basicrum-db
55
command: --default-authentication-plugin=mysql_native_password
66
environment:
7-
MYSQL_DATABASE: wordpress
8-
MYSQL_USER: wordpress
9-
MYSQL_PASSWORD: wordpress
10-
MYSQL_ROOT_PASSWORD: root
7+
MYSQL_DATABASE: ${WORDPRESS_DB_NAME:-wordpress}
8+
MYSQL_USER: ${WORDPRESS_DB_USER:-wordpress}
9+
MYSQL_PASSWORD: ${WORDPRESS_DB_PASSWORD:-wordpress}
10+
MYSQL_ROOT_PASSWORD: ${WORDPRESS_DB_ROOT_PASSWORD:-root}
1111
ports:
1212
- "3306:3306"
1313
volumes:
1414
- db_data:/var/lib/mysql
1515
healthcheck:
16-
test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-proot"]
16+
test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-p${WORDPRESS_DB_ROOT_PASSWORD:-root}"]
1717
interval: 10s
1818
timeout: 5s
1919
retries: 10
@@ -25,16 +25,37 @@ services:
2525
db:
2626
condition: service_healthy
2727
environment:
28-
WORDPRESS_DB_HOST: db:3306
29-
WORDPRESS_DB_NAME: wordpress
30-
WORDPRESS_DB_USER: wordpress
31-
WORDPRESS_DB_PASSWORD: wordpress
28+
WORDPRESS_DB_HOST: ${WORDPRESS_DB_HOST:-db:3306}
29+
WORDPRESS_DB_NAME: ${WORDPRESS_DB_NAME:-wordpress}
30+
WORDPRESS_DB_USER: ${WORDPRESS_DB_USER:-wordpress}
31+
WORDPRESS_DB_PASSWORD: ${WORDPRESS_DB_PASSWORD:-wordpress}
3232
ports:
33-
- "8080:80"
33+
- "${WORDPRESS_PORT:-8080}:80"
3434
volumes:
3535
- wordpress_data:/var/www/html
3636
- ./plugins/basicrum:/var/www/html/wp-content/plugins/basicrum
3737

38+
wpcli:
39+
image: wordpress:cli-php8.2
40+
user: "33:33"
41+
depends_on:
42+
db:
43+
condition: service_healthy
44+
environment:
45+
WORDPRESS_DB_HOST: ${WORDPRESS_DB_HOST:-db:3306}
46+
WORDPRESS_DB_NAME: ${WORDPRESS_DB_NAME:-wordpress}
47+
WORDPRESS_DB_USER: ${WORDPRESS_DB_USER:-wordpress}
48+
WORDPRESS_DB_PASSWORD: ${WORDPRESS_DB_PASSWORD:-wordpress}
49+
WP_URL: ${WP_URL:-http://localhost:8080}
50+
WP_TITLE: ${WP_TITLE:-Basicrum Local}
51+
WP_ADMIN_USER: ${WP_ADMIN_USER:-admin}
52+
WP_ADMIN_PASSWORD: ${WP_ADMIN_PASSWORD:-basicrum-dev-password}
53+
WP_ADMIN_EMAIL: ${WP_ADMIN_EMAIL:-admin@example.test}
54+
volumes:
55+
- wordpress_data:/var/www/html
56+
- ./plugins/basicrum:/var/www/html/wp-content/plugins/basicrum
57+
- ./tools:/tools:ro
58+
3859
php:
3960
build:
4061
context: ./docker/php

‎tools/setup-wordpress.sh‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env sh
2+
3+
set -eu
4+
5+
WP_PATH=${WP_PATH:-/var/www/html}
6+
7+
until [ -f "${WP_PATH}/wp-includes/version.php" ]; do
8+
echo "Waiting for WordPress files..."
9+
sleep 1
10+
done
11+
12+
mkdir -p "${WP_PATH}/wp-content/uploads"
13+
14+
if [ ! -f "${WP_PATH}/wp-config.php" ]; then
15+
wp config create \
16+
--path="${WP_PATH}" \
17+
--dbname="${WORDPRESS_DB_NAME}" \
18+
--dbuser="${WORDPRESS_DB_USER}" \
19+
--dbpass="${WORDPRESS_DB_PASSWORD}" \
20+
--dbhost="${WORDPRESS_DB_HOST}" \
21+
--skip-check
22+
fi
23+
24+
if ! wp core is-installed --path="${WP_PATH}"; then
25+
wp core install \
26+
--path="${WP_PATH}" \
27+
--url="${WP_URL}" \
28+
--title="${WP_TITLE}" \
29+
--admin_user="${WP_ADMIN_USER}" \
30+
--admin_password="${WP_ADMIN_PASSWORD}" \
31+
--admin_email="${WP_ADMIN_EMAIL}" \
32+
--skip-email
33+
fi
34+
35+
if ! wp plugin is-active basicrum --path="${WP_PATH}"; then
36+
wp plugin activate basicrum --path="${WP_PATH}"
37+
fi

0 commit comments

Comments
 (0)