Containerizing old Ghost sites
I recently had to upgrade a machine running some older software. Node applications are extremely finicky about versions ... of node ... of JS libs ... of native libs, etc. I had to get some old Ghost web applications that were unexported running in order to export/upgrade them. It's a pretty hacky container process, but it worked.
The plan: mhart/alpine-node supports versions back to 0.10 series, perfect. I need sqlite, so I lifted the trivial Docker recipe to add from jansanchez/sqlite-alpine:
RUN apk update \
&& apk add sqlite \
&& apk add socat
Buuuut... prebuilt sqlite3 JS lib has builtin symbol ref for memcpy on glibc. Alpine uses musl. Supposedly some kind of newer version has a patch that is necessary over node_modules/sqlite3/src/gcc-preinclude.h. Of course, it's not in what gets pulled down, so patching is required.
See discussion at https://github.com/mapbox/node-sqlite3/issues/459
--- a/sqlite3/src/gcc-preinclude.h 2015-05-08 07:48:21.000000000 -0700
+++ b/sqlite3/src/gcc-preinclude.h 2018-11-18 12:10:23.528699071 -0800
@@ -1,6 +1,6 @@
// https://rjpower9000.wordpress.com/2012/04/09/fun-with-shared-libraries-version-glibc_2-14-not-found/
-#if defined(__linux__) && defined(__x86_64__)
+#if defined(__GLIBC__) && defined(__linux__) && defined(__x86_64__)
__asm__(".symver memcpy,memcpy@GLIBC_2.2.5");
#endif
Application within npm/docker process is a little tricky but doable. I included the patched file in my image build repo to avoid dealing w/ patch in alpine (maybe it would have been fine).
RUN apk add --no-cache make gcc g++ libc-dev python
RUN npm install -g node-pre-gyp
RUN npm install --prod
RUN mv gcc-preinclude.h node_modules/sqlite3/src/gcc-preinclude.h
WORKDIR node_modules/sqlite3
RUN node-pre-gyp configure
RUN node-pre-gyp build verbose
Ready to build & run on the coreOS host:
docker build -t n/ghost:1.0 /data/docker_import/ghost
docker run -d --name ghost1 --restart unless-stopped --mount type=bind,src=/data/ghost1,dst=/app/content --dns x.x.x.x -p x.x.x.x:2369:2369 -e NODE_ENV=production n/ghost:1.0