Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running Ghost in development environment with forever in order to watch for changes and restart #24

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
# Pull base image.
FROM dockerfile/nodejs

# Install Ghost
# Install Ghost & forever
RUN \
cd /tmp && \
wget https://ghost.org/zip/ghost-latest.zip && \
unzip ghost-latest.zip -d /ghost && \
rm -f ghost-latest.zip && \
cd /ghost && \
npm install --production && \
npm install forever -g && \
sed 's/127.0.0.1/0.0.0.0/' /ghost/config.example.js > /ghost/config.js && \
useradd ghost --home /ghost

Expand All @@ -34,4 +35,4 @@ WORKDIR /ghost
CMD ["bash", "/ghost-start"]

# Expose ports.
EXPOSE 2368
EXPOSE 2368
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,24 @@ where `<override-dir>` is an absolute path of a directory that could contain:
- `content/themes/`: more themes

After few seconds, open `http://<host>` for blog or `http://<host>/ghost` for admin page.


#### Running Ghost in development environment with forever

docker run -d -p 80:2368 -e NODE_ENV=development -e WATCH_DIRECTORY=<dir-to-watch> -v <override-dir>:/ghost-override dockerfile/ghost

where `<dir-to-watch>` is a relative path to /ghost

##### Why forever
When Ghost starts with the help of forever https://www.npmjs.com/package/forever and its watchDirectory option.
Then we can develop on a shared `ghost-override` volume and forever will watch for file changes in `watchDirectory`.
When we change a file inside `watchDirectory` forever, after a few seconds, restarts the Ghost process without stoping docker.

e.g.

docker run -d -p 80:2368 -e NODE_ENV=development -e WATCH_DIRECTORY=content/themes/my_theme -v /home/my_localhost_ghost:/ghost-override dockerfile/ghost

or in this case better interactive to see when our process restarts

docker run -p 80:2368 -e NODE_ENV=development -e WATCH_DIRECTORY=content/themes/my_theme -v /home/my_localhost_ghost:/ghost-override dockerfile/ghost

16 changes: 11 additions & 5 deletions start.bash
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ DATA="content/data"
IMAGES="content/images"
THEMES="content/themes"

cd "$GHOST"
NODE_ENV=${NODE_ENV:-production}
WATCH_DIRECTORY=${WATCH_DIRECTORY:-$THEMES}

# Symlink data directory.
mkdir -p "$OVERRIDE/$DATA"
Expand Down Expand Up @@ -37,7 +38,12 @@ fi

# Start Ghost
chown -R ghost:ghost /data /ghost /ghost-override
su ghost << EOF
cd "$GHOST"
NODE_ENV=${NODE_ENV:-production} npm start
EOF
su ghost

if [[ "$NODE_ENV" == "development" ]]; then
COMMAND="NODE_ENV=$NODE_ENV forever --watchDirectory=$WATCH_DIRECTORY -w index.js"
else
COMMAND="NODE_ENV=$NODE_ENV npm start"
fi

echo "$COMMAND" ; eval $COMMAND