/
Dockerfile
87 lines (65 loc) · 3.51 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# This Dockerfile is used to build a container image for running Ghost, a popular open-source blogging platform, on Kubernetes.
# The image is built with official Node 20 on Debian Bookworm (LTS Iron) image and uses the Distroless base image for security and minimalism.
# Stage 1: Build Environment
FROM node:iron-bookworm AS build-env
ENV NODE_ENV=production DEBIAN_FRONTEND=noninteractive
USER root
RUN apt update && apt install --no-install-recommends --no-install-suggests -y libvips-dev
# Install the latest version of Ghost CLI globally and clean the npm cache
RUN yarn config set network-timeout 60000 && \
yarn config set inline-builds true && \
npm config set fetch-timeout 60000 && \
npm config set progress && \
npm config set omit dev
RUN yarn global add ghost-cli@latest
# Define the GHOST_VERSION build argument and set it as an environment variable
ARG GHOST_VERSION
ENV GHOST_VERSION $GHOST_VERSION
# Set the installation directory, content directory, and original content directory for Ghost
ENV GHOST_INSTALL /var/lib/ghost
ENV GHOST_CONTENT /var/lib/ghost/content
ENV GHOST_CONTENT_ORIGINAL /var/lib/ghost/content.orig
# Create the Ghost installation directory and set the owner to the "node" user
RUN mkdir -pv "$GHOST_INSTALL" && \
chown node:node "$GHOST_INSTALL"
# Switch to the "node" user and set the working directory to the home directory
USER node
# WORKDIR /home/node
RUN yarn config set network-timeout 180000 && \
yarn config set inline-builds true && \
npm config set fetch-timeout 180000 && \
npm config set progress && \
npm config set omit dev
# Install Ghost with the specified version, using MySQL as the database, and configure it without prompts, stack traces, setup, and in the specified installation directory
RUN ghost install $GHOST_VERSION --dir $GHOST_INSTALL --db mysql --dbhost mysql --no-prompt --no-stack --no-setup --color --process local
# Switch back to the root user
USER root
# Move the original content directory to a backup location, create a new content directory, set the correct ownership and permissions, and switch back to the "node" user
RUN mv -v $GHOST_CONTENT $GHOST_CONTENT_ORIGINAL && \
mkdir -pv $GHOST_CONTENT && \
chown -Rfv node:node $GHOST_CONTENT_ORIGINAL && \
chown -Rfv node:node $GHOST_CONTENT && \
chown -fv node:node $GHOST_INSTALL && \
chmod 1777 $GHOST_CONTENT
# Switch back to the "node" user
USER node
# Stage 2: Final Image
FROM gcr.io/distroless/nodejs20-debian12:latest AS runtime
# Set the installation directory and content directory for Ghost
ENV GHOST_INSTALL /var/lib/ghost
ENV GHOST_CONTENT /var/lib/ghost/content
ENV GHOST_CONTENT_ORIGINAL /var/lib/ghost/content.orig
# Copy the Ghost installation directory from the build environment to the final image
COPY --from=build-env $GHOST_INSTALL $GHOST_INSTALL
# Set the working directory to the Ghost installation directory and create a volume for the content directory
# The volume is used to persist the data across container restarts, upgrades, and migrations.
# It's going to be handled with an init container that will copy the content from your original content directory to the new content directory (If there is any)
# The CMD script will handle default themes included (Casper and Source) and init Ghost.
WORKDIR $GHOST_INSTALL
VOLUME $GHOST_CONTENT
# Copy the entrypoint script to the current Ghost version.
COPY --chown=1000:1000 entrypoint.js current/entrypoint.js
# Expose port 2368 for Ghost
EXPOSE 2368
# Set the command to start Ghost
CMD ["current/entrypoint.js"]