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

Build sharp for non-amd64 architectures #293

Closed
wants to merge 2 commits into from
Closed
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
11 changes: 8 additions & 3 deletions 4/alpine/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# https://docs.ghost.org/faq/node-versions/
# https://github.com/nodejs/Release (looking for "LTS")
# https://github.com/TryGhost/Ghost/blob/v4.1.2/package.json#L38
FROM node:14-alpine3.14
FROM node:14-alpine3.15

# grab su-exec for easy step-down from root
RUN apk add --no-cache 'su-exec>=0.2'
Expand Down Expand Up @@ -49,11 +49,16 @@ RUN set -eux; \
cd "$GHOST_INSTALL/current"; \
# scrape the expected version of sqlite3 directly from Ghost itself
sqlite3Version="$(node -p 'require("./package.json").optionalDependencies.sqlite3')"; \
if ! su-exec node yarn add "sqlite3@$sqlite3Version" --force; then \
sharpVersion="$(node -p 'require("./node_modules/@tryghost/image-transform/package.json").optionalDependencies.sharp')"; \
su-exec node yarn add "sqlite3@$sqlite3Version" --force && sqlite3Installed=Y || sqlite3Installed=N; \
su-exec node yarn add "sharp@$sharpVersion" --force && sharpInstalled=Y || sharpInstalled=N; \
if [ "$sqlite3Installed" = "N" ] || [ "$sharpInstalled" = "N" ]; then \
# 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
[ "$sharpInstalled" = "N" ] && apk add --no-cache vips; \
apk add --no-cache --virtual .build-deps g++ gcc libc-dev make python2 vips-dev; \
\
npm_config_python='python2' su-exec node yarn add "sqlite3@$sqlite3Version" --force --build-from-source; \
[ "$sqlite3Installed" = "N" ] && npm_config_python='python2' su-exec node yarn add "sqlite3@$sqlite3Version" --force --build-from-source --ignore-optional; \
[ "$sharpInstalled" = "N" ] && ( npm_config_python='python2' npm_config_build_from_source=true su-exec node yarn add "sharp@$sharpVersion" || echo "sharp@$sharpVersion: build failed, continuing..." ); \
\
apk del --no-network .build-deps; \
fi; \
Expand Down
32 changes: 27 additions & 5 deletions 4/debian/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,46 @@ RUN set -eux; \
cd "$GHOST_INSTALL/current"; \
# scrape the expected version of sqlite3 directly from Ghost itself
sqlite3Version="$(node -p 'require("./package.json").optionalDependencies.sqlite3')"; \
if ! gosu node yarn add "sqlite3@$sqlite3Version" --force; then \
sharpVersion="$(node -p 'require("./node_modules/@tryghost/image-transform/package.json").optionalDependencies.sharp')"; \
gosu node yarn add "sqlite3@$sqlite3Version" --force && sqlite3Installed=Y || sqlite3Installed=N; \
gosu node yarn add "sharp@$sharpVersion" --force && sharpInstalled=Y || sharpInstalled=N; \
if [ "$sqlite3Installed" = "N" ] || [ "$sharpInstalled" = "N" ]; then \
# 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
savedAptMark="$(apt-mark showmanual)"; \
apt-get update; \
apt-get install -y --no-install-recommends g++ gcc libc-dev libvips-dev make python2; \
apt-get install -y --no-install-recommends g++ gcc libc-dev make python2; \
rm -rf /var/lib/apt/lists/*; \
\
npm_config_python='python2' gosu node yarn add "sqlite3@$sqlite3Version" --force --build-from-source --ignore-optional; \
\
[ "$sqlite3Installed" = "N" ] && npm_config_python='python2' gosu node yarn add "sqlite3@$sqlite3Version" --force --build-from-source --ignore-optional; \
[ "$sqlite3Installed" = "N" ] && \
# We need a recent copy of "libvips-dev". We're running Debian bullseye.
# So we build the bookworm version of "libvips-dev" against the existing bullseye runtime. This gives us best compatibility.
( mkdir -p /tmp/libvips-build; \
cd /tmp/libvips-build; \
# Add a repo source code entry for Debian bookworm.
echo "deb-src http://deb.debian.org/debian bookworm main" >> /etc/apt/sources.list; \
apt-get update; \
# First we build bookworm "libcgif-dev", a prerequisite for "libvips-dev" that's not in Debian bullseye
apt-get build-dep -y libcgif-dev; \
apt-get -b source libcgif-dev; \
dpkg -i libcgif0_*.deb libcgif-dev_*.deb; \
# Next we build bookworm "libvips-dev" against the rest of the bullseye packages.
apt-get build-dep -y libvips-dev; \
apt-get -b source libvips-dev; \
dpkg -i libvips42_*.deb gir1.2-vips-8.0_*.deb libvips-dev_*.deb; \
# We've finally got "libvips-dev" installed, now we can build sharp.
cd "$GHOST_INSTALL/current"; \
npm_config_python='python2' npm_config_build_from_source=true gosu node yarn add "sharp@$sharpVersion"; ) || echo "sharp@$sharpVersion: build failed, continuing..."; \
apt-mark showmanual | xargs apt-mark auto > /dev/null; \
[ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; \
[ "$sharpInstalled" = "N" ] && apt-mark manual libvips42; \
apt-get purge -y --auto-remove; \
fi; \
\
gosu node yarn cache clean; \
gosu node npm cache clean --force; \
npm cache clean --force; \
rm -rv /tmp/yarn* /tmp/v8*
rm -rv /tmp/yarn* /tmp/v8* /tmp/libvips-build

WORKDIR $GHOST_INSTALL
VOLUME $GHOST_CONTENT
Expand Down