no issue - Dev Containers let you work on Ghost in a consistent, isolated environment with all the necessary development dependencies pre-installed. VSCode (or Cursor) can effectively run _inside_ the container, providing a local quality development environment while working in a well-defined, isolated environment. - For now the default setup only works with "Clone repository in Container Volume" or "Clone PR in Container Volume" — this allows for a super quick and simple setup. We can also introduce another configuration to allow opening an existing local checkout in a Dev Container, but that's not quite ready yet. - This PR also added the `yarn clean:hard` command which: deletes all node_modules, cleans the yarn cache, and cleans the NX cache. This will be necessary for opening a local checkout in a Dev Container. - To learn more about Dev Containers, read this guide from VSCode: https://code.visualstudio.com/docs/devcontainers/containers#_personalizing-with-dotfile-repositories --------- Co-authored-by: Joe Grigg <joe@ghost.org> Co-authored-by: Steve Larson <9larsons@gmail.com>
2.0 KiB
Dev Container Setup
devcontainer.json
This file contains the configuration for the dev container. It is used to define the setup of the container, including things like port bindings, environment variables, and other dev container specific features.
It points to a docker compose file in the .devcontainer/.docker
directory, which in turn relies on a Dockerfile in the same directory.
Dockerfile
The Dockerfile in this directory uses a multi-stage build to allow for multiple types of builds without duplicating code and ensuring maximum consistency. The following targets are available:
base
: The bare minimum base image used to build and run Ghost. Includes the operating system, node, and some build dependencies, but does not include any Ghost code or dependencies.base-devcontainer
: everything frombase
, plus additional development dependencies like the stripe-cli and playwright. No code or node dependencies.full-devcontainer
: everything frombase-devcontainer
, plus Ghost's code and all node dependenciesdevelopment
: an alternative tofull-devcontainer
intended for manual development e.g. with docker compose. Add Ghost's code and installs dependencies with some optimizations for the yarn cache
Docker Compose
Similarly, the docker compose configuration relies on merging compose files to create the final configuration. The base.compose.yml
file contains the bare minimum configuration, and can be extended by specifying additional services or modifying the existing ones by supplying additional compose files. For example, to run the development.compose.yml
file, you would use the following command:
docker compose -f .devcontainer/docker/base.compose.yml -f .devcontainer/docker/development.compose.yml up
There is an alias yarn compose
script in the top level package.json
which points to the appropriate compose.yml
files for local development.
This setup gives us the flexibility to create multiple different docker compose configurations, while ensuring a base level of consistency across configurations.