Docker fails to deploy rails app with Imagemagick

I’m struggling to get a rails app deployed, I had minimal issues launching it but I had to add imagemagick and flyctl deploy (with or without my addition of imagemagick). Whenever I try to deploy I get this error:

Update available 0.0.330 -> v0.0.332.
Run "fly version update" to upgrade.
==> Verifying app config
--> Verified app config
==> Building image
==> Creating build context
--> Creating build context done
==> Building image with Docker
--> docker host: 20.10.13 linux x86_64
[+] Building 50.2s (0/1)
[+] Building 29.1s (12/23)
 => [internal] load remote build context                                                                                  0.0s
 => copy /context /                                                                                                      12.4s
 => resolve image config for docker.io/docker/dockerfile:experimental                                                     0.7s
 => CACHED docker-image://docker.io/docker/dockerfile:experimental@sha256:600e5c62eedff338b3f7a0850beb7c05866e0ef27b2d2e  0.0s
 => [internal] load metadata for quay.io/evl.ms/fullstaq-ruby:2.7.1-jemalloc-slim                                         0.3s
 => [base 1/6] FROM quay.io/evl.ms/fullstaq-ruby:2.7.1-jemalloc-slim@sha256:9bf347162343dbcff69d7418a7535116ac9d5c76bbec  0.0s
 => CACHED [base 2/6] RUN mkdir /app                                                                                      0.0s
 => CACHED [base 3/6] WORKDIR /app                                                                                        0.0s
 => CACHED [base 4/6] RUN mkdir -p tmp/pids                                                                               0.0s
 => CACHED [base 5/6] RUN curl https://get.volta.sh | bash                                                                0.0s
 => CACHED [base 6/6] RUN volta install node@16 && volta install yarn                                                     0.0s
 => ERROR [stage-4 1/5] RUN --mount=type=cache,id=prod-apt-cache,sharing=locked,target=/var/cache/apt     --mount=type=c  1.0s
------
 > [stage-4 1/5] RUN --mount=type=cache,id=prod-apt-cache,sharing=locked,target=/var/cache/apt     --mount=type=cache,id=prod-apt-lib,sharing=locked,target=/var/lib/apt     apt-get update -qq &&     apt-get install --no-install-recommends -y     postgresql-client file vim curl gzip libsqlite3-0 imagemagick     && rm -rf /var/lib/apt/lists /var/cache/apt/archives:
#12 0.921 W: Failed to fetch http://deb.debian.org/debian/dists/buster/InRelease  Error writing to output file - write (28: No space left on device) [IP: 151.101.126.132 80]
#12 0.921 W: Failed to fetch http://security.debian.org/debian-security/dists/buster/updates/InRelease  Error writing to output file - write (28: No space left on device) [IP: 151.101.130.132 80]
#12 0.921 W: Failed to fetch http://deb.debian.org/debian/dists/buster-updates/InRelease  Error writing to output file - write (28: No space left on device) [IP: 151.101.126.132 80]
#12 0.921 W: Failed to fetch https://apt.fullstaqruby.org/dists/debian-10/InRelease  Error writing to output file - write (28: No space left on device) [IP: 142.251.41.80 443]
#12 0.921 W: Some index files failed to download. They have been ignored, or old ones used instead.
#12 0.937 Reading package lists...
#12 0.955 Building dependency tree...
#12 0.958 E: Unable to locate package postgresql-client
#12 0.958 E: Unable to locate package file
#12 0.958 E: Unable to locate package vim
#12 0.958 E: Unable to locate package imagemagick
------
Error failed to fetch an image or build from source: error building: executor failed running [/bin/bash -c apt-get update -qq &&     apt-get install --no-install-recommends -y     ${PROD_PACKAGES}     && rm -rf /var/lib/apt/lists /var/cache/apt/archives]: exit code: 100

(let me know if a longer stack trace from the deployment would help).

Most of this was done by flyctl launch except the addition of Imagemagick:

# syntax = docker/dockerfile:experimental
ARG RUBY_VERSION=2.7.1
ARG VARIANT=jemalloc-slim
FROM quay.io/evl.ms/fullstaq-ruby:${RUBY_VERSION}-${VARIANT} as base

ARG NODE_VERSION=16
ARG BUNDLER_VERSION=2.1.4

ARG RAILS_ENV=production
ENV RAILS_ENV=${RAILS_ENV}

ENV RAILS_SERVE_STATIC_FILES true
ENV RAILS_LOG_TO_STDOUT true

ARG BUNDLE_WITHOUT=development:test
ARG BUNDLE_PATH=vendor/bundle
ENV BUNDLE_PATH ${BUNDLE_PATH}
ENV BUNDLE_WITHOUT ${BUNDLE_WITHOUT}

RUN mkdir /app
WORKDIR /app
RUN mkdir -p tmp/pids

SHELL ["/bin/bash", "-c"]

RUN curl https://get.volta.sh | bash

ENV BASH_ENV ~/.bashrc
ENV VOLTA_HOME /root/.volta
ENV PATH $VOLTA_HOME/bin:/usr/local/bin:$PATH

RUN volta install node@${NODE_VERSION} && volta install yarn

FROM base as build_deps

ARG DEV_PACKAGES="git build-essential libpq-dev wget vim curl gzip xz-utils libsqlite3-dev"
ENV DEV_PACKAGES ${DEV_PACKAGES}

RUN --mount=type=cache,id=dev-apt-cache,sharing=locked,target=/var/cache/apt \
    --mount=type=cache,id=dev-apt-lib,sharing=locked,target=/var/lib/apt \
    apt-get update -qq && \
    apt-get install --no-install-recommends -y ${DEV_PACKAGES} \
    && rm -rf /var/lib/apt/lists /var/cache/apt/archives

FROM build_deps as gems

RUN gem install -N bundler -v ${BUNDLER_VERSION}

COPY Gemfile* ./
RUN bundle install &&  rm -rf vendor/bundle/ruby/*/cache

FROM build_deps as node_modules

COPY package*json ./
COPY yarn.* ./

RUN if [ -f "yarn.lock" ]; then \
    yarn install; \
    elif [ -f "package-lock.json" ]; then \
    npm install; \
    else \
    mkdir node_modules; \
    fi

FROM base

# I added imagemagick as a package
ARG PROD_PACKAGES="postgresql-client file vim curl gzip libsqlite3-0 imagemagick"
ENV PROD_PACKAGES=${PROD_PACKAGES}

RUN --mount=type=cache,id=prod-apt-cache,sharing=locked,target=/var/cache/apt \
    --mount=type=cache,id=prod-apt-lib,sharing=locked,target=/var/lib/apt \
    apt-get update -qq && \
    apt-get install --no-install-recommends -y \
    ${PROD_PACKAGES} \
    && rm -rf /var/lib/apt/lists /var/cache/apt/archives

COPY --from=gems /app /app
COPY --from=node_modules /app/node_modules /app/node_modules

ENV SECRET_KEY_BASE 1

COPY . .

RUN bundle exec rails assets:precompile

ENV PORT 8080

ARG SERVER_COMMAND="bundle exec puma -C config/puma.rb"
ENV SERVER_COMMAND ${SERVER_COMMAND}
CMD ${SERVER_COMMAND}

My Docker knowledge is limited and mostly related to legacy PHP projects, please let me know if there is any other info that would be helpful in resolving this. I’m open to any suggestions.

A longer trace would help here, to see the actual error reported. If you’re having trouble seeing one, try using the latest flyctl with NO_COLOR=1 fly deploy --build-only to get a plaintext build trace that shows all output.

Thanks. I’m pasted the whole stacktrace now. It’s not the latest version, I’m using 0.0.330, I’ve run fly version update several times and haven’t been able to upgrade. Unless upgrading would impact the deployment issue I’d like to save that issue for another day.

Ah, this is hard to notice, but there’s a line:

Error writing to output file - write (28: No space left on device) [IP: 151.101.126.132 80]

This likely means your local Docker environment has run out of space. You can confirm this by trying fly deploy --remote-only to use your remote builder instance.

Awesome, thank you so much!