moonrepo / moon

A build system and monorepo management tool for the web ecosystem, written in Rust.
https://moonrepo.dev/moon
MIT License
2.93k stars 161 forks source link

[bug] panic when running `moon docker setup` in Dockerfile #1700

Open CluEleSsUK opened 1 month ago

CluEleSsUK commented 1 month ago

Describe the bug

I generated a dockerfile using moon docker file <project>. Building the resulting dockerfile panics

Steps to reproduce

  1. moon docker setup projectName
  2. docker build -f path/to/Dockerfile .

Expected behavior

dockerfile builds

Screenshots

[+] Building 72.7s (12/17)                                                                                                                                                                                                                                                                    docker:desktop-linux
 => [internal] load build definition from Dockerfile                                                                                                                                                                                                                                                          0.0s
 => => transferring dockerfile: 1.06kB                                                                                                                                                                                                                                                                        0.0s
 => [internal] load metadata for node:latest                                                                                                                                                                                                                0.0s
 => [internal] load .dockerignore                                                                                                                                                                                                                                                                             0.0s
 => => transferring context: 2B                                                                                                                                                                                                                                                                               0.0s
 => [internal] load build context                                                                                                                                                                                                                                                                            39.7s
 => => transferring context: 6.93GB                                                                                                                                                                                                                                                                          39.0s
 => [base 1/3] FROM node:latest                                                                                                                                                                                                                              0.0s
 => CACHED [base 2/3] WORKDIR /app                                                                                                                                                                                                                                                                            0.0s
 => [base 3/3] RUN curl -fsSL https://moonrepo.dev/install/moon.sh | bash                                                                                                                                                                                                                                     2.3s
 => [skeleton 1/2] COPY . .                                                                                                                                                                                                                                                                                  23.8s 
 => [skeleton 2/2] RUN moon docker scaffold hose                                                                                                                                                                                                                                                              7.5s 
 => [build 1/6] COPY --from=skeleton /root/.proto /root/.proto                                                                                                                                                                                                                                                0.4s 
 => [build 2/6] COPY --from=skeleton /app/.moon/docker/workspace .                                                                                                                                                                                                                                            0.0s 
 => ERROR [build 3/6] RUN moon docker setup                                                                                                                                                                                                                                                                   1.0s 
------                                                                                                                                                                                                                                                                                                             
 > [build 3/6] RUN moon docker setup:
1.016 Error:   × Main thread panicked.
1.016   ├─▶ at /app/crates/action-pipeline/src/action_pipeline.rs:140:38
1.016   ╰─▶ mpsc bounded channel requires buffer > 0
1.016   help: set the `RUST_BACKTRACE=1` environment variable to display a
1.016         backtrace.
1.016 
1.021 Aborted
------
Dockerfile:32

Environment

  System:
    OS: macOS 14.5
    CPU: (10) arm64 Apple M1 Max
    Memory: 67.66 MB / 32.00 GB
    Shell: 3.7.1 - /usr/local/bin/fish
  Binaries:
    Node: 22.3.0 - ~/.nvm/versions/node/v22.3.0/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v22.3.0/bin/yarn
    npm: 10.8.1 - ~/.nvm/versions/node/v22.3.0/bin/npm

Additional context

CluEleSsUK commented 1 month ago

The generated dockerfile looks like so:

#### Installs moon.

FROM  node:latest AS base
WORKDIR /app

# Install moon binary
RUN curl -fsSL https://moonrepo.dev/install/moon.sh | bash
ENV PATH="/root/.moon/bin:$PATH"

#### SKELETON STAGE
#### Scaffolds repository skeleton structures.

FROM base AS skeleton

# Copy entire repository and scaffold
COPY . .
RUN moon docker scaffold hose

#### BUILD STAGE
#### Builds the project.

FROM base AS build

# Copy toolchain
COPY --from=skeleton /root/.proto /root/.proto

# Copy workspace configs
COPY --from=skeleton /app/.moon/docker/workspace .

# Install dependencies
RUN moon docker setup

# Copy project sources
COPY --from=skeleton /app/.moon/docker/sources .

# Build the project
RUN moon run hose:build

# Prune extraneous dependencies
RUN moon docker prune

#### START STAGE
#### Runs the project.

FROM base AS start

# Copy built sources
COPY --from=build /root/.proto /root/.proto
COPY --from=build /app /app

ENTRYPOINT node /app/index.js

I added the last ENTRYPOINT, but that shouldn't change anything

CluEleSsUK commented 1 month ago

fwiw I have also tried npm install -g @moonrepo/cli instead of the curl->bash, but that gives me

 > [build 5/6] RUN moon run hose:build:
0.213 Error: project::task::unknown
0.213 
0.213   × Unknown task build for project hose.
0.213   help: Has this task been configured?
0.213 

This task runs no problem outside docker

milesj commented 1 month ago

Yeah that panic basically means there are no actions in the pipeline: https://github.com/moonrepo/moon/blob/master/crates/action-pipeline/src/action_pipeline.rs#L140

Something isn't right in the Dockerfile. Seems like critical config files are missing.

If you run moon docker scaffold outside of docker, does the shape of .moon/docker look correct?

CluEleSsUK commented 1 month ago

hmm it does not, it contains my package.json, moon.yml, tsconfig.json and .gitignore (but no source directories). This sort of aligns with the build task except the glob:

language: 'typescript'

tasks:
  build:
    command: 'npm run build'
    inputs:
      - 'src/**/*'
      - 'tsconfig.json'
      - 'package.json'
    outputs:
      - 'index.js'
CluEleSsUK commented 1 month ago

ah sorry, the source dir is under .moon/docker/sources/$project 🤡

milesj commented 1 month ago

Can you pass --log trace to moon docker setup and then paste the logs?

Also, .dockerignore looks fine yeah?