Skip to content

A devcontainer boilerplate project to show how to use a custom devcontainer for wordpress/wp-env in both local development, github ci and codesandbox

License

Notifications You must be signed in to change notification settings

lgersman/devcontainer-boilerplate

Repository files navigation

About

This project is a template for WordPress projects using Dev Containers.

Dev Containers are a standardized way to define and describe development environments. They are based on Docker containers and can be used with any editor or IDE. Dev Containers are a great way to ensure that all developers on a project have the same development environment, regardless of their operating system. The same Dev Container can be used for local development, CI/CD, and more.

It shows how to use Development Containers for WordPress plugins/theme development.

The WordPress plugin in this project is a very rudimentary plugin stub only for showcasing that Dev Containers just work for WordPress development (including usage of wp-scripts and friends)

Features

  • Dev Container definition (./.devcontainer) providing
    • pnpm
    • composer
    • wp-env
    • php including out of the box xdebug support
    • SSH access
    • configurable environment (./.devcontainer/devcontainer.env)
  • Automatic provisioning of the Dev Container for CI using a GitHub Action
    • including caching of the Dev Container image
  • VSCode Dev Container integration

Docker in Docker works smoothly in the Dev Container (wp-env makes usage of this feature).

Additional Software can easily be installed/configured into the Dev Container by editing ./.devcontainer/Dockerfile and or ./.devcontainer/devcontainer.json.

GitHub actions

GitHub action ./.github/workflows/build-devcontainer.yml is used to build the Dev Container image and push it to the GitHub Container Registry.

The image is then used in the CI pipeline to run the tests (./.github/workflows/test-devcontainer.yml).

Development

Prerequisites

  • docker

  • (optional) vscode

Setup

  • pnpm install

  • pnpm start

VS Code

setup using dev container :

  • install vscode

  • install vscode extension ms-vscode-remote.remote-containers

  • open vscode and follow the directions or open the devcontainer in vscode

Snippets

  • execute composer --version in dev container : pnpm exec devcontainer exec --workspace-folder $(pwd) composer --version

  • execute pnpm exec devcontainer build --workspace-folder $(pwd) to rebuild the devcontainer image

Codespaces

Open in GitHub Codespaces

If you want to use Git hooks for your codespace, then you should set up hooks using the devcontainer.json lifecycle scripts, such as postCreateCommand

GitLab CI

Dev Container can also be used in GitLab CI. Usage is straightforward and similar to GitHub CI : https://containers.dev/guide/gitlab-ci

PHPStorm

Dev Container can also be used in PHPStorm : https://www.jetbrains.com/help/phpstorm/connect-to-devcontainer.html

CLI

Dev Containers can be used in any environment as long as the docker prereqisite exists.

There is a NPM package @devcontainers/cli managing the usage of Dev Containers in a terminal right at your fingertips : https://containers.dev/guide/cli

As a consequence of the above almost any editing environment can be used with Dev Containers.

Links

About

A devcontainer boilerplate project to show how to use a custom devcontainer for wordpress/wp-env in both local development, github ci and codesandbox

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages