Skip to content

Commit

Permalink
chore: add .devcontainer files (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
thorbrink authored Sep 4, 2024
1 parent 5a0d203 commit e355bc6
Show file tree
Hide file tree
Showing 6 changed files with 250 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# WordPress version can be any of the listed tags from https://hub.docker.com/_/wordpress/tags
# E.g. latest, 6.2, ...
ARG WORDPRESS_VERSION=latest

# PHP Variant can be any of the listed tags from https://mcr.microsoft.com/v2/devcontainers/php/tags/list
ARG PHP_VARIANT=8.2-bullseye

FROM wordpress:${WORDPRESS_VERSION}
FROM mcr.microsoft.com/vscode/devcontainers/php:${PHP_VARIANT}

# Copy WordPress files from wordpress container.
COPY --from=0 /usr/src/wordpress/ /var/www/html/

# Make vscode owner of all WordPress files.
RUN chown -R vscode:vscode /var/www/html

# Install php-mysql driver
RUN docker-php-ext-install mysqli pdo pdo_mysql

# Enable apache mods
RUN a2enmod rewrite expires

# Install WP-CLI
RUN curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar && chmod +x wp-cli.phar && sudo mv wp-cli.phar /usr/local/bin/wp
68 changes: 68 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/php-mariadb
{
"name": "PHP & MySQL",
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
"forwardPorts": [
80,
3306
],
"portsAttributes": {
"80": {
"label": "WordPress"
},
"3306": {
"label": "Database"
}
},
"remoteEnv": {
"XDEBUG_MODE": "off"
},
"customizations": {
"vscode": {
"extensions": [
"xdebug.php-debug",
"ms-azuretools.vscode-docker",
"ritwickdey.liveserver"
],
"settings": {
"intelephense.environment.includePaths": [
"/var/www/html"
]
}
},
"codespaces": {
"extensions": [
"xdebug.php-debug",
"ms-azuretools.vscode-docker"
],
"settings": {
"intelephense.environment.includePaths": [
"/var/www/html/wp-includes",
"/var/www/html/wp-admin"
],
"intelephense.environment.phpVersion": "8.2"
}
}
},
"features": {
"ghcr.io/rocker-org/devcontainer-features/apt-packages:1": {
"packages": "curl,nano,bash-completion",
"upgradePackages": true
},
"ghcr.io/devcontainers/features/node:1": {
"nodeGypDependencies": true,
"version": "16"
}
},
"postCreateCommand": {
"symlink-plugin": "ln -s \"$(pwd)\" \"/var/www/html/wp-content/plugins/$(basename \"$PWD\")\"",
"symlink-wp-config-local": "ln -s \"$(pwd)/.devcontainer/wp-config-local.php\" /var/www/html/wp-config-local.php",
"symlink-wp-config": "ln -s \"$(pwd)/.devcontainer/wp-config.php\" /var/www/html/wp-config.php",
"start-apache": "service apache2 start"
},
"waitFor": "postCreateCommand",
"remoteUser": "vscode"
}
37 changes: 37 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
version: '3.8'

services:
app:
# env_file: devcontainer.env
build:
context: .
dockerfile: Dockerfile

volumes:
- ../..:/workspaces:cached

# Overrides default command so things don't shut down after the process ends.
command: sleep infinity

# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
network_mode: service:db

# Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
# (Adding the "ports" property to this file will not forward from a Codespace.)

db:
image: mariadb:10.4
restart: always
volumes:
- db-data:/var/lib/mysql
environment:
MYSQL_DATABASE: dev
MYSQL_ROOT_PASSWORD: dev
MYSQL_USER: dev
MYSQL_PASSWORD: dev

# Add "forwardPorts": ["3306"] to **devcontainer.json** to forward MariaDB locally.
# (Adding the "ports" property to this file will not forward from a Codespace.)

volumes:
db-data:
106 changes: 106 additions & 0 deletions .devcontainer/wp-config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php

/**
* The base configuration for WordPress
*
* The wp-config.php creation script uses this file during the installation.
* You don't have to use the web site, you can copy this file to "wp-config.php"
* and fill in the values.
*
* This file contains the following configurations:
*
* * Database settings
* * Secret keys
* * Database table prefix
* * ABSPATH
*
* @link https://wordpress.org/documentation/article/editing-wp-config-php/
*
* @package WordPress
*/

if (file_exists(__DIR__ . '/wp-config-local.php')) {
require __DIR__ . '/wp-config-local.php';
}

// ** Database settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
if (!defined('DB_NAME')) define('DB_NAME', 'dev');

/** Database username */
if (!defined('DB_USER')) define('DB_USER', 'dev');

/** Database password */
if (!defined('DB_PASSWORD')) define('DB_PASSWORD', 'dev');

/** Database hostname */
if (!defined('DB_HOST')) define('DB_HOST', 'db');

/** Database charset to use in creating database tables. */
if (!defined('DB_CHARSET')) define('DB_CHARSET', 'utf8mb4');

/** The database collate type. Don't change this if in doubt. */
if (!defined('DB_COLLATE')) define('DB_COLLATE', '');

if (!defined('WP_SITEURL')) define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']);
if (!defined('WP_HOME')) define('WP_HOME', WP_SITEURL);
if (!defined('WP_CONTENT_URL')) define('WP_CONTENT_URL', WP_SITEURL . '/wp-content');

/**#@+
* Authentication unique keys and salts.
*
* Change these to different unique phrases! You can generate these using
* the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}.
*
* You can change these at any point in time to invalidate all existing cookies.
* This will force all users to have to log in again.
*
* @since 2.6.0
*/
define('AUTH_KEY', '(J.hL1=7inY7O%xo.1K^b1*=NQ!AvkBfq>HHW}D6T#6ktdvZ4qMpm7OW+vR:pHxm');
define('SECURE_AUTH_KEY', 'pPwN{M1g=?j`me{7rE-7OtJN$zDS(y#uM7.1~.X~>m+#/ln~%Myo$Ca2mBFEa0s:');
define('LOGGED_IN_KEY', '8-AQ.XlAXQTq8:f2ddzxIs]xeC cE`ZdvAv9S=*bg>I~bHT/jGLyXW4=)!rhjz+g');
define('NONCE_KEY', '9{1MgwMd|^-i3OIy(`4jmEk5T/%1Q_i^bB&h%Jc7: :m]Ic7e&fkc=8YV_2|A~Fs');
define('AUTH_SALT', 'P(}]`j]rI]Rzd<NTP`1A|aNg`)I&5cNjxZ3cb,C]PDRFeOgys@?}lV)8omoqq|UZ');
define('SECURE_AUTH_SALT', 'r./W6cc]R;#&[Isz7$`<G@4UM0qIe|mLwu;kZzG:o@[T^ML&QyN!K!Lb88X3n{<h');
define('LOGGED_IN_SALT', 'R:O%d{!<Ua/sf9zc6/^G;I*!+,&<UFgJ&hD r6GZ]x@Q[j#;&;X&&JQdJG~eqN1[');
define('NONCE_SALT', '^G^t@e9n!ys-{?yz V9&U2zCsyEVI_P3C4>S*{U]Y#(n~NzR|*Xx)6{0*/kvY^pc');

/**#@-*/

/**
* WordPress database table prefix.
*
* You can have multiple installations in one database if you give each
* a unique prefix. Only numbers, letters, and underscores please!
*/
if (!isset($table_prefix)) $table_prefix = 'wp_';

/**
* For developers: WordPress debugging mode.
*
* Change this to true to enable the display of notices during development.
* It is strongly recommended that plugin and theme developers use WP_DEBUG
* in their development environments.
*
* For information on other constants that can be used for debugging,
* visit the documentation.
*
* @link https://wordpress.org/documentation/article/debugging-in-wordpress/
*/
define('WP_DEBUG', true);
if (!defined('WP_DEBUG')) define('WP_DEBUG', false);

define('WP_DEBUG_LOG', true);

/* Add any custom values between this line and the "stop editing" line. */



/* That's all, stop editing! Happy publishing. */

/** Absolute path to the WordPress directory. */
if (!defined('ABSPATH')) define('ABSPATH', __DIR__ . '/');

/** Sets up WordPress vars and included files. */
require_once ABSPATH . 'wp-settings.php';
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
.*
~*

# Allow .devcontainer
!.devcontainer

# ignore node/grunt dependency directories
node_modules/

Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ _For more examples, please refer to the [Documentation](https://example.com)_

Instructions for deploys.

## Development environment
Devcontainer can be used for development.

1. To start the development environment, open the project in Visual Studio Code and then select "Reopen in Container" from the quick actions menu.

1. When the container is started, run the following commands to install the necessary dependencies: `php build.php`.

1. Then run `composer install`.

1. You should then be able to access the project in your browser. You will find the exposed port in the ports section Visual Studio Code.

1. When accessing the project in the browser, you will need to go through the WordPress installation process. When that is done you should activate the plugin from the WordPress admin panel.

## Constants

Expand Down

0 comments on commit e355bc6

Please sign in to comment.