Skip to content

Instantly share code, notes, and snippets.

@pascalandy
Created April 9, 2018 00:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pascalandy/f68f6c754f41d7253753304abea20542 to your computer and use it in GitHub Desktop.
Save pascalandy/f68f6c754f41d7253753304abea20542 to your computer and use it in GitHub Desktop.
# https://docs.ghost.org/supported-node-versions/
# https://github.com/nodejs/LTS
# Update Ghost version on line: 16
# Update Ghost-cli on line: 12
FROM node:8.10-alpine
# grab su-exec for easy step-down from root
RUN apk update && apk upgrade && apk add --no-cache 'su-exec>=0.2' bash
# Add tzdata --> see alpine-base
ENV NODE_ENV="production" \
GHOST_CLI_VERSION="1.6.0"
RUN npm install --production -g "ghost-cli@$GHOST_CLI_VERSION"
ENV GHOST_VERSION="1.21.7" \
GHOST_INSTALL="/var/lib/ghost" \
GHOST_CONTENT="/var/lib/ghost/content"
RUN set -ex; \
mkdir -p "$GHOST_INSTALL"; \
chown node:node "$GHOST_INSTALL"; \
\
su-exec node ghost install "$GHOST_VERSION" --db sqlite3 --no-prompt --no-stack --no-setup --dir "$GHOST_INSTALL"; \
\
# Tell Ghost to listen on all ips and not prompt for additional configuration
cd "$GHOST_INSTALL"; \
su-exec node ghost config --ip 0.0.0.0 --port 2368 --no-prompt --db sqlite3 --url http://localhost:2368 --dbpath "$GHOST_CONTENT/data/ghost.db"; \
su-exec node ghost config paths.contentPath "$GHOST_CONTENT"; \
\
# make a config.json symlink for NODE_ENV=development (and sanity check that it's correct)
su-exec node ln -s config.production.json "$GHOST_INSTALL/config.development.json"; \
readlink -f "$GHOST_INSTALL/config.development.json"; \
\
# need to save initial content for pre-seeding empty volumes
mv "$GHOST_CONTENT" "$GHOST_INSTALL/content.orig"; \
mkdir -p "$GHOST_CONTENT"; \
chown node:node "$GHOST_CONTENT"; \
\
# sanity check to ensure knex-migrator was installed
"$GHOST_INSTALL/current/node_modules/knex-migrator/bin/knex-migrator" --version \
# uninstall ghost-cli
su-exec node npm uninstall -S -D -O -g "ghost-cli@$GHOST_CLI_VERSION";
# add knex-migrator bins into PATH
# we want these from the context of Ghost's "node_modules" directory (instead of doing "npm install -g knex-migrator") so they can share the DB driver modules
ENV PATH $PATH:$GHOST_INSTALL/current/node_modules/knex-migrator/bin
# TODO multiarch sqlite3 (once either "node:6-alpine" has multiarch or we switch to a base that does)
WORKDIR $GHOST_INSTALL
VOLUME $GHOST_CONTENT
COPY docker-entrypoint.sh /usr/local/bin
ENTRYPOINT ["docker-entrypoint.sh"]
EXPOSE 2368
CMD ["node", "current/index.js"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment