Golang app: build failed

Hi, everyone Its my first time attemping to deploy to railwayapp and i dont understand why my golang project fails to build. Appreciate any help! 🙂 project: https://github.com/nikita-shtimenko/snippetbox-api
#5 DONE 0.0s



#6 [stage-1 1/5] FROM docker.io/library/ubuntu:jammy@sha256:2b7412e6465c3c7fc5bb21d3e6f1917c167358449fecac8176c6e496e5c1f05f

#6 DONE 0.0s



#7 [internal] load build context

#7 transferring context: 24.52kB done

#7 DONE 0.0s



#8 [stage-0 2/10] WORKDIR /app/

#8 CACHED



#9 [stage-0 3/8] COPY .nixpacks/nixpkgs-5148520bfab61f99fd25fb9ff7bfbb50dad3c9db.nix .nixpacks/nixpkgs-5148520bfab61f99fd25fb9ff7bfbb50dad3c9db.nix

#9 CACHED



#10 [stage-0 4/8] RUN nix-env -if .nixpacks/nixpkgs-5148520bfab61f99fd25fb9ff7bfbb50dad3c9db.nix && nix-collect-garbage -d

#10 CACHED



#11 [stage-0 5/8] COPY . /app/.

#11 DONE 0.0s



#12 [stage-0 6/8] RUN --mount=type=cache,id=s/9d103b90-f62d-425c-b77c-91c33b0e602f-/root/cache/go-build,target=/root/.cache/go-build go mod download



#12 DONE 0.5s





#13 [stage-0 7/8] COPY . /app/.

#13 DONE 0.0s



#14 [stage-0 8/8] RUN --mount=type=cache,id=s/9d103b90-f62d-425c-b77c-91c33b0e602f-/root/cache/go-build,target=/root/.cache/go-build go build -o out



#14 0.341 no Go files in /app

#14 ERROR: process "/bin/bash -ol pipefail -c go build -o out" did not complete successfully: exit code: 1

-----

> [stage-0 8/8] RUN --mount=type=cache,id=s/9d103b90-f62d-425c-b77c-91c33b0e602f-/root/cache/go-build,target=/root/.cache/go-build go build -o out:

0.341 no Go files in /app

-----



Dockerfile:23

-------------------

21 | # build phase

22 | COPY . /app/.

23 | >>> RUN --mount=type=cache,id=s/9d103b90-f62d-425c-b77c-91c33b0e602f-/root/cache/go-build,target=/root/.cache/go-build go build -o out

24 |

25 |

-------------------

ERROR: failed to solve: process "/bin/bash -ol pipefail -c go build -o out" did not complete successfully: exit code: 1



Error: Docker build failed
#5 DONE 0.0s



#6 [stage-1 1/5] FROM docker.io/library/ubuntu:jammy@sha256:2b7412e6465c3c7fc5bb21d3e6f1917c167358449fecac8176c6e496e5c1f05f

#6 DONE 0.0s



#7 [internal] load build context

#7 transferring context: 24.52kB done

#7 DONE 0.0s



#8 [stage-0 2/10] WORKDIR /app/

#8 CACHED



#9 [stage-0 3/8] COPY .nixpacks/nixpkgs-5148520bfab61f99fd25fb9ff7bfbb50dad3c9db.nix .nixpacks/nixpkgs-5148520bfab61f99fd25fb9ff7bfbb50dad3c9db.nix

#9 CACHED



#10 [stage-0 4/8] RUN nix-env -if .nixpacks/nixpkgs-5148520bfab61f99fd25fb9ff7bfbb50dad3c9db.nix && nix-collect-garbage -d

#10 CACHED



#11 [stage-0 5/8] COPY . /app/.

#11 DONE 0.0s



#12 [stage-0 6/8] RUN --mount=type=cache,id=s/9d103b90-f62d-425c-b77c-91c33b0e602f-/root/cache/go-build,target=/root/.cache/go-build go mod download



#12 DONE 0.5s





#13 [stage-0 7/8] COPY . /app/.

#13 DONE 0.0s



#14 [stage-0 8/8] RUN --mount=type=cache,id=s/9d103b90-f62d-425c-b77c-91c33b0e602f-/root/cache/go-build,target=/root/.cache/go-build go build -o out



#14 0.341 no Go files in /app

#14 ERROR: process "/bin/bash -ol pipefail -c go build -o out" did not complete successfully: exit code: 1

-----

> [stage-0 8/8] RUN --mount=type=cache,id=s/9d103b90-f62d-425c-b77c-91c33b0e602f-/root/cache/go-build,target=/root/.cache/go-build go build -o out:

0.341 no Go files in /app

-----



Dockerfile:23

-------------------

21 | # build phase

22 | COPY . /app/.

23 | >>> RUN --mount=type=cache,id=s/9d103b90-f62d-425c-b77c-91c33b0e602f-/root/cache/go-build,target=/root/.cache/go-build go build -o out

24 |

25 |

-------------------

ERROR: failed to solve: process "/bin/bash -ol pipefail -c go build -o out" did not complete successfully: exit code: 1



Error: Docker build failed
GitHub
GitHub - nikita-shtimenko/snippetbox-api
Contribute to nikita-shtimenko/snippetbox-api development by creating an account on GitHub.
Solution:
1. remove the server binary from your repo 2. make sure the server binary is being gitignored 3. in the service settings set the build command to go build ./... 4. in the service settings set the start command to ./server...
Jump to solution
15 Replies
Percy
Percy14mo ago
Project ID: 9d103b90-f62d-425c-b77c-91c33b0e602f,9d103b90-f62d-425c-b77c-91c33b0e602f,9d103b90-f62d-425c-b77c-91c33b0e602f,9d103b90-f62d-425c-b77c-91c33b0e602f
Fragly
Fragly14mo ago
"no Go files in /app", did you specify the main directory?
Nikita Shtimenko
Nikita ShtimenkoOP14mo ago
Heh, no... Where can i do? In the dashboard of the project?
Nikita Shtimenko
Nikita ShtimenkoOP14mo ago
now im getting another errors
No description
Nikita Shtimenko
Nikita ShtimenkoOP14mo ago
#12 1.389 main.go:8:2: no required module provides package github.com/go-sql-driver/mysql: go.mod file not found in current directory or any parent directory; see 'go help modules'

#12 1.389 main.go:9:2: no required module provides package github.com/joho/godotenv: go.mod file not found in current directory or any parent directory; see 'go help modules'

#12 1.389 main.go:10:2: no required module provides package go.uber.org/zap: go.mod file not found in current directory or any parent directory; see 'go help modules'

#12 1.389 main.go:6:2: package snippetbox-api/internal is not in GOROOT (/nix/store/hxvbx812hcd8ci4rcx66ipb958g77gp8-go-1.20.8/share/go/src/snippetbox-api/internal)

#12 ERROR: process "/bin/bash -ol pipefail -c go build -o out main.go" did not complete successfully: exit code: 1

> [stage-0 6/6] RUN --mount=type=cache,id=s/9d103b90-f62d-425c-b77c-91c33b0e602f-/root/cache/go-build,target=/root/.cache/go-build go build -o out main.go:

1.389 main.go:8:2: no required module provides package github.com/go-sql-driver/mysql: go.mod file not found in current directory or any parent directory; see 'go help modules'

1.389 main.go:9:2: no required module provides package github.com/joho/godotenv: go.mod file not found in current directory or any parent directory; see 'go help modules'

1.389 main.go:10:2: no required module provides package go.uber.org/zap: go.mod file not found in current directory or any parent directory; see 'go help modules'

1.389 main.go:6:2: package snippetbox-api/internal is not in GOROOT (/nix/store/hxvbx812hcd8ci4rcx66ipb958g77gp8-go-1.20.8/share/go/src/snippetbox-api/internal)
#12 1.389 main.go:8:2: no required module provides package github.com/go-sql-driver/mysql: go.mod file not found in current directory or any parent directory; see 'go help modules'

#12 1.389 main.go:9:2: no required module provides package github.com/joho/godotenv: go.mod file not found in current directory or any parent directory; see 'go help modules'

#12 1.389 main.go:10:2: no required module provides package go.uber.org/zap: go.mod file not found in current directory or any parent directory; see 'go help modules'

#12 1.389 main.go:6:2: package snippetbox-api/internal is not in GOROOT (/nix/store/hxvbx812hcd8ci4rcx66ipb958g77gp8-go-1.20.8/share/go/src/snippetbox-api/internal)

#12 ERROR: process "/bin/bash -ol pipefail -c go build -o out main.go" did not complete successfully: exit code: 1

> [stage-0 6/6] RUN --mount=type=cache,id=s/9d103b90-f62d-425c-b77c-91c33b0e602f-/root/cache/go-build,target=/root/.cache/go-build go build -o out main.go:

1.389 main.go:8:2: no required module provides package github.com/go-sql-driver/mysql: go.mod file not found in current directory or any parent directory; see 'go help modules'

1.389 main.go:9:2: no required module provides package github.com/joho/godotenv: go.mod file not found in current directory or any parent directory; see 'go help modules'

1.389 main.go:10:2: no required module provides package go.uber.org/zap: go.mod file not found in current directory or any parent directory; see 'go help modules'

1.389 main.go:6:2: package snippetbox-api/internal is not in GOROOT (/nix/store/hxvbx812hcd8ci4rcx66ipb958g77gp8-go-1.20.8/share/go/src/snippetbox-api/internal)
Fragly
Fragly14mo ago
<:mommy_whatthe:970691006557212672> nah, in your dockercompose file I think what's your file structure
Nikita Shtimenko
Nikita ShtimenkoOP14mo ago
no docker mate >_<
Fragly
Fragly14mo ago
Sorry I'm tired 😭
Nikita Shtimenko
Nikita ShtimenkoOP14mo ago
GitHub
GitHub - nikita-shtimenko/snippetbox-api
Contribute to nikita-shtimenko/snippetbox-api development by creating an account on GitHub.
Fragly
Fragly14mo ago
yea I have no idea, seems fine to me
Nikita Shtimenko
Nikita ShtimenkoOP14mo ago
same 😦
Brody
Brody14mo ago
you have your main file in a slightly unorthodox location, most people have their main files in the root of the project, either way, follow these instructions
Solution
Brody
Brody14mo ago
1. remove the server binary from your repo 2. make sure the server binary is being gitignored 3. in the service settings set the build command to go build ./... 4. in the service settings set the start command to ./server
Nikita Shtimenko
Nikita ShtimenkoOP14mo ago
i will try it right now, thanks! It worked! Thank you, appreciate your help and time spent! ❤️
Brody
Brody14mo ago
no problem
Want results from more Discord servers?
Add your server