Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

armv7l failed to build docker image #14125

Closed
kamysheblid opened this issue Jun 23, 2020 · 18 comments
Closed

armv7l failed to build docker image #14125

kamysheblid opened this issue Jun 23, 2020 · 18 comments

Comments

@kamysheblid
Copy link

kamysheblid commented Jun 23, 2020

Problem

I am using raspbian with armv7l, and I cannot build the package from source and I cannot build from docker either. Docker does not build for me and this is what the issue is about.

I am not familiar with Ruby and Docker so I cant decipher whats going on.

My guess is that either I am doing the build wrong (and so it gives me an error when building something for a different architecture x86.S because maybe I need to give it more info) or that there is a bug in the program.

My System

uname -a
Linux raspberrypi 4.19.118-v7+ #1311 SMP Mon Apr 27 14:21:24 BST 2020 armv7l GNU/Linux
cat /etc/isssue
Raspbian GNU/Linux 10

To Recreate

I cloned this repo and then cd'd into the directory and did docker build ./

# All done as root user, otherwise normal users fail with permission denied
git clone https://github.com/tootsuite/mastodon
cd mastodon
docker build ./

The Error

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

current directory:
/opt/mastodon/vendor/bundle/ruby/2.6.0/gems/bcrypt-3.1.13/ext/mri
/opt/ruby/bin/ruby -I /opt/ruby/lib/ruby/2.6.0 -r
./siteconf20200623-10-1lu2cbw.rb extconf.rb
creating Makefile

current directory:
/opt/mastodon/vendor/bundle/ruby/2.6.0/gems/bcrypt-3.1.13/ext/mri
make "DESTDIR=" clean

current directory:
/opt/mastodon/vendor/bundle/ruby/2.6.0/gems/bcrypt-3.1.13/ext/mri
make "DESTDIR="
compiling bcrypt_ext.c
compiling crypt_blowfish.c
gcc  -D__SKIP_GNU -I/opt/jemalloc/include -D_FILE_OFFSET_BITS=64   -c -o x86.o
x86.S
x86.S: Assembler messages:
x86.S:202: Error: junk at end of line, first unrecognized character is `,'
<builtin>: recipe for target 'x86.o' failed
make: *** [x86.o] Error 1

make failed, exit code 2

Gem files will remain installed in
/opt/mastodon/vendor/bundle/ruby/2.6.0/gems/bcrypt-3.1.13 for inspection.
Results logged to
/opt/mastodon/vendor/bundle/ruby/2.6.0/extensions/armv7l-linux/2.6.0-static/bcrypt-3.1.13/gem_make.out

An error occurred while installing bcrypt (3.1.13), and Bundler cannot continue.
Make sure that `gem install bcrypt -v '3.1.13' --source 'https://rubygems.org/'`
succeeds before bundling.

In Gemfile:
  devise-two-factor was resolved to 3.1.0, which depends on
    devise was resolved to 4.7.2, which depends on
      bcrypt
The command 'bash -c cd /opt/mastodon &&   bundle config set deployment 'true' &&   bundle config set without 'development test' &&       bundle install -j$(nproc) &&    yarn install --pure-lockfile' returned a non-zero code: 5

My Attempt at a Fix

I went to the Gemfile and added gem 'bcrypt', '~> 3.1.13'. This game me a new error message.

Don't run Bundler as root. Bundler can ask for sudo if it is needed, and
installing your bundle as root will break this application for all non-root
users on this machine.
You are trying to install in deployment mode after changing
your Gemfile. Run `bundle install` elsewhere and add the
updated Gemfile.lock to version control.

If this is a development machine, remove the /opt/mastodon/Gemfile freeze
by running `bundle config unset deployment`.

Bundler is unlocking ruby

You have added to the Gemfile:
* bcrypt (~> 3.1.13)
The command 'bash -c cd /opt/mastodon &&   bundle config set deployment 'true' &&   bundle config set without 'development test' &&       bundle install -j$(nproc) &&    yarn install --pure-lockfile' returned a non-zero code: 16
@SuperSandro2000
Copy link
Contributor

I cloned this repo and then cd'd into the directory and did docker build ./

You only need to run docker as root.

git clone https://github.com/tootsuite/mastodon
cd mastodon
sudo docker build .

@ClearlyClaire
Copy link
Contributor

Yeah, this is a known bug with bcrypt (see #11693)… I'd be inclined to revert it to 3.1.12 again, but apparently 3.1.13 may actually fix stuff on other systems.

To bypass that, don't change Gemfile, but only Gemfile.lock: change bcrypt (3.1.13) to bcrypt (3.1.12), this should be enough.

@kamysheblid
Copy link
Author

Yeah, this is a known bug with bcrypt (see #11693)… I'd be inclined to revert it to 3.1.12 again, but apparently 3.1.13 may actually fix stuff on other systems.

To bypass that, don't change Gemfile, but only Gemfile.lock: change bcrypt (3.1.13) to bcrypt (3.1.12), this should be enough.

I changed the Gemfile.lock as you said and tried to build multiple times. The build got almost to the end, but each time it ends with the same error message

Step 36/39 : RUN cd ~ &&        OTP_SECRET=precompile_placeholder SECRET_KEY_BASE=precompile_placeholder rails assets:precompile &&     yarn cache clean
 ---> Running in d15b6d75a069
`Redis#exists(key)` will return an Integer by default in redis-rb 4.3. The option to explicitly disable this behaviour via `Redis.exists_returns_integer` will be removed in 5.0. You
should use `exists?` instead.
yarn install v1.22.4
[1/6] Validating package.json...
[2/6] Resolving packages...
[3/6] Fetching packages...
info There appears to be trouble with your network connection. Retrying...
info There appears to be trouble with your network connection. Retrying...
info fsevents@2.1.3: The platform "linux" is incompatible with this module.
info "fsevents@2.1.3" is an optional dependency and failed compatibility check. Excluding it from installation.
info fsevents@1.2.13: The platform "linux" is incompatible with this module.
info "fsevents@1.2.13" is an optional dependency and failed compatibility check. Excluding it from installation.
[4/6] Linking dependencies...
warning " > react-redux-loading-bar@4.0.8" has incorrect peer dependency "react-redux@^3.0.0 || ^4.0.0 || ^5.0.0".
[5/6] Building fresh packages...
[6/6] Cleaning modules...
Done in 633.31s.
I, [2020-06-24T07:55:09.921601 #6]  INFO -- : Writing /opt/mastodon/public/assets/doorkeeper/admin/application-a644908e7bab54fb749be0f59fb64a7480bbf9c4c2b79d4a65791cb7ab4d8730.css
I, [2020-06-24T07:55:09.923552 #6]  INFO -- : Writing /opt/mastodon/public/assets/doorkeeper/admin/application-a644908e7bab54fb749be0f59fb64a7480bbf9c4c2b79d4a65791cb7ab4d8730.css.gz
I, [2020-06-24T07:55:09.984430 #6]  INFO -- : Writing /opt/mastodon/public/assets/doorkeeper/application-c93dac2ad9d65e3393e0e2c958481e86ef7a5e5b0f6ce406842a7b99b25a4850.css
I, [2020-06-24T07:55:09.985283 #6]  INFO -- : Writing /opt/mastodon/public/assets/doorkeeper/application-c93dac2ad9d65e3393e0e2c958481e86ef7a5e5b0f6ce406842a7b99b25a4850.css.gz
I, [2020-06-24T07:55:10.001940 #6]  INFO -- : Writing /opt/mastodon/public/assets/pghero/favicon-db10337a56c45eb43c22ff5019546b520fa22c7281d4d385f235cbca67ed26bb.png
I, [2020-06-24T07:55:12.329988 #6]  INFO -- : Writing /opt/mastodon/public/assets/pghero/application-87b7850fd393b53b385603a88e606efeb7d09e6f4c34f9abc1835ddbb41fbe80.js
I, [2020-06-24T07:55:12.330977 #6]  INFO -- : Writing /opt/mastodon/public/assets/pghero/application-87b7850fd393b53b385603a88e606efeb7d09e6f4c34f9abc1835ddbb41fbe80.js.gz
I, [2020-06-24T07:55:12.388422 #6]  INFO -- : Writing /opt/mastodon/public/assets/pghero/application-91a51e56fd7a8fe6fa10d1ccccf54a9e628dc3f4a47682ba17989cf58fd5dfd2.css
I, [2020-06-24T07:55:12.389285 #6]  INFO -- : Writing /opt/mastodon/public/assets/pghero/application-91a51e56fd7a8fe6fa10d1ccccf54a9e628dc3f4a47682ba17989cf58fd5dfd2.css.gz
Compiling...
Compilation failed:

The command '/bin/sh -c cd ~ &&         OTP_SECRET=precompile_placeholder SECRET_KEY_BASE=precompile_placeholder rails assets:precompile &&     yarn cache clean' returned a non-zero
code: 1

If the build is failing because there was a config file I was supposed to edit, I did not do that. I couldnt find any guides in the documentation for building a docker image either.

@ClearlyClaire
Copy link
Contributor

It seems like this failure be webpack being out of memory. In this case, I would try to make sure I have several GB of free RAM before doing the assets:precompile task, or, alternatively, edit config/webpack/production.js to change minimize: true to minimize: false and get rid of the CompressionPlugin and BundleAnalyzerPlugin plugins. This is not recommended as it will create larger files, but it greatly reduces the requirements on available memory in the assets:precompile step.

@kamysheblid
Copy link
Author

It seems like this failure be webpack being out of memory. In this case, I would try to make sure I have several GB of free RAM before doing the assets:precompile task, or, alternatively, edit config/webpack/production.js to change minimize: true to minimize: false and get rid of the CompressionPlugin and BundleAnalyzerPlugin plugins. This is not recommended as it will create larger files, but it greatly reduces the requirements on available memory in the assets:precompile step.

You were right.
I edited the production.js file as you said to change minimize and remove the 2 plugins by commenting them out. Then I added 3GB of swap (since I only have 1GB of ram). It finished and is running. Thank you.

@kamysheblid
Copy link
Author

I've been trying to get it to build since I saw your message. Initially the build kept failing when trying to build db, so I had to do docker-compose build db first before docker-compose build.

Now I get this new error message. I think it is failing because it cannot be built on arm maybe?
Though Im sure Ive seen people say it can be built.

$ docker-compose up
Creating network "mastodon_internal_network" with the default driver
Creating network "mastodon_external_network" with the default driver
Creating mastodon_redis_1 ... done
Creating mastodon_db_1    ... done
Creating mastodon_sidekiq_1   ... done
Creating mastodon_streaming_1 ... done
Creating mastodon_web_1       ... done
Attaching to mastodon_redis_1, mastodon_db_1, mastodon_streaming_1, mastodon_web_1, mastodon_sidekiq_1
redis_1      | 1:C 28 Jun 2020 15:47:10.411 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis_1      | 1:C 28 Jun 2020 15:47:10.411 # Redis version=6.0.5, bits=32, commit=00000000, modified=0, pid=1, just started
redis_1      | 1:C 28 Jun 2020 15:47:10.411 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
streaming_1  | standard_init_linux.go:211: exec user process caused "exec format error"
redis_1      | 1:M 28 Jun 2020 15:47:10.418 # Warning: 32 bit instance detected but no memory limit set. Setting 3 GB maxmemory limit with 'noeviction' policy now.
redis_1      | 1:M 28 Jun 2020 15:47:10.419 * Running mode=standalone, port=6379.
redis_1      | 1:M 28 Jun 2020 15:47:10.419 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
redis_1      | 1:M 28 Jun 2020 15:47:10.419 # Server initialized
redis_1      | 1:M 28 Jun 2020 15:47:10.419 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
redis_1      | 1:M 28 Jun 2020 15:47:10.426 * Loading RDB produced by version 6.0.5
redis_1      | 1:M 28 Jun 2020 15:47:10.426 * RDB age 1800 seconds
redis_1      | 1:M 28 Jun 2020 15:47:10.426 * RDB memory usage when created 0.63 Mb
redis_1      | 1:M 28 Jun 2020 15:47:10.426 * DB loaded from disk: 0.006 seconds
redis_1      | 1:M 28 Jun 2020 15:47:10.426 * Ready to accept connections
db_1         |
web_1        | standard_init_linux.go:211: exec user process caused "exec format error"
sidekiq_1    | standard_init_linux.go:211: exec user process caused "exec format error"
db_1         | PostgreSQL Database directory appears to contain a database; Skipping initialization
db_1         |
db_1         | LOG:  database system was shut down at 2020-06-28 15:46:54 UTC
db_1         | LOG:  MultiXact member wraparound protections are now enabled
db_1         | LOG:  database system is ready to accept connections
db_1         | LOG:  autovacuum launcher started
mastodon_streaming_1 exited with code 1
mastodon_web_1 exited with code 1
mastodon_sidekiq_1 exited with code 0
streaming_1  | standard_init_linux.go:211: exec user process caused "exec format error"
streaming_1  | standard_init_linux.go:211: exec user process caused "exec format error"
streaming_1  | standard_init_linux.go:211: exec user process caused "exec format error"
web_1        | standard_init_linux.go:211: exec user process caused "exec format error"
web_1        | standard_init_linux.go:211: exec user process caused "exec format error"
web_1        | standard_init_linux.go:211: exec user process caused "exec format error"
sidekiq_1    | standard_init_linux.go:211: exec user process caused "exec format error"
sidekiq_1    | standard_init_linux.go:211: exec user process caused "exec format error"
sidekiq_1    | standard_init_linux.go:211: exec user process caused "exec format error"
sidekiq_1    | standard_init_linux.go:211: exec user process caused "exec format error"
mastodon_streaming_1 exited with code 1
mastodon_sidekiq_1 exited with code 1
streaming_1  | standard_init_linux.go:211: exec user process caused "exec format error"
streaming_1  | standard_init_linux.go:211: exec user process caused "exec format error"
streaming_1  | standard_init_linux.go:211: exec user process caused "exec format error"
streaming_1  | standard_init_linux.go:211: exec user process caused "exec format error"
streaming_1  | standard_init_linux.go:211: exec user process caused "exec format error"
mastodon_web_1 exited with code 0
web_1        | standard_init_linux.go:211: exec user process caused "exec format error"
web_1        | standard_init_linux.go:211: exec user process caused "exec format error"
web_1        | standard_init_linux.go:211: exec user process caused "exec format error"
web_1        | standard_init_linux.go:211: exec user process caused "exec format error"
web_1        | standard_init_linux.go:211: exec user process caused "exec format error"
sidekiq_1    | standard_init_linux.go:211: exec user process caused "exec format error"
sidekiq_1    | standard_init_linux.go:211: exec user process caused "exec format error"
sidekiq_1    | standard_init_linux.go:211: exec user process caused "exec format error"
sidekiq_1    | standard_init_linux.go:211: exec user process caused "exec format error"
sidekiq_1    | standard_init_linux.go:211: exec user process caused "exec format error"
sidekiq_1    | standard_init_linux.go:211: exec user process caused "exec format error"
mastodon_streaming_1 exited with code 1
mastodon_web_1 exited with code 1
web_1        | standard_init_linux.go:211: exec user process caused "exec format error"
web_1        | standard_init_linux.go:211: exec user process caused "exec format error"
web_1        | standard_init_linux.go:211: exec user process caused "exec format error"
web_1        | standard_init_linux.go:211: exec user process caused "exec format error"
web_1        | standard_init_linux.go:211: exec user process caused "exec format error"
web_1        | standard_init_linux.go:211: exec user process caused "exec format error"
mastodon_sidekiq_1 exited with code 1
streaming_1  | standard_init_linux.go:211: exec user process caused "exec format error"
streaming_1  | standard_init_linux.go:211: exec user process caused "exec format error"
streaming_1  | standard_init_linux.go:211: exec user process caused "exec format error"
streaming_1  | standard_init_linux.go:211: exec user process caused "exec format error"
streaming_1  | standard_init_linux.go:211: exec user process caused "exec format error"
streaming_1  | standard_init_linux.go:211: exec user process caused "exec format error"
sidekiq_1    | standard_init_linux.go:211: exec user process caused "exec format error"
sidekiq_1    | standard_init_linux.go:211: exec user process caused "exec format error"
sidekiq_1    | standard_init_linux.go:211: exec user process caused "exec format error"
sidekiq_1    | standard_init_linux.go:211: exec user process caused "exec format error"
sidekiq_1    | standard_init_linux.go:211: exec user process caused "exec format error"
sidekiq_1    | standard_init_linux.go:211: exec user process caused "exec format error"
sidekiq_1    | standard_init_linux.go:211: exec user process caused "exec format error"
mastodon_streaming_1 exited with code 1
mastodon_web_1 exited with code 1



@kamysheblid kamysheblid reopened this Jun 28, 2020
@ClearlyClaire
Copy link
Contributor

Hm… can you apply this patch and retry?

diff --git a/Dockerfile b/Dockerfile
index fa6abad5a..fa502b3a8 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -99,20 +99,13 @@ RUN apt update && \
 RUN apt -y --no-install-recommends install \
          libssl1.1 libpq5 imagemagick ffmpeg \
          libicu66 libprotobuf17 libidn11 libyaml-0-2 \
-         file ca-certificates tzdata libreadline8 && \
+         file ca-certificates tzdata libreadline8 tini && \
        apt -y install gcc && \
        ln -s /opt/mastodon /mastodon && \
        gem install bundler && \
        rm -rf /var/cache && \
        rm -rf /var/lib/apt/lists/*
 
-# Add tini
-ENV TINI_VERSION="0.18.0"
-ENV TINI_SUM="12d20136605531b09a2c2dac02ccee85e1b874eb322ef6baf7561cd93f93c855"
-ADD https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini /tini
-RUN echo "$TINI_SUM tini" | sha256sum -c -
-RUN chmod +x /tini
-
 # Copy over mastodon source, and dependencies from building, and set permissions
 COPY --chown=mastodon:mastodon . /opt/mastodon
 COPY --from=build-dep --chown=mastodon:mastodon /opt/mastodon /opt/mastodon
@@ -135,5 +128,5 @@ RUN cd ~ && \
 
 # Set the work dir and the container entry point
 WORKDIR /opt/mastodon
-ENTRYPOINT ["/tini", "--"]
+ENTRYPOINT ["/usr/bin/tini", "--"]
 EXPOSE 3000 4000

@SuperSandro2000
Copy link
Contributor

Why are we even adding tini? Docker has that inbuilt behind the init flag.

@ClearlyClaire
Copy link
Contributor

I don't know. tini has been first explicitly used in #6514 and first explicitly downloaded from github in #10100.

I don't know how people are currently using our Dockerfile and I don't know much about Docker. Can we drop the ENTRYPOINT thing entirely without potentially breaking stuff for our current users?

@SuperSandro2000
Copy link
Contributor

We probably can't drop it without breaking setups. You would need to add -init to the docker run command which we can only change if people use our docker-compose.yml file.

@kamysheblid
Copy link
Author

kamysheblid commented Jun 28, 2020

Still gives an error when I do docker-compose build:

Step 23/34 : RUN apt -y --no-install-recommends install           libssl1.1 libpq5 imagemagick ffmpeg     libicu60 libprotobuf10 libidn11 libyaml-0-2     file ca-certificates tzdata
libreadline7 tini &&    apt -y install gcc &&   ln -s /opt/mastodon /mastodon &&        gem install bundler &&  rm -rf /var/cache &&    rm -rf /var/lib/apt/lists/*
 ---> Running in c32d7d668ce8

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package tini
Service 'web' failed to build: The command '/bin/sh -c apt -y --no-install-recommends install     libssl1.1 libpq5 imagemagick ffmpeg     libicu60 libprotobuf10 libidn11 libyaml-0-2
  file ca-certificates tzdata libreadline7 tini &&      apt -y install gcc &&   ln -s /opt/mastodon /mastodon &&        gem install bundler &&  rm -rf /var/cache &&    rm -rf /var/lib/apt/lists/*' returned a non-zero code: 100

My Dockerfile:

FROM ubuntu:18.04 as build-dep

# Use bash for the shell
SHELL ["bash", "-c"]

# Install Node v12 (LTS)
ENV NODE_VER="12.16.1"
RUN     ARCH= && \
    dpkgArch="$(dpkg --print-architecture)" && \
  case "${dpkgArch##*-}" in \
    amd64) ARCH='x64';; \
    ppc64el) ARCH='ppc64le';; \
    s390x) ARCH='s390x';; \
    arm64) ARCH='arm64';; \
    armhf) ARCH='armv7l';; \
    i386) ARCH='x86';; \
    *) echo "unsupported architecture"; exit 1 ;; \
  esac && \
    echo "Etc/UTC" > /etc/localtime && \
        apt update && \
        apt -y install wget python && \
        cd ~ && \
        wget https://nodejs.org/download/release/v$NODE_VER/node-v$NODE_VER-linux-$ARCH.tar.gz && \
        tar xf node-v$NODE_VER-linux-$ARCH.tar.gz && \
        rm node-v$NODE_VER-linux-$ARCH.tar.gz && \
        mv node-v$NODE_VER-linux-$ARCH /opt/node

# Install jemalloc
ENV JE_VER="5.2.1"
RUN apt update && \
        apt -y install make autoconf gcc g++ && \
        cd ~ && \
        wget https://github.com/jemalloc/jemalloc/archive/$JE_VER.tar.gz && \
        tar xf $JE_VER.tar.gz && \
        cd jemalloc-$JE_VER && \
        ./autogen.sh && \
        ./configure --prefix=/opt/jemalloc && \
        make -j$(nproc) > /dev/null && \
        make install_bin install_include install_lib

# Install Ruby
ENV RUBY_VER="2.6.6"
ENV CPPFLAGS="-I/opt/jemalloc/include"
ENV LDFLAGS="-L/opt/jemalloc/lib/"
RUN apt update && \
        apt -y install build-essential \
                bison libyaml-dev libgdbm-dev libreadline-dev \
                libncurses5-dev libffi-dev zlib1g-dev libssl-dev && \
        cd ~ && \
        wget https://cache.ruby-lang.org/pub/ruby/${RUBY_VER%.*}/ruby-$RUBY_VER.tar.gz && \
        tar xf ruby-$RUBY_VER.tar.gz && \
        cd ruby-$RUBY_VER && \
        ./configure --prefix=/opt/ruby \
          --with-jemalloc \
          --with-shared \
          --disable-install-doc && \
        ln -s /opt/jemalloc/lib/* /usr/lib/ && \
        make -j$(nproc) > /dev/null && \
        make install

ENV PATH="${PATH}:/opt/ruby/bin:/opt/node/bin"

RUN npm install -g yarn && \
        gem install bundler && \
        apt update && \
        apt -y install git libicu-dev libidn11-dev \
        libpq-dev libprotobuf-dev protobuf-compiler

COPY Gemfile* package.json yarn.lock /opt/mastodon/

RUN cd /opt/mastodon && \
  bundle config set deployment 'true' && \
  bundle config set without 'development test' && \
        bundle install -j$(nproc) && \
        yarn install --pure-lockfile

FROM ubuntu:18.04

# Copy over all the langs needed for runtime
COPY --from=build-dep /opt/node /opt/node
COPY --from=build-dep /opt/ruby /opt/ruby
COPY --from=build-dep /opt/jemalloc /opt/jemalloc

# Add more PATHs to the PATH
ENV PATH="${PATH}:/opt/ruby/bin:/opt/node/bin:/opt/mastodon/bin"

# Create the mastodon user
ARG UID=991
ARG GID=991
RUN apt update && \
        echo "Etc/UTC" > /etc/localtime && \
        ln -s /opt/jemalloc/lib/* /usr/lib/ && \
        apt install -y whois wget && \
        addgroup --gid $GID mastodon && \
        useradd -m -u $UID -g $GID -d /opt/mastodon mastodon && \
        echo "mastodon:`head /dev/urandom | tr -dc A-Za-z0-9 | head -c 24 | mkpasswd -s -m sha-256`" | chpasswd

# Install mastodon runtime deps
RUN apt -y --no-install-recommends install \
          libssl1.1 libpq5 imagemagick ffmpeg \
          libicu60 libprotobuf10 libidn11 libyaml-0-2 \
          file ca-certificates tzdata libreadline7 tini && \
        apt -y install gcc && \
        ln -s /opt/mastodon /mastodon && \
        gem install bundler && \
        rm -rf /var/cache && \
        rm -rf /var/lib/apt/lists/*

# Add tini
#ENV TINI_VERSION="0.18.0"
#ENV TINI_SUM="12d20136605531b09a2c2dac02ccee85e1b874eb322ef6baf7561cd93f93c855"
#ADD https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini /tini
#RUN echo "$TINI_SUM tini" | sha256sum -c -
#RUN chmod +x /tini

# Copy over mastodon source, and dependencies from building, and set permissions
COPY --chown=mastodon:mastodon . /opt/mastodon
COPY --from=build-dep --chown=mastodon:mastodon /opt/mastodon /opt/mastodon

# Run mastodon services in prod mode
ENV RAILS_ENV="production"
ENV NODE_ENV="production"

# Tell rails to serve static files
ENV RAILS_SERVE_STATIC_FILES="true"
ENV BIND="0.0.0.0"

# Set the run user
USER mastodon

# Precompile assets
RUN cd ~ && \
        OTP_SECRET=precompile_placeholder SECRET_KEY_BASE=precompile_placeholder rails assets:precompile && \
        yarn cache clean

# Set the work dir and the container entry point
WORKDIR /opt/mastodon
ENTRYPOINT ["/usr/bin/tini", "--"]
EXPOSE 3000 4000

@ClearlyClaire
Copy link
Contributor

Ah, right, tini isn't in bionic… could you apply glitch-soc@9ea91bb too?

@kamysheblid
Copy link
Author

kamysheblid commented Jun 29, 2020

Ah, right, tini isn't in bionic… could you apply glitch-soc@9ea91bb too?

Ill try to automate this so I dont make the same stupid mistake again. I am using a patch file arm.patch to automate it a little.

$ git clone https://github.com/tootsuite/mastodon
Cloning into 'mastodon'...
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 112479 (delta 1), reused 0 (delta 0), pack-reused 112474
Receiving objects: 100% (112479/112479), 103.80 MiB | 3.17 MiB/s, done.
Resolving deltas: 100% (80501/80501), done.
Checking out files: 100% (6170/6170), done.

$ patch -Nup0 -i ../arm.patch
patching file config/webpack/production.js
patching file Dockerfile
patching file Gemfile.lock

$ cp .env.{nanobox,production}

$ nohup docker-compose build &

Here is my Dockerfile. (I feel like Im spamming this page, so Ill just dumped things into pastebin unless someone says otherwise)

This is the output:
https://pastebin.com/vFNXaY3D

apt gives some permission error when using tar (apparently the error can be supressed using -m or something, but I dont have access to tar from deb):

Replacing files in old package libgcc1:armhf (1:9.2.1-21ubuntu1) ...
Setting up libgcc-s1:armhf (10-20200411-0ubuntu1) ...
(Reading database ... 4133 files and directories currently installed.)
Preparing to unpack .../libc6_2.31-0ubuntu9_armhf.deb ...
debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (Can't locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains:
/etc/perl /usr/local/lib/arm-linux-gnueabihf/perl/5.30.0 /usr/local/share/perl/5.30.0 /usr/lib/arm-linux-gnueabihf
/perl5/5.30 /usr/share/perl5 /usr/lib/arm-linux-gnueabihf/perl/5.30 /usr/share/perl/5.30 /usr/local/lib/site_perl /usr/lib
/arm-linux-gnueabihf/perl-base) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7.)
debconf: falling back to frontend: Teletype
Checking for services that may need to be restarted...
Checking init scripts...
Checking for services that may need to be restarted...
Checking init scripts...
Nothing to restart.
Unpacking libc6:armhf (2.31-0ubuntu9) over (2.30-0ubuntu3) ...
tar: ./control: Cannot utime: Operation not permitted
tar: ./md5sums: Cannot utime: Operation not permitted
tar: ./shlibs: Cannot utime: Operation not permitted
tar: ./symbols: Cannot utime: Operation not permitted
tar: ./triggers: Cannot utime: Operation not permitted
tar: .: Cannot utime: Operation not permitted
tar: Exiting with failure status due to previous errors
dpkg-deb: error: tar subprocess returned error exit status 2
dpkg: error processing archive /var/cache/apt/archives/libcrypt1_1%3a4.4.10-10ubuntu4_armhf.deb (--unpack):
 dpkg-deb --control subprocess returned error exit status 2
Errors were encountered while processing:
 /var/cache/apt/archives/libcrypt1_1%3a4.4.10-10ubuntu4_armhf.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

I can't tell if there is something wrong with the ubuntu:20.04 image for armhf. When I try to install any package it errors about this one package libc-bin : Depends: libc6 (< 2.31) but 2.31-0ubuntu9 is to be installed and how nothing else (sudo, wget, python, perl, etc) can be installed/upgraded because of this. Even apt -y upgrade fails with the same error:

 libc-bin : Depends: libc6 (< 2.31) but 2.31-0ubuntu9 is installed
 libc6 : Depends: libcrypt1 (>= 1:4.4.10-10ubuntu4) but it is not installed

@ClearlyClaire
Copy link
Contributor

https://bugs.launchpad.net/ubuntu/+source/glibc/+bug/1867675

Apparently this is an issue with running too recent ubuntu versions in Docker on armhf, and the upcoming fix would be for the host system running Docker, not the image/within the container.

@kamysheblid
Copy link
Author

kamysheblid commented Jun 30, 2020

https://bugs.launchpad.net/ubuntu/+source/glibc/+bug/1867675

Apparently this is an issue with running too recent ubuntu versions in Docker on armhf, and the upcoming fix would be for the host system running Docker, not the image/within the container.

I finaly built it and learned a lot about Docker along the way.

diff --git a/Dockerfile b/Dockerfile
index fa6abad5a..b4b5c6c1c 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,4 +1,4 @@
-FROM ubuntu:20.04 as build-dep
+FROM ubuntu as build-dep
 
 # Use bash for the shell
 SHELL ["bash", "-c"]
@@ -74,7 +74,7 @@ RUN cd /opt/mastodon && \
 	bundle install -j$(nproc) && \
 	yarn install --pure-lockfile
 
-FROM ubuntu:20.04
+FROM ubuntu
 
 # Copy over all the langs needed for runtime
 COPY --from=build-dep /opt/node /opt/node
@@ -98,25 +98,23 @@ RUN apt update && \
 # Install mastodon runtime deps
 RUN apt -y --no-install-recommends install \
 	  libssl1.1 libpq5 imagemagick ffmpeg \
-	  libicu66 libprotobuf17 libidn11 libyaml-0-2 \
-	  file ca-certificates tzdata libreadline8 && \
+	  libicu60 libprotobuf10 libidn11 libyaml-0-2 \
+	  file ca-certificates tzdata libreadline7 && \
 	apt -y install gcc && \
 	ln -s /opt/mastodon /mastodon && \
 	gem install bundler && \
 	rm -rf /var/cache && \
 	rm -rf /var/lib/apt/lists/*
 
-# Add tini
-ENV TINI_VERSION="0.18.0"
-ENV TINI_SUM="12d20136605531b09a2c2dac02ccee85e1b874eb322ef6baf7561cd93f93c855"
-ADD https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini /tini
-RUN echo "$TINI_SUM tini" | sha256sum -c -
-RUN chmod +x /tini
-
 # Copy over mastodon source, and dependencies from building, and set permissions
 COPY --chown=mastodon:mastodon . /opt/mastodon
 COPY --from=build-dep --chown=mastodon:mastodon /opt/mastodon /opt/mastodon
 
+# Install tini
+ENV TINI_VERSION="0.18.0"
+ADD https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini-armhf /usr/bin/tini 
+RUN chmod +x /usr/bin/tini
+
 # Run mastodon services in prod mode
 ENV RAILS_ENV="production"
 ENV NODE_ENV="production"
@@ -135,5 +133,5 @@ RUN cd ~ && \
 
 # Set the work dir and the container entry point
 WORKDIR /opt/mastodon
-ENTRYPOINT ["/tini", "--"]
+ENTRYPOINT ["/usr/bin/tini", "--"]
 EXPOSE 3000 4000
diff --git a/Gemfile.lock b/Gemfile.lock
index d99e0db7f..01ec459ca 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -107,7 +107,7 @@ GEM
       aws-sigv4 (~> 1.1)
     aws-sigv4 (1.2.1)
       aws-eventstream (~> 1, >= 1.0.2)
-    bcrypt (3.1.13)
+    bcrypt (3.1.12)
     better_errors (2.7.1)
       coderay (>= 1.0.0)
       erubi (>= 1.0.0)
diff --git a/config/webpack/production.js b/config/webpack/production.js
index bceffaf5c..c9c23d906 100644
--- a/config/webpack/production.js
+++ b/config/webpack/production.js
@@ -31,7 +31,7 @@ module.exports = merge(sharedConfig, {
   stats: 'normal',
   bail: true,
   optimization: {
-    minimize: true,
+    minimize: false,
     minimizer: [
       new TerserPlugin({
         cache: true,
@@ -42,16 +42,6 @@ module.exports = merge(sharedConfig, {
   },
 
   plugins: [
-    new CompressionPlugin({
-      filename: '[path].gz[query]',
-      cache: true,
-      test: /\.(js|css|html|json|ico|svg|eot|otf|ttf|map)$/,
-    }),
-    new BundleAnalyzerPlugin({ // generates report.html
-      analyzerMode: 'static',
-      openAnalyzer: false,
-      logLevel: 'silent', // do not bother Webpacker, who runs with --json and parses stdout
-    }),
     new OfflinePlugin({
       publicPath: output.publicPath, // sw.js must be served from the root to avoid scope issues
       safeToUseOptionalCaches: true,

EDIT: Fixed an error in diff above

@ClearlyClaire
Copy link
Contributor

I don't know if it should be closed, us using a version of Ubuntu that doesn't work on some platforms isn't great, and so is us downloading a x64 binary isn't great either.

@kamysheblid
Copy link
Author

Do you want me to open it again?

Maybe if I have time later I might help make a multi-arch docker build.

Im surprised mastodon doesnt use make to auto build this thing.

@SuperSandro2000
Copy link
Contributor

Basically docker run --rm --privileged multiarch/qemu-user-static --reset -p yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants