diff --git a/ghost/README.md b/ghost/README.md index df534e3..aeaca83 100644 --- a/ghost/README.md +++ b/ghost/README.md @@ -11,7 +11,7 @@ ghost: ports: - "127.0.0.1:2368:2368" volumes: - - ./data:/var/lib/ghost + - ./data:/var/lib/ghost/content restart: always ``` diff --git a/ghost/arm/Dockerfile b/ghost/arm/Dockerfile index 60fcfb9..dca9854 100644 --- a/ghost/arm/Dockerfile +++ b/ghost/arm/Dockerfile @@ -5,32 +5,34 @@ FROM easypi/alpine-arm MAINTAINER EasyPi Software Foundation -ENV GHOST_VER 0.11.9 -ENV GHOST_URL https://github.com/TryGhost/Ghost/releases/download/$GHOST_VER/Ghost-$GHOST_VER.zip -ENV GHOST_SOURCE /usr/src/ghost -ENV GHOST_CONTENT /var/lib/ghost +ENV GHOST_VERSION 1.5.0 +ENV GHOST_INSTALL /var/lib/ghost +ENV GHOST_CONTENT /var/lib/ghost/content +ENV GHOST_CLI_VERSION 1.0.3 +ENV NPM_CONFIG_LOGLEVEL warn +ENV NODE_ENV production -WORKDIR $GHOST_SOURCE +RUN set -xe \ + && addgroup -g 1000 node \ + && adduser -u 1000 -G node -s /bin/sh -D node \ + && apk add --no-cache bash build-base nodejs nodejs-npm python su-exec \ + && npm install -g --unsafe-perm ghost-cli@$GHOST_CLI_VERSION knex-migrator@latest \ + && 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 \ + && 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 \ + && mv $GHOST_CONTENT $GHOST_INSTALL/content.orig \ + && mkdir -p $GHOST_CONTENT \ + && chown node:node $GHOST_CONTENT \ + && apk del build-base python + +WORKDIR $GHOST_INSTALL VOLUME $GHOST_CONTENT -RUN set -ex \ - && apk add -U bash \ - nodejs \ - nodejs-npm \ - && apk add -t TMP build-base \ - curl \ - python \ - && curl -sSL $GHOST_URL -o ghost.zip \ - && unzip ghost.zip \ - && npm install --production \ - && npm cache clean \ - && apk del TMP \ - && rm -rf ghost.zip \ - /tmp/npm* \ - /var/cache/apk/* - -COPY docker-entrypoint.sh /entrypoint.sh -ENTRYPOINT ["/entrypoint.sh"] +COPY docker-entrypoint.sh /usr/local/bin +ENTRYPOINT ["docker-entrypoint.sh"] EXPOSE 2368 -CMD ["npm", "start"] +CMD ["node", "current/index.js"] diff --git a/ghost/arm/docker-compose.yml b/ghost/arm/docker-compose.yml index b1d1b6d..6957362 100644 --- a/ghost/arm/docker-compose.yml +++ b/ghost/arm/docker-compose.yml @@ -3,5 +3,5 @@ ghost: ports: - "127.0.0.1:2368:2368" volumes: - - ./data:/var/lib/ghost + - ./data:/var/lib/ghost/content restart: always diff --git a/ghost/arm/docker-entrypoint.sh b/ghost/arm/docker-entrypoint.sh index 0b68ca9..21eee25 100755 --- a/ghost/arm/docker-entrypoint.sh +++ b/ghost/arm/docker-entrypoint.sh @@ -1,25 +1,24 @@ #!/bin/bash set -e -if [[ "$*" == npm*start* ]]; then - for dir in "$GHOST_SOURCE/content"/*/; do - targetDir="$GHOST_CONTENT/$(basename "$dir")" - mkdir -p "$targetDir" - if [ -z "$(ls -A "$targetDir")" ]; then - tar cC "$dir" . | tar xC "$targetDir" +# allow the container to be started with `--user` +if [[ "$*" == node*current/index.js* ]] && [ "$(id -u)" = '0' ]; then + chown -R node "$GHOST_CONTENT" + exec su-exec node "$BASH_SOURCE" "$@" +fi + +if [[ "$*" == node*current/index.js* ]]; then + baseDir="$GHOST_INSTALL/content.orig" + for src in "$baseDir"/*/ "$baseDir"/themes/*; do + src="${src%/}" + target="$GHOST_CONTENT/${src#$baseDir/}" + mkdir -p "$(dirname "$target")" + if [ ! -e "$target" ]; then + tar -cC "$(dirname "$src")" "$(basename "$src")" | tar -xC "$(dirname "$target")" fi done - if [ ! -e "$GHOST_CONTENT/config.js" ]; then - sed -r ' - s/127\.0\.0\.1/0.0.0.0/g; - s!path.join\(__dirname, (.)/content!path.join(process.env.GHOST_CONTENT, \1!g; - ' "$GHOST_SOURCE/config.example.js" > "$GHOST_CONTENT/config.js" - fi - - ln -sf "$GHOST_CONTENT/config.js" "$GHOST_SOURCE/config.js" - - exec "$@" + knex-migrator-migrate --init --mgpath "$GHOST_INSTALL/current" fi exec "$@" diff --git a/ghost/docker-compose.yml b/ghost/docker-compose.yml index c90024b..525c1bd 100644 --- a/ghost/docker-compose.yml +++ b/ghost/docker-compose.yml @@ -3,5 +3,5 @@ ghost: ports: - "127.0.0.1:2368:2368" volumes: - - ./data:/var/lib/ghost + - ./data:/var/lib/ghost/content restart: always