dockeroctopressruby-development-kitalpine-linux

Dockerization of octopress with Alpine Linux


I'm not sure if this is right place to ask this question. I'll try. Please close if it's not compliant.

I'm having problems dockerizing octopress to publish content on github.io, specifically with Alpine Linux.

This is my Dockerfile:

FROM alpine:edge
MAINTAINER Emanuele Ianni <dierre@gmail.com>

ENV BUILD_PACKAGES bash curl-dev build-base git
ENV RUBY_PACKAGES ruby ruby-dev ruby-io-console ruby-bundler
ENV EXECJS_DEPENDENCY nodejs
ENV GIT_URL https://github.com/invasionofsmallcubes/invasionofsmallcubes.github.io.git

# Update and install all of the required packages.
# At the end, remove the apk cache
RUN apk update && \
    apk upgrade && \
    apk add $BUILD_PACKAGES && \
    apk add $RUBY_PACKAGES && \
    apk add $EXECJS_DEPENDENCY && \
    rm -rf /var/cache/apk/*

# RUN gem install --no-rdoc --no-ri posix-spawn -v 0.3.11
RUN gem install --no-rdoc --no-ri execjs

# cloning existing octopress repo
WORKDIR ~
RUN git clone $GIT_URL octopress
WORKDIR octopress
RUN gem install --no-rdoc --no-ri bundler

It breaks here, which is part of step 12 RUN bundle install:

    Installing posix-spawn 0.3.6 with native extensions

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /usr/bin/ruby -r ./siteconf20150914-5-1oxh9qm.rb extconf.rb
creating Makefile

make "DESTDIR=" clean

make "DESTDIR="
compiling posix-spawn.c
In file included from /usr/include/ruby-2.2.0/ruby/ruby.h:24:0,
                 from /usr/include/ruby-2.2.0/ruby.h:33,
                 from posix-spawn.c:14:
/usr/include/ruby-2.2.0/x86_64-linux-musl/ruby/config.h:17:0: warning: "_GNU_SOURCE" redefined
 #define _GNU_SOURCE 1
 ^
posix-spawn.c:3:0: note: this is the location of the previous definition
 #define _GNU_SOURCE
 ^
posix-spawn.c: In function 'rb_posixspawn_pspawn':
posix-spawn.c:403:11: error: 'POSIX_SPAWN_USEVFORK' undeclared (first use in this function)
  flags |= POSIX_SPAWN_USEVFORK;
           ^
posix-spawn.c:403:11: note: each undeclared identifier is reported only once for each function it appears in
Makefile:237: recipe for target 'posix-spawn.o' failed
make: *** [posix-spawn.o] Error 1

make failed, exit code 2

Gem files will remain installed in /usr/lib/ruby/gems/2.2.0/gems/posix-spawn-0.3.6 for inspection.
Results logged to /usr/lib/ruby/gems/2.2.0/extensions/x86_64-linux/2.2.0/posix-spawn-0.3.6/gem_make.out
An error occurred while installing posix-spawn (0.3.6), and Bundler cannot
continue.
Make sure that `gem install posix-spawn -v '0.3.6'` succeeds before bundling.
The command '/bin/sh -c bundle install' returned a non-zero code: 5

I'm not having problems installing a greater version of posix-spawn but this is the one needed by bundle install.

If I run the file using Ubuntu, I do not have this error:

Installing syntax 1.0.0
Installing maruku 0.6.1
Installing posix-spawn 0.3.6 with native extensions
Installing yajl-ruby 1.1.0 with native extensions

I've installed ruby-dev so I thought this was enough. Do you know if there is something else I can check?


Solution

  • Alpine Linux uses musl libc instead of glibc, and this sometimes causes issues for edge cases. See issue #54 at rtomayko/posix-spawn.

    There are a couple of possible solutions I can think of if you insist on sticking with Alpine. The first is to check out this experimental package for posix-spawn on Alpine. You'd have to add the edge/testing repository, of course, at http://dl-4.alpinelinux.org/alpine/edge/testing/x86_64/

    Alternatively, you could install an experimental glibc package for Alpine. Here's an example used to install the Java 8 JDK to get you started: https://github.com/sillelien/base-java/blob/master/Dockerfile (specifically lines 10-16).

    Of course, you can always use debian:jessie (or Ubuntu) instead of Alpine if you can't get anything else to work. That wouldn't be the end of the world, but as an Alpine fan, I'd understand if you'd want to continue trying workarounds to get Octopress working on Alpine.

    Hope this helps!