Skip to content
This repository has been archived by the owner on Jan 16, 2025. It is now read-only.

Commit

Permalink
adding src
Browse files Browse the repository at this point in the history
  • Loading branch information
awfixer committed Dec 26, 2024
1 parent 11e31d3 commit 938fabc
Show file tree
Hide file tree
Showing 6,248 changed files with 721,069 additions and 0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
65 changes: 65 additions & 0 deletions .devcontainer/.docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
ARG NODE_VERSION=20.15.1
## Base Image used for all targets
FROM node:$NODE_VERSION-bullseye-slim AS base
RUN apt-get update && \
apt-get install -y \
build-essential \
curl \
jq \
libjemalloc2 \
python3 \
tar

# 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
# 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 && \
apt update && \
apt install -y \
git \
stripe \
zsh \
procps \
default-mysql-client && \
npx -y [email protected] install --with-deps

ENV NX_DAEMON=true
ENV YARN_CACHE_FOLDER=/workspaces/ghost/.yarncache

EXPOSE 2368
EXPOSE 4200
EXPOSE 4173
EXPOSE 41730
EXPOSE 4175
EXPOSE 4176
EXPOSE 4177
EXPOSE 4178
EXPOSE 6174
EXPOSE 7173
EXPOSE 7174


# Full Devcontainer Stage: Add the code and install dependencies
### 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
WORKDIR /workspaces/ghost
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

WORKDIR /workspaces/ghost

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"]
CMD ["yarn", "dev"]
13 changes: 13 additions & 0 deletions .devcontainer/.docker/base-devcontainer.compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# For use in a Dev Container where your local code is mounted into the container
name: ghost-devcontainer
services:
ghost:
image: ghost-base-devcontainer
build:
target: base-devcontainer
command: ["sleep", "infinity"]
environment:
- DEVCONTAINER=true
- DISPLAY=host.docker.internal:0
volumes:
- /tmp/.X11-unix:/tmp/.X11-unix
47 changes: 47 additions & 0 deletions .devcontainer/.docker/base.compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Base container and services for running Ghost
## Intended to be extended by another compose file
## e.g. docker compose -f base.compose.yml -f development.compose.yml up
## Does not include development dependencies, Ghost code, or any other dependencies
name: ghost-base
services:
ghost:
image: ghost-base
build:
context: ../../
dockerfile: .devcontainer/.docker/Dockerfile
target: base
pull_policy: never
tty: true
depends_on:
mysql:
condition: service_healthy
redis:
condition: service_healthy
mysql:
image: mysql:8.0.35
# We'll need to look into how we can further fine tune the memory usage/performance here
command: --innodb-buffer-pool-size=1G --innodb-log-buffer-size=500M --innodb-change-buffer-max-size=50 --innodb-flush-log-at-trx_commit=0 --innodb-flush-method=O_DIRECT
ports:
- "3306"
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: ghost
restart: always
volumes:
- mysql-data:/var/lib/mysql
healthcheck:
test: "mysql -uroot -proot ghost -e 'select 1'"
interval: 1s
retries: 120
redis:
image: redis:7.0
ports:
- "6379"
restart: always
healthcheck:
test: [ "CMD", "redis-cli", "--raw", "incr", "ping" ]
interval: 1s
retries: 120

volumes:
mysql-data:
38 changes: 38 additions & 0 deletions .devcontainer/.docker/development.compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Development container with Ghost code and dependencies pre-installed
## Watches your local filesystem and syncs changes to the container
## Intended for use with raw docker compose commands
name: ghost-development
services:
ghost:
image: ghost-development
build:
target: development
command: ["yarn", "dev"]
volumes:
- ../../.yarncache:/workspaces/ghost/.yarncache
develop:
watch:
- path: ../../
action: sync
target: /workspaces/ghost
ignore:
- node_modules/
- .yarncache/
- path: yarn.lock
action: rebuild
ports:
- 2368:2368
- 4200:4200
- 4173:4173
- 41730:41730
- 4175:4175
- 4176:4176
- 4177:4177
- 4178:4178
- 6174:6174
- 7173:7173
- 7174:7174
- 9174:9174
environment:
- DEBUG=${DEBUG:-}
- APP_FLAGS=${APP_FLAGS:-}
7 changes: 7 additions & 0 deletions .devcontainer/.docker/development.entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

if [ -z "$(ls -A ".yarncache")" ]; then
cp -r /workspaces/ghost/.yarncachecopy/* /workspaces/ghost/.yarncache/
fi

exec "$@"
26 changes: 26 additions & 0 deletions .devcontainer/.docker/full-devcontainer.compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Dev Container with all Ghost code and dependencies pre-installed
name: ghost-full-devcontainer
services:
ghost:
image: ghost-full-devcontainer
build:
target: full-devcontainer
command: ["sleep", "infinity"]
environment:
- DEVCONTAINER=true
- DISPLAY=host.docker.internal:0
volumes:
- /tmp/.X11-unix:/tmp/.X11-unix
ports:
- 2368:2368
- 4200:4200
- 4173:4173
- 41730:41730
- 4175:4175
- 4176:4176
- 4177:4177
- 4178:4178
- 6174:6174
- 7173:7173
- 7174:7174
- 9174:9174
24 changes: 24 additions & 0 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 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.

There are three main components that the devcontainer.json file relies on:
- The docker compose file (`.devcontainer/compose.yml`), which defines all the services that should be started when the dev container is launched, like MySQL and Redis.
- The Dockerfile (`.docker/Dockerfile`), which is used to build the dev container image.
- The `onCreateCommand` script (`.devcontainer/onCreateCommand.js`), which is used to setup the dev container after it is created.

The Dev Container setup is intended to be as simple as possible with a focus on a really simple setup experience. It is designed to use VSCode's "Clone Repository in Container" feature, which will automatically handle the setup of the dev container, and create a volume for the Ghost codebase that is managed by Docker. It is a great tool for quickly spinning up an isolated development environment, but it lacks some of the flexibility and direct control that a full docker compose setup can provide. Therefore, if you plan to do more "heavy lifting" on Ghost, we recommend using the docker compose setup instead.

## Dockerfile
The Dockerfile used to build the Dev Container itself is located at `.docker/Dockerfile`. This Dockerfile 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 from `base`, plus additional development dependencies like the stripe-cli and playwright. No code or node dependencies.
- `full-devcontainer`: everything from `base-devcontainer`, plus Ghost's code and all node dependencies
- `development`: an alternative to `full-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
The docker compose setup for the dev container is located at `.devcontainer/compose.yml`. This compose file includes the MySQL database service and the Redis service, in addition to the Ghost dev container service. When running the Dev Container (i.e. via the "Clone Repository in Container" feature in VSCode), this compose file will be used to start the necessary services before starting the Ghost Dev Container itself.

## On Create Command
The Dev Container spec allows developers to specify a command to run after the container is created. This is done by specifying an `onCreateCommand` in the devcontainer.json file. For Ghost's Dev Container, this command simply runs a JS script defined in `.devcontainer/onCreateCommand.js`. This script handles installing node dependencies, setting up the local configuration at `ghost/core/config.local.json`, and some other simple setup tasks to get the dev container ready for use.
50 changes: 50 additions & 0 deletions .devcontainer/compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Base container and services for running Ghost
## Intended to be extended by another compose file
## e.g. docker compose -f base.compose.yml -f development.compose.yml up
## Does not include development dependencies, Ghost code, or any other dependencies
name: ghost-devcontainer
services:
ghost:
image: ghost-devcontainer
command: ["sleep", "infinity"]
build:
context: ../
dockerfile: .docker/Dockerfile
target: base-devcontainer
pull_policy: never
environment:
- DEVCONTAINER=true
tty: true
depends_on:
mysql:
condition: service_healthy
redis:
condition: service_healthy
mysql:
image: mysql:8.0.35
# We'll need to look into how we can further fine tune the memory usage/performance here
command: --innodb-buffer-pool-size=1G --innodb-log-buffer-size=500M --innodb-change-buffer-max-size=50 --innodb-flush-log-at-trx_commit=0 --innodb-flush-method=O_DIRECT
ports:
- "3306"
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: ghost
restart: always
volumes:
- mysql-data:/var/lib/mysql
healthcheck:
test: "mysql -uroot -proot ghost -e 'select 1'"
interval: 1s
retries: 120
redis:
image: redis:7.0
ports:
- "6379"
restart: always
healthcheck:
test: [ "CMD", "redis-cli", "--raw", "incr", "ping" ]
interval: 1s
retries: 120

volumes:
mysql-data:
Loading

0 comments on commit 938fabc

Please sign in to comment.