Browse Source

dockerfile: Give more stack space to /sbin/tini.

/sbin/tini ends up running the Sass compiler, which seems to need a
larger thread stack size than the musl default.  This patch incorporates
a fix from
https://raw.githubusercontent.com/jubel-han/dockerfiles/master/common/stack-fix.c,
as described in https://github.com/sass/node-sass/issues/2031.
David Yip 1 year ago
parent
commit
f13ebd02c9
No account linked to committer's email address
3 changed files with 36 additions and 1 deletions
  1. 3
    0
      Dockerfile
  2. 1
    1
      docker_entrypoint.sh
  3. 32
    0
      stack-fix.c

+ 3
- 0
Dockerfile View File

@@ -61,6 +61,9 @@ RUN apk -U upgrade \
61 61
  && rm -rf /tmp/* /var/cache/apk/*
62 62
 
63 63
 COPY Gemfile Gemfile.lock package.json yarn.lock .yarnclean /mastodon/
64
+COPY stack-fix.c /lib
65
+RUN gcc -shared -fPIC /lib/stack-fix.c -o /lib/stack-fix.so
66
+RUN rm /lib/stack-fix.c
64 67
 
65 68
 RUN bundle config build.nokogiri --with-iconv-lib=/usr/local/lib --with-iconv-include=/usr/local/include \
66 69
  && bundle install -j$(getconf _NPROCESSORS_ONLN) --deployment --without test development \

+ 1
- 1
docker_entrypoint.sh View File

@@ -11,4 +11,4 @@ echo "Updating permissions..."
11 11
 find /mastodon -path /mastodon/public/system -prune -o -not -user mastodon -not -group mastodon -print0 | xargs -0 chown -f mastodon:mastodon
12 12
 
13 13
 echo "Executing process..."
14
-exec su-exec mastodon:mastodon /sbin/tini -- "$@"
14
+LD_PRELOAD=/lib/stack-fix.so exec su-exec mastodon:mastodon /sbin/tini -- "$@"

+ 32
- 0
stack-fix.c View File

@@ -0,0 +1,32 @@
1
+#include <dlfcn.h>
2
+#include <pthread.h>
3
+#include <stdio.h>
4
+
5
+// THIS IS TO AVOID A SIGFAULT WHEN RUNNING python3.6 manage.py runserver
6
+// This should be fixed at some point by Alpine and/or Python
7
+// Check this issue for more info
8
+// https://github.com/docker-library/python/issues/211
9
+typedef int (*func_t)(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void*), void *arg);
10
+
11
+int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void*), void *arg) {
12
+
13
+    pthread_attr_t local;
14
+    int used = 0, ret;
15
+
16
+    if (!attr) {
17
+        used = 1;
18
+        pthread_attr_init(&local);
19
+        attr = &local;
20
+    }
21
+    pthread_attr_setstacksize((void*)attr, 2 * 1024 * 1024); // 2 MB
22
+
23
+    func_t orig = (func_t)dlsym(RTLD_NEXT, "pthread_create");
24
+
25
+    ret = orig(thread, attr, start_routine, arg);
26
+
27
+    if (used) {
28
+        pthread_attr_destroy(&local);
29
+    }
30
+
31
+    return ret;
32
+}

Loading…
Cancel
Save