Skip to content

Commit c91b1df

Browse files
authored
Merge pull request #308 from infosiftr/arm64+
Refactor 5.x installation to allow for building where necessary
2 parents 1791d76 + 4283e69 commit c91b1df

File tree

2 files changed

+76
-26
lines changed

2 files changed

+76
-26
lines changed

5/alpine/Dockerfile

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,15 @@ RUN set -eux; \
2626
mkdir -p "$GHOST_INSTALL"; \
2727
chown node:node "$GHOST_INSTALL"; \
2828
\
29-
su-exec node ghost install "$GHOST_VERSION" --db sqlite3 --no-prompt --no-stack --no-setup --dir "$GHOST_INSTALL"; \
29+
apkDel=; \
30+
\
31+
installCmd='su-exec node ghost install "$GHOST_VERSION" --db sqlite3 --no-prompt --no-stack --no-setup --dir "$GHOST_INSTALL"'; \
32+
if ! eval "$installCmd"; then \
33+
virtual='.build-deps-ghost'; \
34+
apkDel="$apkDel $virtual"; \
35+
apk add --no-cache --virtual "$virtual" g++ make python3; \
36+
eval "$installCmd"; \
37+
fi; \
3038
\
3139
# Tell Ghost to listen on all ips and not prompt for additional configuration
3240
cd "$GHOST_INSTALL"; \
@@ -43,21 +51,39 @@ RUN set -eux; \
4351
chown node:node "$GHOST_CONTENT"; \
4452
chmod 1777 "$GHOST_CONTENT"; \
4553
\
46-
# force install "sqlite3" manually since it's an optional dependency of "ghost"
54+
# force install a few extra packages manually since they're "optional" dependencies
4755
# (which means that if it fails to install, like on ARM/ppc64le/s390x, the failure will be silently ignored and thus turn into a runtime error instead)
4856
# see https://github.com/TryGhost/Ghost/pull/7677 for more details
4957
cd "$GHOST_INSTALL/current"; \
50-
# scrape the expected version of sqlite3 directly from Ghost itself
51-
sqlite3Version="$(node -p 'require("./package.json").optionalDependencies["sqlite3"]')"; \
52-
[ -n "$sqlite3Version" ]; \
53-
[ "$sqlite3Version" != 'undefined' ]; \
54-
if ! su-exec node yarn add "sqlite3@$sqlite3Version" --force; then \
58+
# scrape the expected versions directly from Ghost/dependencies
59+
packages="$(node -p ' \
60+
var ghost = require("./package.json"); \
61+
var transform = require("./node_modules/@tryghost/image-transform/package.json"); \
62+
[ \
63+
"sharp@" + transform.optionalDependencies["sharp"], \
64+
"sqlite3@" + ghost.optionalDependencies["sqlite3"], \
65+
].join(" ") \
66+
')"; \
67+
if echo "$packages" | grep 'undefined'; then exit 1; fi; \
68+
for package in $packages; do \
69+
installCmd='su-exec node yarn add "$package" --force'; \
70+
if ! eval "$installCmd"; then \
5571
# must be some non-amd64 architecture pre-built binaries aren't published for, so let's install some build deps and do-it-all-over-again
56-
apk add --no-cache --virtual .build-deps g++ gcc libc-dev make python2 vips-dev; \
57-
\
58-
npm_config_python='python2' su-exec node yarn add "sqlite3@$sqlite3Version" --force --build-from-source; \
59-
\
60-
apk del --no-network .build-deps; \
72+
virtual=".build-deps-${package%%@*}"; \
73+
apkDel="$apkDel $virtual"; \
74+
virtualPackages='g++ make python3'; \
75+
case "$package" in \
76+
# TODO sharp@*) virtualPackages="$virtualPackages pkgconf vips-dev"; \
77+
sharp@*) echo >&2 "sorry: libvips 8.12.1 in Alpine 3.15 is not new enough (8.12.2+) for sharp 0.30 😞"; continue ;; \
78+
esac; \
79+
apk add --no-cache --virtual "$virtual" $virtualPackages; \
80+
\
81+
eval "$installCmd --build-from-source"; \
82+
fi; \
83+
done; \
84+
\
85+
if [ -n "$apkDel" ]; then \
86+
apk del --no-network $apkDel; \
6187
fi; \
6288
\
6389
su-exec node yarn cache clean; \

5/debian/Dockerfile

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,16 @@ RUN set -eux; \
5050
mkdir -p "$GHOST_INSTALL"; \
5151
chown node:node "$GHOST_INSTALL"; \
5252
\
53-
gosu node ghost install "$GHOST_VERSION" --db sqlite3 --no-prompt --no-stack --no-setup --dir "$GHOST_INSTALL"; \
53+
savedAptMark="$(apt-mark showmanual)"; \
54+
aptPurge=; \
55+
\
56+
installCmd='gosu node ghost install "$GHOST_VERSION" --db sqlite3 --no-prompt --no-stack --no-setup --dir "$GHOST_INSTALL"'; \
57+
if ! eval "$installCmd"; then \
58+
aptPurge=1; \
59+
apt-get update; \
60+
apt-get install -y --no-install-recommends g++ make python3; \
61+
eval "$installCmd"; \
62+
fi; \
5463
\
5564
# Tell Ghost to listen on all ips and not prompt for additional configuration
5665
cd "$GHOST_INSTALL"; \
@@ -67,26 +76,41 @@ RUN set -eux; \
6776
chown node:node "$GHOST_CONTENT"; \
6877
chmod 1777 "$GHOST_CONTENT"; \
6978
\
70-
# force install "sqlite3" manually since it's an optional dependency of "ghost"
79+
# force install a few extra packages manually since they're "optional" dependencies
7180
# (which means that if it fails to install, like on ARM/ppc64le/s390x, the failure will be silently ignored and thus turn into a runtime error instead)
7281
# see https://github.com/TryGhost/Ghost/pull/7677 for more details
7382
cd "$GHOST_INSTALL/current"; \
74-
# scrape the expected version of sqlite3 directly from Ghost itself
75-
sqlite3Version="$(node -p 'require("./package.json").optionalDependencies["sqlite3"]')"; \
76-
[ -n "$sqlite3Version" ]; \
77-
[ "$sqlite3Version" != 'undefined' ]; \
78-
if ! gosu node yarn add "sqlite3@$sqlite3Version" --force; then \
83+
# scrape the expected versions directly from Ghost/dependencies
84+
packages="$(node -p ' \
85+
var ghost = require("./package.json"); \
86+
var transform = require("./node_modules/@tryghost/image-transform/package.json"); \
87+
[ \
88+
"sharp@" + transform.optionalDependencies["sharp"], \
89+
"sqlite3@" + ghost.optionalDependencies["sqlite3"], \
90+
].join(" ") \
91+
')"; \
92+
if echo "$packages" | grep 'undefined'; then exit 1; fi; \
93+
for package in $packages; do \
94+
installCmd='gosu node yarn add "$package" --force'; \
95+
if ! eval "$installCmd"; then \
7996
# must be some non-amd64 architecture pre-built binaries aren't published for, so let's install some build deps and do-it-all-over-again
80-
savedAptMark="$(apt-mark showmanual)"; \
81-
apt-get update; \
82-
apt-get install -y --no-install-recommends g++ gcc libc-dev libvips-dev make python2; \
83-
rm -rf /var/lib/apt/lists/*; \
84-
\
85-
npm_config_python='python2' gosu node yarn add "sqlite3@$sqlite3Version" --force --build-from-source; \
86-
\
97+
aptPurge=1; \
98+
apt-get update; \
99+
apt-get install -y --no-install-recommends g++ make python3; \
100+
case "$package" in \
101+
# TODO sharp@*) apt-get install -y --no-install-recommends libvips-dev ;; \
102+
sharp@*) echo >&2 "sorry: libvips 8.10 in Debian bullseye is not new enough (8.12.2+) for sharp 0.30 😞"; continue ;; \
103+
esac; \
104+
\
105+
eval "$installCmd --build-from-source"; \
106+
fi; \
107+
done; \
108+
\
109+
if [ -n "$aptPurge" ]; then \
87110
apt-mark showmanual | xargs apt-mark auto > /dev/null; \
88111
[ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; \
89112
apt-get purge -y --auto-remove; \
113+
rm -rf /var/lib/apt/lists/*; \
90114
fi; \
91115
\
92116
gosu node yarn cache clean; \

0 commit comments

Comments
 (0)