diff --git a/docker-compose.yml b/docker-compose.yml index f43e15a..c1ddb42 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,4 +4,4 @@ services: web: image: ghcr.io/jurajkubrican/knet/go-web-server:latest ports: - - 5000:5000/tcp + - 54321:54321/tcp diff --git a/dockerfile b/dockerfile index 14c40e9..9f1aea6 100644 --- a/dockerfile +++ b/dockerfile @@ -1,14 +1,30 @@ -# Step 1: Build the Go binary +# Step 1: Build the Go binary in a separate stage +FROM golang:1.23 AS builder + +# Set the working directory +WORKDIR /app + +# Copy the Go module files +COPY go.mod go.sum ./ +RUN go mod download + +# Copy the rest of the application code +COPY . . + +# Build the Go binary with static linking for Linux +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /server src/main.go + + FROM scratch # Set the current working directory inside the container WORKDIR /app -# Copy go.mod and go.sum files -COPY server ./ +COPY . . +COPY --from=builder server ./ # Command to run the executable CMD ["./server"] # Expose the port on which the Go server will run -EXPOSE 80 \ No newline at end of file +EXPOSE 54321 \ No newline at end of file diff --git a/server b/server deleted file mode 100755 index 935c3e4..0000000 Binary files a/server and /dev/null differ diff --git a/src/main.go b/src/main.go index 8d21876..36809be 100644 --- a/src/main.go +++ b/src/main.go @@ -43,5 +43,5 @@ func main() { return c.Render(200, "index", page) }) - e.Logger.Fatal(e.Start(":5000")) + e.Logger.Fatal(e.Start(":54321")) }