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

how to install on M1 (running in a container) #104

Closed
wdiechmann opened this issue Dec 20, 2021 · 12 comments
Closed

how to install on M1 (running in a container) #104

wdiechmann opened this issue Dec 20, 2021 · 12 comments

Comments

@wdiechmann
Copy link

wdiechmann commented Dec 20, 2021

Let me start by apologizing for 'fuming in the wrong kitchen' (this is not tailwindcss-rails per se - I actually anticipate it doing exactly what it should! It's much more likely some Docker container "thing" that lures the container into reporting "aarch64-linux" which I -- by now -- have learned repeatedly, is not a supported architecture by tailwindcss-rails !

Reckoning me not being alone on this crusade I risk the barrage and go forth:

Question: Does anyone know how to get Rails 7.0.0 to install with TailwindCSS in containers on the Apple M1 ?

the sordid details

Apple's latest/finest 'sand' - the M1 - is screaming fast but somewhat of a challenge to run Docker containers on;

Like with the sparkling fresh Rails 7.0.0 when doing rails new . --css=tailwind

I have a Dockerfile like this

[ update: 2021-12-20 22:30 CEST: the from image is actually arm64v8/ruby ]

FROM arm64v8/ruby:3.03
#
# I took great inspiration in this work by [Will Schenk](https://willschenk.com/articles/2020/rails_in_docker/)
#

WORKDIR /app

COPY src/Gemfile /app/Gemfile
COPY src/Gemfile.lock /app/Gemfile.lock
RUN gem install bundler && bundle install


# Add a script to be executed every time the container starts.
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000

# Configure the main process to run when running the image
CMD ["rails","server","-b","0.0.0.0"]

and a docker-compose.yml like this (the db part is merely for completeness - it serves no purpose in this trickery

#
# Most if not all of it is a blatant c/p from
# Will Schenk's https://willschenk.com/articles/2020/rails_in_docker/
#
version: "3.9"
services:
  db:
    build: mysql 
    platform: linux/x86_64
    image: mindling_db
    container_name: mindling_db
    command: [ "--default-authentication-plugin=mysql_native_password" ]
    ports:
      - "3306:3306"
    volumes:
      - ~/src/mysql_data:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: secret
      MYSQL_DATABASE: mindling_development
  mindling:
    platform: linux/arm64/v8
    build: .
    command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
    volumes:
      - ./src:/app
    ports:
      - "3000:3000"
    depends_on:
      - db

When I let it 'rip' -- hoping to install tailwindcss goodness after the fact (it failed during the initial rails new too ) -- I get this sad reply:

√ mindling % x rails tailwindcss:install
Creating mindling_mindling_run ... done
Add Tailwindcss include tags and container element in application layout
File unchanged! The supplied flag value not found!  app/views/layouts/application.html.erb
File unchanged! The supplied flag value not found!  app/views/layouts/application.html.erb
File unchanged! The supplied flag value not found!  app/views/layouts/application.html.erb
Build into app/assets/builds
       exist  app/assets/builds
   identical  app/assets/builds/.keep
File unchanged! The supplied flag value not found!  app/assets/config/manifest.js
File unchanged! The supplied flag value not found!  .gitignore
File unchanged! The supplied flag value not found!  Procfile.dev
Add bin/dev to start foreman
   identical  bin/dev
Compile initial Tailwind build
         run  rails tailwindcss:build from "."
ERROR: tailwindcss-rails does not support the aarch64-linux platform
Please install tailwindcss following instructions at https://tailwindcss.com/docs/installation

but for some reason the container keeps 'bragging about being' aarch64-linux 😆

So - now my heading (and my bearing for that matter too) is somewhat lost!

How do I get my containers to swallow their (linux) pride and start behaving?

@flavorjones
Copy link
Member

@wdiechmann - Sorry you're having a problem, I'll try to help.

Inside your docker container, what does ruby -v emit? What does gem env emit?

@wdiechmann
Copy link
Author

oh no - don't be sorry - it's me being sorry not able to offer any help solving this (giving back just something to the community) - but I'll take that help any given (Monday) 🤣

root@c9d65417ca89:/app# ruby -v
ruby 3.0.3p157 (2021-11-24 revision 3fb7d2cadc) [aarch64-linux]
root@c9d65417ca89:/app# gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 3.2.32
  - RUBY VERSION: 3.0.3 (2021-11-24 patchlevel 157) [aarch64-linux]
  - INSTALLATION DIRECTORY: /usr/local/bundle
  - USER INSTALLATION DIRECTORY: /root/.local/share/gem/ruby/3.0.0
  - RUBY EXECUTABLE: /usr/local/bin/ruby
  - GIT EXECUTABLE: /usr/bin/git
  - EXECUTABLE DIRECTORY: /usr/local/bundle/bin
  - SPEC CACHE DIRECTORY: /root/.local/share/gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /usr/local/etc
  - RUBYGEMS PLATFORMS:
     - ruby
     - aarch64-linux
  - GEM PATHS:
     - /usr/local/bundle
     - /root/.local/share/gem/ruby/3.0.0
     - /usr/local/lib/ruby/gems/3.0.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
     - "install" => "--no-document"
     - "update" => "--no-document"
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /usr/local/bundle/bin
     - /usr/local/sbin
     - /usr/local/bin
     - /usr/sbin
     - /usr/bin
     - /sbin
     - /bin
root@c9d65417ca89:/app# 

@wdiechmann
Copy link
Author

I guess I'm on my way to "the land of containers" -- pulling the finer print on the container underlines that tailwindcss-rails is entirely without fault (I think)

"Architecture": "arm64",

√ mindling % docker image inspect mindling_mindling
[
    {
        "Id": "sha256:f242988c9cb499c9800d1a63658e3b59532b9363b7c69d5e78fff54acb4ff2bb",
        "RepoTags": [
            "mindling_mindling:latest"
        ],
        "RepoDigests": [],
        "Parent": "sha256:f81e1251a06caef8172645d6461f5f0c352bd201538797c31831a1d3575f28d3",
        "Comment": "",
        "Created": "2021-12-20T21:33:33.867996384Z",
        "Container": "ec400067e25d3c5fde6af04d97b78efa0c97c4fb118429e2c6a418e52b1ece43",
        "ContainerConfig": {
            "Hostname": "ec400067e25d",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "3000/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/bundle/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "LANG=C.UTF-8",
                "RUBY_MAJOR=3.0",
                "RUBY_VERSION=3.0.3",
                "RUBY_DOWNLOAD_SHA256=88cc7f0f021f15c4cd62b1f922e3a401697f7943551fe45b1fdf4f2417a17a9c",
                "GEM_HOME=/usr/local/bundle",
                "BUNDLE_SILENCE_ROOT_WARNING=1",
                "BUNDLE_APP_CONFIG=/usr/local/bundle"
            ],
            "Cmd": [
                "/bin/sh",
                "-c",
                "#(nop) ",
                "CMD [\"rails\" \"server\" \"-b\" \"0.0.0.0\"]"
            ],
            "Image": "sha256:f81e1251a06caef8172645d6461f5f0c352bd201538797c31831a1d3575f28d3",
            "Volumes": null,
            "WorkingDir": "/app",
            "Entrypoint": [
                "entrypoint.sh"
            ],
            "OnBuild": null,
            "Labels": {}
        },
        "DockerVersion": "20.10.11",
        "Author": "",
        "Config": {
            "Hostname": "",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "3000/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/bundle/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "LANG=C.UTF-8",
                "RUBY_MAJOR=3.0",
                "RUBY_VERSION=3.0.3",
                "RUBY_DOWNLOAD_SHA256=88cc7f0f021f15c4cd62b1f922e3a401697f7943551fe45b1fdf4f2417a17a9c",
                "GEM_HOME=/usr/local/bundle",
                "BUNDLE_SILENCE_ROOT_WARNING=1",
                "BUNDLE_APP_CONFIG=/usr/local/bundle"
            ],
            "Cmd": [
                "rails",
                "server",
                "-b",
                "0.0.0.0"
            ],
            "Image": "sha256:f81e1251a06caef8172645d6461f5f0c352bd201538797c31831a1d3575f28d3",
            "Volumes": null,
            "WorkingDir": "/app",
            "Entrypoint": [
                "entrypoint.sh"
            ],
            "OnBuild": null,
            "Labels": null
        },
        "Architecture": "arm64",
        "Variant": "v8",
        "Os": "linux",
        "Size": 957009464,
        "VirtualSize": 957009464,
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/a4370d7bfef94f3dcf8b8db5fe226624dcf27f7ed9c7fed7ace4e40c3ab1367b/diff:/var/lib/docker/overlay2/db5b95d78a781e3fb20c98bb761e6ba4946a8fbb8fd3d8a9c2b16a5ea90dc201/diff:/var/lib/docker/overlay2/4013dfe6f62521d8b8627bc4e41f0cf6770eef74baf479ec825684fb80dae4dd/diff:/var/lib/docker/overlay2/d4d2e3f962b4a401b5a46a9e9cc76c5263291627cca00c264b46814730eaeda9/diff:/var/lib/docker/overlay2/8a5f9592b1abe839ad86f0e73e45b447e30bc6b1ce6b65721e44c3c6d7ae208e/diff:/var/lib/docker/overlay2/02977e98c260724224787cba6b86c5ace98982886d7bee3b72dc1813a8b51ad0/diff:/var/lib/docker/overlay2/dfb68af05d27880d2cd39308a453bb1016d7352b7205962230279d4ee9c50b43/diff:/var/lib/docker/overlay2/befe96c96561bff26a9102522102eec1769bc61e88363a84fbaa79b3c9ccb431/diff:/var/lib/docker/overlay2/f17555df2a4471d59d2938c0e7b738abc4f74c192fb37f600b802f3d07a05524/diff:/var/lib/docker/overlay2/038d1d0969dcb2cb9c60f44345d5bf902394ad70916cb6bd76089ad1ef2b92b3/diff:/var/lib/docker/overlay2/7f404f031fd131dde9f192e76d85956fd67c18e167941525d954cd6e70b20db5/diff:/var/lib/docker/overlay2/fbfcf813065f89ee158fa294ee3c17edd524ba035fa853d93c3a5b158368d3b6/diff:/var/lib/docker/overlay2/633e0411278e3fd81b0db049d6f4b96674de5bb0d65107d13313ede2c14d55ee/diff",
                "MergedDir": "/var/lib/docker/overlay2/ff15dc7996672f3d68ae0e0eb80b47401b3cc4deb3ac29f0d83253d72de1b32c/merged",
                "UpperDir": "/var/lib/docker/overlay2/ff15dc7996672f3d68ae0e0eb80b47401b3cc4deb3ac29f0d83253d72de1b32c/diff",
                "WorkDir": "/var/lib/docker/overlay2/ff15dc7996672f3d68ae0e0eb80b47401b3cc4deb3ac29f0d83253d72de1b32c/work"
            },
            "Name": "overlay2"
        },
        "RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:c83a1e9f8928c8475c4b26facacb6c90fd76afc61e6b02b0ed07084eab6cd996",
                "sha256:ebb785818cd967192bc651106ed517ee4fdbf4da86f9a2ae511dff790451d68f",
                "sha256:2c62d9fb0ac2cea00189bb9e3ccec5544ca0f16fd97f465abdafe7315797af02",
                "sha256:621d723cc532662f594c373ae0172da6b372b24a049dc69fd9f0944a50816756",
                "sha256:31f97397a8f27f75dd9e59d423c4510e6cf293d6a3013a9a25d987ed650343f0",
                "sha256:c6fb555e9c0add89d68368c0fa9d1ff09ae0f79c8c98eaf7bd5038041cf291aa",
                "sha256:ac2c27936d8a1190347ee837640a117832567d09e577614f323b1f37af77f280",
                "sha256:270675516ae7d76b73c9a1ef050a89cc37b723b57c3c39d9d89be504150637ea",
                "sha256:10966c0a6ba9ad099d56d47b3cd73c59122f9e43c0fd8ce85ff5160b1d812da0",
                "sha256:74bc7e62c0cd2089b50cee7195cbaea2fb969aa397c7f5f8711bb9b8d72aff7d",
                "sha256:a717f9a8a13b8417746e49e3fd8768c0421d3b358cfab7494de153aae2364625",
                "sha256:1c1eba780ce65324e9a31e3240736e1ca718345baa98579e11a537b5b6ca1812",
                "sha256:716d67ee2ed8d6c5236012ee51e738a897d75666514e1b820efa6ae36db338ea",
                "sha256:716d67ee2ed8d6c5236012ee51e738a897d75666514e1b820efa6ae36db338ea"
            ]
        },
        "Metadata": {
            "LastTagTime": "2021-12-20T21:33:34.214568176Z"
        }
    }
]

@flavorjones
Copy link
Member

@wdiechmann OK, since your version of Ruby says it's aarch64-linux that's why it's trying to not installing x86_64-linux platform gems.

Your best bet is to follow the instructions at https://tailwindcss.com/docs/installation to install tailwindcss via npm.

@wdiechmann
Copy link
Author

well - roger that - but I'm not going down the npm gauntlet again 🤣

not with this beautiful piece of 'ware letting out sirene songs from those cliffs up high 😄

but thx a bunch for holding my hand and administering a cold handkerchief on my forehead ❤️

@wdiechmann
Copy link
Author

BTW - this docker/for-linux#1170 confirms it and now I just have to find out how to impersonate the correct platform for tailwindcss to ask for

it certainly is xmas all around 😌

@wdiechmann
Copy link
Author

I'm addressing the issue here - placing all my faith in the "Gods of Container Heaven"

@flavorjones
Copy link
Member

I think we can close this @dhh

@dhh dhh closed this as completed Dec 21, 2021
@wdiechmann
Copy link
Author

For good measure:

SOLVED!

build the container "by hand" - using docker build --platform linux/x86_64 and then stick the same platform argument into the docker-compose.yml (I suspect once there is an image you don't need to build it by hand anymore - how all the finer print reads is sadly beyond me) making the [important parts of the ] docker-compose.yml look like this:

#
# Most if not all of it is a blatant c/p from
# Will Schenk's https://willschenk.com/articles/2020/rails_in_docker/
#
version: "3.9"
services:
...8<...
  mindling:
    platform: linux/x86_64
    build: .
    command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
    volumes:
      - ./src:/app
    ports:
      - "3000:3000"
    depends_on:
      - db

@paulodeon
Copy link

I ran into the same problem and the above didnt work for me (perhaps I didnt follow all the steps)

Specifically I get the error ERROR: tailwindcss-rails does not support the aarch64-linux platform on M1 Mac running tailwind in an alpine docker container using the rails command bin/rails tailwindcss:watch

Digging into this gems code we can see it compares the platform with the matching executable

irb(main):001:0> Gem::Platform.match('aarch64-linux')
=> false
irb(main):002:0> Gem.platforms
=> ["ruby", #<Gem::Platform:0x0000ffff94611888 @cpu="aarch64", @os="linux", @version="musl">]

It seems that the musl causes a mismatch - this is the alpine stdlib and there is a ticket here which purports to fix it but does not: rubygems/rubygems#5852

My fix was to bypass the rails command and run the executable directly using something like this:

/usr/local/bundle/gems/tailwindcss-rails-2.0.12-aarch64-linux/exe/aarch64-linux/tailwindcss -i /app/app/assets/stylesheets/application.tailwind.css -o /app/app/assets/builds/tailwind.css -c /app/config/tailwind.config.js --minify -w

@unikitty37
Copy link

I still can't get it working, and I'm very confused by the above. If my architecture is ARM, why do I want to force it to install x86_64 binaries?

Won't that end up running everything more slowly, under Rosetta 2 (and breaking completely when Apple discontinues that)?

@flavorjones
Copy link
Member

Please make sure you're on the most recent version of Bundler. If you're still having problems, please open a new issue and we can dig in together.

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

5 participants