Skip to content

Commit

Permalink
DevContainer: use docker-compose instead of wp-env
Browse files Browse the repository at this point in the history
  • Loading branch information
jrtashjian authored May 5, 2024
1 parent 10050fe commit 0546672
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 15 deletions.
14 changes: 9 additions & 5 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"image": "mcr.microsoft.com/devcontainers/base:debian",
"name": "OmniForm Development",
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
"features": {
"ghcr.io/devcontainers/features/php:1": {
"installComposer": true
Expand All @@ -8,8 +11,9 @@
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers/features/git:1": {}
},
"onCreateCommand": "sudo chmod +x .devcontainer/install-tools.sh && .devcontainer/install-tools.sh",
"postCreateCommand": "sudo chmod +x .devcontainer/setup.sh && .devcontainer/setup.sh",
"forwardPorts": [
8888
]
}
"forwardPorts": [
8080
]
}
29 changes: 29 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: '3.1'

services:
app:
image: wordpress
restart: always
ports:
- 8080:80
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: exampleuser
WORDPRESS_DB_PASSWORD: examplepass
WORDPRESS_DB_NAME: exampledb
volumes:
- ../..:/workspaces:cached

db:
image: mariadb
restart: unless-stopped
environment:
MYSQL_DATABASE: exampledb
MYSQL_USER: exampleuser
MYSQL_PASSWORD: examplepass
MYSQL_RANDOM_ROOT_PASSWORD: '1'
volumes:
- db:/var/lib/mysql

volumes:
db:
11 changes: 11 additions & 0 deletions .devcontainer/install-tools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

set -eux

echo "Installing wp-cli..."
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
sudo chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp

# Install PHP Scoper globally
composer global require humbug/php-scoper
25 changes: 15 additions & 10 deletions .devcontainer/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,30 @@

set -eux

# If CODESPACE_NAME is set, set SITE_HOST.
if [ -n ${CODESPACE_NAME+x} ]; then
SITE_HOST="https://${CODESPACE_NAME}-8888.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}"
echo "{\"config\": {\"WP_SITEURL\": \"${SITE_HOST}\",\"WP_HOME\": \"${SITE_HOST}\"}}" | jq . > /workspaces/omniform/.wp-env.override.json
if [ -z ${CODESPACE_NAME+x} ]; then
SITE_HOST="http://localhost:8080"
else
SITE_HOST="https://${CODESPACE_NAME}-8080.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}"
fi

echo "PATH=\"\$PATH:${HOME}/.composer/vendor/bin\"" >> $HOME/.bashrc
export PATH="$PATH:$HOME/.composer/vendor/bin"

# Install PHP Scoper globally
composer global require humbug/php-scoper

# Install dependencies
cd /workspaces/omniform

# Prefix required Composer packages.
composer install --no-autoloader --no-dev --prefer-dist
php-scoper add-prefix --force
rm -rf ./vendor

# Reset and install Composer dependencies.
rm -rf ./vendor
composer install
npm install && npm run build

# Install WordPress.
cd /var/www/html
echo "Setting up WordPress at $SITE_HOST"

npm install && npm run build
wp core install --url="$SITE_HOST" \
--title="OmniForm Development" \
--admin_user="admin" --admin_email="admin@example.com" --admin_password="password" --skip-email

0 comments on commit 0546672

Please sign in to comment.