aripalo / gatsby-docker

Develop & Build GatsbyJS static sites within Docker.
MIT License
187 stars 53 forks source link

Building Docker image fails #9

Open machetto opened 5 years ago

machetto commented 5 years ago

Step 1/10 : FROM node:9.5-alpine 9.5-alpine: Pulling from library/node 605ce1bd3f31: Pull complete 5c0ee846ddbc: Pull complete 4273d9861593: Pull complete Digest: sha256:50ae5f22356c5a0b0c0ea76d27a453b0baf577c61633aee25cea93dcacec1630 Status: Downloaded newer image for node:9.5-alpine ---> e90a5bfd29f6 Step 2/10 : EXPOSE 8000 ---> Running in eba84000a15c Removing intermediate container eba84000a15c ---> ee5238c013d1 Step 3/10 : RUN apk update && apk add --update --repository http://dl-3.alpinelinux.org/alpine/edge/testing vips-tools vips-dev fftw-dev gcc g++ make libc6-compat && apk add git && apk add python && rm -rf /var/cache/apk/ ---> Running in ca25cdd3e5b3 fetch http://dl-cdn.alpinelinux.org/alpine/v3.6/main/x86_64/APKINDEX.tar.gz fetch http://dl-cdn.alpinelinux.org/alpine/v3.6/community/x86_64/APKINDEX.tar.gz v3.6.3-56-ge3af38305d [http://dl-cdn.alpinelinux.org/alpine/v3.6/main] v3.6.3-50-g43dd52bda8 [http://dl-cdn.alpinelinux.org/alpine/v3.6/community] OK: 8443 distinct packages available fetch http://dl-3.alpinelinux.org/alpine/edge/testing/x86_64/APKINDEX.tar.gz fetch http://dl-cdn.alpinelinux.org/alpine/v3.6/main/x86_64/APKINDEX.tar.gz fetch http://dl-cdn.alpinelinux.org/alpine/v3.6/community/x86_64/APKINDEX.tar.gz WARNING: This apk-tools is OLD! Some packages might not function properly. ERROR: unsatisfiable constraints: pc:fftw3 (missing): required by: vips-dev-8.7.0-r0[pc:fftw3] vips-dev-8.7.0-r0[pc:fftw3] vips-dev-8.7.0-r0[pc:fftw3] The command '/bin/sh -c apk update && apk add --update --repository http://dl-3.alpinelinux.org/alpine/edge/testing vips-tools vips-dev fftw-dev gcc g++ make libc6-compat && apk add git && apk add python && rm -rf /var/cache/apk/' returned a non-zero code: 2

polarathene commented 5 years ago
ERROR: unsatisfiable constraints:
pc:fftw3 (missing):
required by: vips-dev-8.7.0-r0[pc:fftw3]
vips-dev-8.7.0-r0[pc:fftw3]
vips-dev-8.7.0-r0[pc:fftw3]

This appears to be fixed by adding an extra repo main instead of just testing:

RUN apk update && \
    apk add --update --repository http://dl-3.alpinelinux.org/alpine/edge/testing --repository http://dl-cdn.alpinelinux.org/alpine/edge/main vips-tools vips-dev fftw-dev gcc g++ make libc6-compat && \
    apk add git && \
    apk add python && \
    rm -rf /var/cache/apk/*

Note that you might want to use a newer version of node, like 10 or 11 as well, and that Gatsby is at v2 now, which afaik introduced a few changes, so changing the @1.9 to @^2.0.0 might be preferrable as well.

WARNING: This apk-tools is OLD! Some packages might not function properly.

Not super important, but this warning is due to using the edge repo to get vips-dev. It should be avoidable by keeping apk-tools up to date with the edge version as suggested here.

apk add --upgrade apk-tools@edge
polarathene commented 5 years ago

Although the above lets you build vips-dev as well as the npm sharp package(which will notice the global install of libvips and use that to build itself from source?) seems to work fine, gatsby-plugin-sharp for reasons unknown to me seem to fail.

I've come across information that this can be due to using those edge repositories for vips-dev on non-edge alpine images which is said not to be reliable(hence why the breakage is now despite trying to build an image that built fine in the past). You need to either use edge version of alpine or with nodejs v8 or v10, the npm sharp package now supports alpine binaries(no packages in alpines actual package manager though besides edge vip-dev). So remove building this dependency and let the sharp package handle it :)

FROM node:10-alpine

EXPOSE 8000

ARG GATSBY_VERSION=^2.0.0

# Install dev dependencies
RUN set -x \
  && apk add --no-cache \
  g++ \
  git \
  make \
  python2 \
  binutils

# Install gatsby cli and cleanup
RUN set -x \
  && npm install --global gatsby@${GATSBY_VERSION} \
  --no-optional gatsby@${GATSBY_VERSION} \
  && npm cache clean --force

RUN mkdir -p /site
WORKDIR /site
VOLUME /site

COPY ./entry.sh /
RUN chmod +x /entry.sh
ENTRYPOINT ["/entry.sh"]

This is a bit different from the Dockerfile on this repo, I've taken a bit from a similar Dockerfile intended for the official gatsby docker image(which only seems to provide a nginx host rather than any actual gatsby). It could be tweaked a bit more, but is the first Dockerfile I got building properly and working after spending 12 hours trying to suss this out :) (I had success with their Dockerfile too(it's presently in a PR on their repo) with my changes, but wasn't able to get my browser to access/work on localhost:8000 like I could with the above for some reason)