Local Development Environment
To be productive, developers require local development environments which mirror their dev / staging / production counterparts.
Below is an example workflow for developers when getting started.
Docker Compose
Overview
The following local developer architecture is built to:
- Mimic production
- Enable Xdebug ONLY when required
- Decoupled Web/CLI architecture
- Frontend developers get their own image/toolchain
Config per OS
Not all "Docker for X" environments are equal e.g.
- OSX has file performance issues and needs special configuration.
- Windows requires different slash for paths.
- Linux allows for us to run our services in the same network namespace as the host (e.g. localhost)
To fix this we have setup a hierarchy to managing the differences for each OS.
- Base
- Linux
- OSX
- OSX - Catalina
- Windows - Coming soon...
To manage this we recommend you setup a bash function:
function dc() {
FILES=""
if [ -f docker-compose.yml ]; then
FILES+="-f docker-compose.yml "
fi
if [[ "$OSTYPE" == "darwin"* ]]; then
if [ -f docker-compose.osx.yml ]; then
FILES+="-f docker-compose.osx.yml "
fi
if [[ "$OSTYPE" =~ "darwin19" ]] && [ -f docker-compose.catalina.yml ]; then
FILES+="-f docker-compose.catalina.yml "
fi
elif [[ "$OSTYPE" =~ "linux"* ]]; then
if [ -f docker-compose.linux.yml ]; then
FILES+="-f docker-compose.linux.yml "
fi
fi
ARGS=${@:-""}
bash -xc "docker-compose ${FILES} ${ARGS}"
}
# Helper commands.
# NOTE: We will use these later in the document.
alias dcu="dc up"
alias dcr="dc run"
Command Line Containers
Skpr decouples the web and CLI containers to provide a smaller attack surface for environments (see shell for more info).
To mimic this locally we have setup "run" services which can be used with the dcr
alias from above.
Running a PHP command
dcr php-cli composer install
Running a NodeJS command
dcr frontend yarn install
Spinning up the environment
To spin up the environment run the following command:
$ dcu
The environment will be available via http://localhost:8080