From c1f9740665bb710d863c11c59b3dd06bc00b1e0a Mon Sep 17 00:00:00 2001 From: Chris Raible Date: Tue, 7 Jan 2025 14:16:43 -0800 Subject: [PATCH] Added opt-in `ghost` service to docker compose (#21938) ref https://linear.app/ghost/issue/ENG-1957/add-ghost-service-to-base-docker-compose-setup - Currently our `compose.yml` file only runs Ghost's supporting services, and it's expected that you'll run Ghost locally on your host machine. This commit adds a `ghost` service to our `compose.yml` file, so you can optionally run Ghost itself in a container using docker compose. - The `ghost` service is opt-in using [docker compose profiles](https://docs.docker.com/compose/how-tos/profiles/), to maintain the current behavior of only running supporting services as the default. - This commit also fixes an issue in the Dockerfile: the `WORKDIR` arg, which is used to optionally specify an alternative working directory, is not propagated from one build stage to the next, so it has to be manually added as an `ARG` in each stage. This was necessary to use the same Dockerfile for devcontainers (which require the WORKDIR to be `/workspaces/ghost`) and docker compose, where we use `/home/ghost` in alignment with the production image. --- .docker/Dockerfile | 19 ++++++------------- .docker/development.entrypoint.sh | 8 ++++++++ compose.yml | 15 +++++++++++++++ 3 files changed, 29 insertions(+), 13 deletions(-) create mode 100755 .docker/development.entrypoint.sh diff --git a/.docker/Dockerfile b/.docker/Dockerfile index 79a0d98e7c..2b83e7a4b3 100644 --- a/.docker/Dockerfile +++ b/.docker/Dockerfile @@ -15,6 +15,7 @@ RUN apt-get update && \ # Base DevContainer: for use in a Dev Container where your local code is mounted into the container ### Adding code and installing dependencies gets overridden by your local code/dependencies, so this is done in onCreateCommand FROM base AS base-devcontainer +ARG WORKDIR=/home/ghost # Install Stripe CLI, zsh, playwright RUN curl -s https://packages.stripe.dev/api/security/keypair/stripe-cli-gpg/public | gpg --dearmor | tee /usr/share/keyrings/stripe.gpg && \ echo "deb [signed-by=/usr/share/keyrings/stripe.gpg] https://packages.stripe.dev/stripe-cli-debian-local stable main" | tee -a /etc/apt/sources.list.d/stripe.list && \ @@ -28,7 +29,7 @@ RUN curl -s https://packages.stripe.dev/api/security/keypair/stripe-cli-gpg/publ npx -y playwright@1.46.1 install --with-deps ENV NX_DAEMON=true -ENV YARN_CACHE_FOLDER=/workspaces/ghost/.yarncache +ENV YARN_CACHE_FOLDER=$WORKDIR/.yarncache EXPOSE 2368 EXPOSE 4200 @@ -47,21 +48,13 @@ EXPOSE 7174 ### This is a full devcontainer with all the code and dependencies installed ### Useful in an environment like Github Codespaces where you don't mount your local code into the container FROM base-devcontainer AS full-devcontainer +ARG WORKDIR=/home/ghost WORKDIR $WORKDIR -COPY ../../ . +COPY . . RUN yarn install --frozen-lockfile --prefer-offline --cache-folder $YARN_CACHE_FOLDER -# Development Stage: alternative entrypoint for development with some caching optimizations FROM base-devcontainer AS development - +ARG WORKDIR=/home/ghost WORKDIR $WORKDIR - -COPY ../../ . - -RUN yarn install --frozen-lockfile --prefer-offline --cache-folder $YARN_CACHE_FOLDER && \ - cp -r .yarncache .yarncachecopy && \ - rm -Rf .yarncachecopy/.tmp && \ - yarn cache clean - -ENTRYPOINT ["./.devcontainer/.docker/development.entrypoint.sh"] +ENTRYPOINT ["/home/ghost/.docker/development.entrypoint.sh"] CMD ["yarn", "dev"] diff --git a/.docker/development.entrypoint.sh b/.docker/development.entrypoint.sh new file mode 100755 index 0000000000..69df8c12b7 --- /dev/null +++ b/.docker/development.entrypoint.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# Mounting local code into the container overwrites the `node_modules` directories +# so we need to install dependencies again +yarn install --frozen-lockfile --prefer-offline + +# Execute the CMD +exec "$@" \ No newline at end of file diff --git a/compose.yml b/compose.yml index 08e8a44472..16382d1560 100644 --- a/compose.yml +++ b/compose.yml @@ -1,6 +1,21 @@ name: ghost services: + ghost: + build: + context: . + dockerfile: ./.docker/Dockerfile + target: development + ports: + - "2368:2368" + - "4200:4200" + profiles: [full] + volumes: + - .:/home/ghost + tty: true + depends_on: + - mysql + - redis mysql: image: mysql:8.0.35 container_name: ghost-mysql