Go Deploy Gone Wrong

Hey all, need a sanity check on a failing deploy. I am able to build and run my app locally just fine with my Dockerfile but it fails when I attempt to deploy on Railway. Interestingly, I have used the exact same project structure and Dockerfile to deploy an app to Railway before too.
28 Replies
Percy
Percy15mo ago
Project ID: 3a924444-5f7c-477b-a993-438ff0417e6d
BagelsForTuesday
BagelsForTuesdayOP15mo ago
3a924444-5f7c-477b-a993-438ff0417e6d service id: f4b778dc-aa7e-4d96-acf0-53e538f72d79
Brody
Brody15mo ago
what a title lol send the dockerfile please? would you mind wrapping that in triple backticks
BagelsForTuesday
BagelsForTuesdayOP15mo ago
ofc...
# Use the specific Go 1.20 image as the base image
FROM golang:1.20

# Set the working directory inside the container
WORKDIR /app

# Copy the Go module files to the working directory
COPY go.mod go.sum ./

# Download the Go module dependencies
RUN go mod download

# Copy the rest of the application source code to the working directory
COPY . .

# Build the Go application
RUN go build -o colosseum ./internal/cmd/colosseum

# Set the port number that the container should expose
ENV PORT 8080

# Expose the port on which the application will listen
EXPOSE $PORT

# Set the command to run when the container starts
CMD ["./colosseum"]
# Use the specific Go 1.20 image as the base image
FROM golang:1.20

# Set the working directory inside the container
WORKDIR /app

# Copy the Go module files to the working directory
COPY go.mod go.sum ./

# Download the Go module dependencies
RUN go mod download

# Copy the rest of the application source code to the working directory
COPY . .

# Build the Go application
RUN go build -o colosseum ./internal/cmd/colosseum

# Set the port number that the container should expose
ENV PORT 8080

# Expose the port on which the application will listen
EXPOSE $PORT

# Set the command to run when the container starts
CMD ["./colosseum"]
Brody
Brody15mo ago
yeah that looks like a perfectly good dockerfile, very similar to the one I use, what exactly is failing?
BagelsForTuesday
BagelsForTuesdayOP15mo ago
[6/6] RUN go build -o colosseum ./internal/cmd/colosseum:

0.294 stat /app/internal/cmd/colosseum: directory not found

-----
[6/6] RUN go build -o colosseum ./internal/cmd/colosseum:

0.294 stat /app/internal/cmd/colosseum: directory not found

-----
Brody
Brody15mo ago
wanna try ./... instead of that path?
BagelsForTuesday
BagelsForTuesdayOP15mo ago
to clarify
RUN go build -o colosseum ./...
RUN go build -o colosseum ./...
?
Brody
Brody15mo ago
yep
BagelsForTuesday
BagelsForTuesdayOP15mo ago
hmmm
#9 [5/6] COPY . .
#9 DONE 0.0s

#10 [6/6] RUN go build -o colosseum ./...

#10 0.698 go: cannot write multiple packages to non-directory colosseum

#10 ERROR: process "/bin/sh -c go build -o colosseum ./..." did not complete successfully: exit code: 1
#9 [5/6] COPY . .
#9 DONE 0.0s

#10 [6/6] RUN go build -o colosseum ./...

#10 0.698 go: cannot write multiple packages to non-directory colosseum

#10 ERROR: process "/bin/sh -c go build -o colosseum ./..." did not complete successfully: exit code: 1
yeah its a weird one
Brody
Brody15mo ago
I'm hmmm'ing too
BagelsForTuesday
BagelsForTuesdayOP15mo ago
appreciate the quick response, FWIW, I have tried things like deleting the project/service in case there was some weird caching of the context etc but no luck
Brody
Brody15mo ago
would you mind sharing your repo? or maybe a minimal reproducible example repo?
BagelsForTuesday
BagelsForTuesdayOP15mo ago
I wouldn't be able to share the repo but I can promise that the structure is correct
e.g:

├── internal

│   ├── cmd
│   │   └── colosseum
│   │   └── main.go
e.g:

├── internal

│   ├── cmd
│   │   └── colosseum
│   │   └── main.go
Brody
Brody15mo ago
maybe it's because you have a folder named colosseum and are trying to output the binary as colosseum too change the output bin to just app or something
BagelsForTuesday
BagelsForTuesdayOP15mo ago
🤞 Dang, I tried ls -la /app/internal/cmd && ls -la /app/internal/cmd/colosseum inside the Dockerfile and somehow that dir is actually not there, super weird but nothing in the dockerignore and works just fine locally...
Brody
Brody15mo ago
I'm not just saying this, but that was my first thought, I really don't know why I didn't say anything also, why dockerignore instead of just a .gitignore, do you have things you want in the repo and not in the image?
BagelsForTuesday
BagelsForTuesdayOP15mo ago
I was using the railway cli to test, does that also ignore .gitignore when building? (wasn't sure) but I see your point, but just for sanity, I removed both but the issue remains
Brody
Brody15mo ago
the cli will omit tarballing files/folders based on rules in either a .gitignore or a .railwayignore file
BagelsForTuesday
BagelsForTuesdayOP15mo ago
ah nice, good to know
Brody
Brody15mo ago
I know you've shown me a tree, but if you'd provide me with a repo that has a minimal reproducible example, id be happy to debug it myself too
BagelsForTuesday
BagelsForTuesdayOP15mo ago
Will do, let me try and put something together!
Brody
Brody15mo ago
sounds good
BagelsForTuesday
BagelsForTuesdayOP15mo ago
of course the repro attempt actually works RIP
Brody
Brody15mo ago
lmao make it not work
BagelsForTuesday
BagelsForTuesdayOP15mo ago
Alright will take some time to chew on this and see if I can see whats up, I'll be sure to update you on here if I do figure it out or if I don't Once again, appreciate your help so far
Brody
Brody15mo ago
sounds good 🙂
Want results from more Discord servers?
Add your server