mint-lang / mint

:leaves: A refreshing programming language for the front-end web.
https://mint-lang.com
BSD 3-Clause "New" or "Revised" License
4.06k stars 141 forks source link

Failed building Mint on Docker on macOS Big Sur - M1 Apple Silicon #391

Closed controlade closed 2 years ago

controlade commented 3 years ago

After doing:

git clone https://github.com/mint-lang/mint-docker.git
cd mint-docker
docker-compose up

Using Docker Desktop preview 3.3 on macOS BigSur, Apple Silicon M1:

$ docker-compose up
Docker Compose is now in the Docker CLI, try `docker compose up`

Building mint
[+] Building 24.5s (14/18)                                                                                                        
 => [internal] load build definition from Dockerfile.alpine                                                                  0.0s
 => => transferring dockerfile: 44B                                                                                          0.0s
 => [internal] load .dockerignore                                                                                            0.0s
 => => transferring context: 34B                                                                                             0.0s
 => [internal] load metadata for docker.io/library/alpine:latest                                                             1.9s
 => [internal] load metadata for docker.io/crystallang/crystal:1.0.0-alpine                                                  1.9s
 => [auth] library/alpine:pull token for registry-1.docker.io                                                                0.0s
 => [auth] crystallang/crystal:pull token for registry-1.docker.io                                                           0.0s
 => [build 1/6] FROM docker.io/crystallang/crystal:1.0.0-alpine@sha256:c9b59f80f6b3821596f45494cd56c3b08048067e18ff0b12c268  0.0s
 => [stage-1 1/5] FROM docker.io/library/alpine@sha256:ec14c7992a97fc11425907e908340c6c3d6ff602f5f13d899e6b7027c9b4133a      0.0s
 => [internal] load build context                                                                                            0.0s
 => => transferring context: 58B                                                                                             0.0s
 => CACHED [stage-1 2/5] RUN mkdir -p /opt/mint                                                                              0.0s
 => CACHED [build 2/6] RUN mkdir -p /opt/build                                                                               0.0s
 => CACHED [build 3/6] WORKDIR /opt/build                                                                                    0.0s
 => CACHED [build 4/6] RUN git clone https://github.com/mint-lang/mint.git .                                                 0.0s
 => ERROR [build 5/6] RUN shards install --ignore-crystal-version                                                           22.6s
------                                                                                                                            
 > [build 5/6] RUN shards install --ignore-crystal-version:                                                                       
#13 0.263 Resolving dependencies                                                                                                  
#13 0.263 Fetching https://github.com/mosop/string_inflection.git                                                                 
#13 2.242 Fetching https://github.com/schovi/baked_file_system.git                                                                
#13 3.512 Fetching https://github.com/kemalcr/kemal.git                                                                           
#13 5.799 Fetching https://github.com/luislavena/radix.git
#13 6.897 Fetching https://github.com/jeromegn/kilt.git
#13 7.883 Fetching https://github.com/crystal-loot/exception_page.git
#13 9.017 Fetching https://github.com/jwaldrip/admiral.cr.git
#13 10.28 Fetching https://github.com/gdotdesign/tree_template.git
#13 11.71 Fetching https://github.com/vladfaust/time_format.cr.git
#13 12.76 Fetching https://github.com/gdotdesign/cr-dotenv.git
#13 13.85 Fetching https://github.com/icyleaf/markd.git
#13 15.19 Fetching https://github.com/crystal-ameba/ameba.git
#13 17.69 Fetching https://github.com/makenowjust/crystal-diff.git
#13 21.19 Installing string_inflection (0.2.1)
#13 21.24 Installing baked_file_system (0.9.8 at 7183bfd)
#13 21.28 Installing radix (0.3.9)
#13 21.31 Installing kilt (0.4.0)
#13 21.35 Installing exception_page (0.1.4)
#13 21.39 Installing kemal (0.27.0)
#13 21.44 Installing admiral (1.11.2)
#13 21.48 Installing tree_template (0.1.0 at 7e24c92)
#13 21.54 Installing time_format (0.1.1)
#13 21.57 Installing dotenv (0.3.1)
#13 21.61 Installing markd (0.4.0)
#13 21.65 Installing ameba (0.14.0)
#13 21.71 Postinstall of ameba: make bin && make run_file
#13 22.52 Failed postinstall of ameba on make bin && make run_file:
#13 22.52 /usr/bin/shards build 
#13 22.52 Dependencies are satisfied
#13 22.52 Building: ameba
#13 22.52 Error target ameba failed to compile:
#13 22.52 GC Warning: Failed to expand heap by 1175552 bytes
#13 22.52 GC Warning: Failed to expand heap by 1261568 bytes
#13 22.52 GC Warning: Failed to expand heap by 1347584 bytes
#13 22.52 GC Warning: Failed to expand heap by 262144 bytes
#13 22.52 GC Warning: Out of Memory! Heap size: 3 MiB. Returning NULL!
#13 22.52 Invalid memory access (signal 11) at address 0xd8
#13 22.52 [0x4000c5ebf6] ???
#13 22.52 [0x4000badab2] ???
#13 22.52 [0x4001bf5e0f] ???
#13 22.52 
#13 22.52 make: *** [Makefile:8: bin/ameba] Error 1
------
executor failed running [/bin/sh -c shards install --ignore-crystal-version]: exit code: 1
ERROR: Service 'mint' failed to build

Cannot find any reference on internet about ameba.

Anyone with a hint on what to do?

I know alternative is to compile source on the machine, but preferred method is to virtualize and homologate local environment (several for multiple developers) and against cloud environments.

nailuj29 commented 3 years ago

according to the error,

Docker Compose is now in the Docker CLI, try docker compose up

What happens when you run that? Edit: I misread the error, sorry

controlade commented 3 years ago

according to the error,

Docker Compose is now in the Docker CLI, try docker compose up

What happens when you run that? Edit: I misread the error, sorry

No problem @nailuj29gaming , thanks for replying.

For documentation purposes, here the log when using docker compose up

$ docker compose up
[+] Building 22.2s (12/16)                                                                                                        
 => [internal] load build definition from Dockerfile.alpine                                                                  0.0s
 => => transferring dockerfile: 39B                                                                                          0.0s
 => [internal] load .dockerignore                                                                                            0.0s
 => => transferring context: 34B                                                                                             0.0s
 => [internal] load metadata for docker.io/library/alpine:latest                                                             1.1s
 => [internal] load metadata for docker.io/crystallang/crystal:1.0.0-alpine                                                  1.1s
 => [internal] load build context                                                                                            0.0s
 => => transferring context: 58B                                                                                             0.0s
 => [build 1/6] FROM docker.io/crystallang/crystal:1.0.0-alpine@sha256:c9b59f80f6b3821596f45494cd56c3b08048067e18ff0b12c268  0.0s
 => [stage-1 1/5] FROM docker.io/library/alpine@sha256:ec14c7992a97fc11425907e908340c6c3d6ff602f5f13d899e6b7027c9b4133a      0.0s
 => CACHED [stage-1 2/5] RUN mkdir -p /opt/mint                                                                              0.0s
 => CACHED [build 2/6] RUN mkdir -p /opt/build                                                                               0.0s
 => CACHED [build 3/6] WORKDIR /opt/build                                                                                    0.0s
 => CACHED [build 4/6] RUN git clone https://github.com/mint-lang/mint.git .                                                 0.0s
 => ERROR [build 5/6] RUN shards install --ignore-crystal-version                                                           21.0s
------                                                                                                                            
 > [build 5/6] RUN shards install --ignore-crystal-version:                                                                       
#11 0.203 Resolving dependencies                                                                                                  
#11 0.203 Fetching https://github.com/mosop/string_inflection.git                                                                 
#11 1.641 Fetching https://github.com/schovi/baked_file_system.git                                                                
#11 2.752 Fetching https://github.com/kemalcr/kemal.git                                                                           
#11 4.403 Fetching https://github.com/luislavena/radix.git
#11 5.551 Fetching https://github.com/jeromegn/kilt.git
#11 6.681 Fetching https://github.com/crystal-loot/exception_page.git
#11 7.802 Fetching https://github.com/jwaldrip/admiral.cr.git
#11 9.165 Fetching https://github.com/gdotdesign/tree_template.git
#11 10.57 Fetching https://github.com/vladfaust/time_format.cr.git
#11 11.60 Fetching https://github.com/gdotdesign/cr-dotenv.git
#11 12.66 Fetching https://github.com/icyleaf/markd.git
#11 14.07 Fetching https://github.com/crystal-ameba/ameba.git
#11 16.53 Fetching https://github.com/makenowjust/crystal-diff.git
#11 19.78 Installing string_inflection (0.2.1)
#11 19.83 Installing baked_file_system (0.9.8 at 7183bfd)
#11 19.87 Installing radix (0.3.9)
#11 19.91 Installing kilt (0.4.0)
#11 19.94 Installing exception_page (0.1.4)
#11 19.98 Installing kemal (0.27.0)
#11 20.03 Installing admiral (1.11.2)
#11 20.07 Installing tree_template (0.1.0 at 7e24c92)
#11 20.13 Installing time_format (0.1.1)
#11 20.17 Installing dotenv (0.3.1)
#11 20.21 Installing markd (0.4.0)
#11 20.25 Installing ameba (0.14.0)
#11 20.30 Postinstall of ameba: make bin && make run_file
#11 20.94 Failed postinstall of ameba on make bin && make run_file:
#11 20.94 /usr/bin/shards build 
#11 20.94 Dependencies are satisfied
#11 20.94 Building: ameba
#11 20.94 Error target ameba failed to compile:
#11 20.94 GC Warning: Failed to expand heap by 1175552 bytes
#11 20.94 GC Warning: Failed to expand heap by 1261568 bytes
#11 20.94 GC Warning: Failed to expand heap by 1347584 bytes
#11 20.94 GC Warning: Failed to expand heap by 262144 bytes
#11 20.94 GC Warning: Out of Memory! Heap size: 3 MiB. Returning NULL!
#11 20.94 Invalid memory access (signal 11) at address 0xd8
#11 20.94 [0x4000c5ebf6] ???
#11 20.94 [0x4000badab2] ???
#11 20.94 [0x4001bf5e0f] ???
#11 20.94 
#11 20.94 make: *** [Makefile:8: bin/ameba] Error 1
------
The new 'docker compose' command is currently experimental. To provide feedback or request new features please open issues at https://github.com/docker/compose-cli
failed to solve: rpc error: code = Unknown desc = executor failed running [/bin/sh -c shards install --ignore-crystal-version]: exit code: 1
gdotdesign commented 3 years ago

It seems that the container runs out of memory, you can try adding mem_reservation: 512m, mem_limit: 1000000000 and memswap_limit: 2000000000 to the docker-compose.yml file, more information is here https://docs.docker.com/compose/compose-file/compose-file-v2/#cpu-and-other-resources

controlade commented 3 years ago

It seems that the container runs out of memory, you can try adding mem_reservation: 512m, mem_limit: 1000000000 and memswap_limit: 2000000000 to the docker-compose.yml file, more information is here https://docs.docker.com/compose/compose-file/compose-file-v2/#cpu-and-other-resources

Thanks for replying @gdotdesign

Result is the same after updating and running docker-compose.yml:

version: "2.4"
services:
  mint:
    image: mint
    build:
      context: ./
      dockerfile: Dockerfile.alpine
    volumes:
      - ./workspace:/opt/mint
    working_dir: /opt/mint
    command: start --host 0.0.0.0
    ports:
      - 3000:3000
    mem_limit: 1000000000
    memswap_limit: 2000000000
    mem_reservation: 1024m
    privileged: true

Any other recommendation?

gdotdesign commented 3 years ago

I've pushed the tag latest to https://hub.docker.com/r/mintlang/mint/tags?page=1&ordering=last_updated you can probably use that for now.

I'll integrate pushing docker to the CI soon.

controlade commented 3 years ago

I've pushed the tag latest to https://hub.docker.com/r/mintlang/mint/tags?page=1&ordering=last_updated you can probably use that for now.

I'll integrate pushing docker to the CI soon.

Hi @gdotdesign thanks for replying.

Here my feedback:

Result

$ docker compose up
[+] Running 1/0
 ⠿ Container mint-docker_mint_1  Recreated                                                                                                                              0.1s
Attaching to mint-docker_mint_1
mint_1  | Mint - Running the development server
mint_1  | ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
mint_1  | ⚙ Ensuring dependencies... 5.871ms
⚙ Parsing files... 56.374ms0 / 1
mint_1  | GC Warning: Failed to expand heap by 1187840 bytes
mint_1  | GC Warning: Failed to expand heap by 1212416 bytes
mint_1  | GC Warning: Failed to expand heap by 1232896 bytes
mint_1  | GC Warning: Failed to expand heap by 1220608 bytes
mint_1  | GC Warning: Failed to expand heap by 1277952 bytes
mint_1  | GC Warning: Failed to expand heap by 1396736 bytes
mint_1  | GC Warning: Failed to expand heap by 135168 bytes
mint_1  | GC Warning: Out of Memory! Heap size: 3 MiB. Returning NULL!
mint_1  | GC Warning: Failed to expand heap by 1396736 bytes
mint_1  | GC Warning: Failed to expand heap by 135168 bytes
mint_1  | GC Warning: Out of Memory! Heap size: 3 MiB. Returning NULL!
mint_1  | Invalid memory access (signal 11) at address 0x0
mint_1  | [0x400057b6d6] ???
mint_1  | [0x40002033f8] ???
mint_1  | [0x40007effea] ???
mint_1  | [0x4000807546] ???
mint-docker_mint_1 exited with code 11

Changes applied before launching ( docker-compose up )

#FROM crystallang/crystal:1.0.0-alpine AS build
FROM mintlang/mint:latest

#RUN mkdir -p /opt/build
#WORKDIR /opt/build
#RUN git clone https://github.com/mint-lang/mint.git .
#RUN shards install --ignore-crystal-version
#RUN crystal build src/mint.cr -o mint --static --release --no-debug

#FROM alpine
#RUN mkdir -p /opt/mint
#COPY --from=build /opt/build/mint /bin/mint
#COPY ./bin/entrypoint /bin/entrypoint

WORKDIR /opt/mint
ENTRYPOINT [ "/bin/entrypoint" ]
CMD [ "start" ]

I tested both, with and without memory configuration on docker-compose.yml file

image

gdotdesign commented 3 years ago

It's some kind of memory issue related to Docker itself, unfortunately I'm not that versed in Docker, maybe asking in one of their forum channels would lead to a solution.

controlade commented 3 years ago

It's some kind of memory issue related to Docker itself, unfortunately I'm not that versed in Docker, maybe asking in one of their forum channels would lead to a solution.

Thank you @gdotdesign One final question: had you seen the same issue with memory before?

I am thinking that it could be due to Docker Desktop for macbook M1 chip is still under development by the Docker team, and the problem could be in a lower layer, not the image or the mint level.

gdotdesign commented 3 years ago

It's some kind of memory issue related to Docker itself, unfortunately I'm not that versed in Docker, maybe asking in one of their forum channels would lead to a solution.

Thank you @gdotdesign One final question: had you seen the same issue with memory before?

I am thinking that it could be due to Docker Desktop for macbook M1 chip is still under development by the Docker team, and the problem could be in a lower layer, not the image or the mint level.

I didn't see it before, my gut tells me that it's an issue with Docker Desktop for macbook M1 chip as you wrote.

MarcusE1W commented 2 years ago

Not 100% sure if I have the same problem, but it looks like quite similar.

Main difference, I am not using docker.

On a Pinebook (aarch64) I get this error after shard install:

git clone ...
cd mint
shards install
mmw@PBP  ~/.local/mint   master  shards install
Resolving dependencies
Fetching https://github.com/schovi/baked_file_system.git
Fetching https://github.com/kemalcr/kemal.git
Fetching https://github.com/luislavena/radix.git
Fetching https://github.com/crystal-loot/exception_page.git
Fetching https://github.com/sija/backtracer.cr.git
Fetching https://github.com/jwaldrip/admiral.cr.git
Fetching https://github.com/gdotdesign/cr-dotenv.git
Fetching https://github.com/icyleaf/markd.git
Fetching https://github.com/crystal-ameba/ameba.git
Installing baked_file_system (0.10.0)
Installing radix (0.4.1)
Installing backtracer (1.2.1)
Installing exception_page (0.2.2)
Installing kemal (1.1.2)
Installing admiral (1.11.5)
Installing dotenv (1.0.0)
Installing markd (0.4.2)
Installing ameba (1.0.0)
Postinstall of ameba: make bin && make run_file
Failed postinstall of ameba on make bin && make run_file:
shards build 
Dependencies are satisfied
Building: ameba
Error target ameba failed to compile:
Showing last frame. Use --error-trace for full trace.

In src/ameba/inline_comments.cr:98:65

 98 | Tokenizer.new(lexer).run { |t| commented = true if t.type.comment? }
                                                                ^-------
Error: undefined method 'comment?' for Symbol

make: *** [Makefile:8: bin/ameba] Error 1

I am not experienced with docker, but error message looks similar and the problematic package appears to be ameba as well.

Let me know if it would be better to have a separate issue.

Any idea how to install into in an ARM Pinebook ?

gdotdesign commented 2 years ago

From the message the issue is with ameba and not the system.

You can remove ameba from the dependencies (shards.yml), since it's for development only.

What crystal version are you using?

Sija commented 2 years ago

@MarcusE1W That's a different issue. It seems you're using an older Crystal version, which is unsupported by the Ameba linter. Try updating Crystal to v1.4.0.

MarcusE1W commented 2 years ago

Thanks. I have used the current one from Archlinux ARM. I have to check you how to update.

Sija commented 2 years ago

@MarcusE1W Since arch linux arm crystal package is one version behind, the best you can do right now is to remove ameba from shard.yml - at least until the package gets updated.

MarcusE1W commented 2 years ago

Happy to report that mint now builds from source (without docker) on my ARM Pinebook Pro. It was really only the wrong crystal version. Sorry to have reported this wrongly in this issue, I thought they are maybe the same.

Sija commented 2 years ago

I'm closing this issue since Crystal and ameba are both m1-compatible now.