Deploying Golang web server along side static site

I am trying to deploy a Go app. I’ve look through the guides and some questions here but I’m still stuck. I’m likely missing something relatively simple, but I need help from the community.

I have a Go project with the following basic folder structure

project/
--api
--- main.go
--- routes.go
--- handlers.go
--- helpers.go
--docs
--- Hugo Project with static site built to 'public' folder
go.mod
go.sum
Dockerfile

I keep running into an error with Docker saying there are no .go files.
Here is what I have for Dockerfile. What am I missing/doing wrong?

FROM golang:1.20

WORKDIR /app

COPY go.mod ./
COPY go.sum ./

RUN go mod download

COPY /api ./
# COPY /docs/public ./

RUN go build -v -o ../project

CMD [ "./project" ]

Okay, I got this figured out. I updated my Dockerfile to this:

FROM golang:1.20

WORKDIR /app
ADD . /api
ADD . /docs

COPY go.mod .
COPY go.sum .

RUN go mod download

COPY ./api ./api
COPY ./docs ./docs
RUN ls /app
# COPY /docs/ .

RUN go build -v -o ./project ./api


CMD [ "./project" ]

If you have a .gitignore or .dockerignore file, that might be the cause. The only other thing I can think of is working directory.


Edit, oh you figured it out. Nice.

1 Like