Reputation: 341
I have two private GitLab repositories: webserver and helper, both written in Golang.
The webserver/main.go is as simple as this:
package main
import (
"net/http"
"github.com/labstack/echo/v4"
"gitlab.com/randomname/helper"
)
func main() {
e := echo.New()
e.GET("/greet", func(c echo.Context) error {
greet := helper.Greetings()
return c.String(http.StatusOK, greet)
})
e.Logger.Fatal(e.Start(":1323"))
}
The helper repository contains a single file: helper/helper.go
package helper
func Greetings() string {
return "Halo, how are you?"
}
I can run this locally without any issues using the replace directive in the go.mod file. I’ve also successfully set up SSH keys on my GitLab account for pulling and pushing the repositories.
When I try to run this service locally using Docker, I encounter issues. Below is the Dockerfile I use in the webserver repository:
FROM golang:1.23-alpine AS builder
ENV GOPRIVATE="gitlab.com/randomname/*" GO111MODULE=on CGO_ENABLED=0 GOOS=linux GOARCH=amd64
RUN apk --no-cache add ca-certificates git openssh
RUN mkdir /root/.ssh/
RUN echo "${SSH_PRIVATEKEY}" > /root/.ssh/id_rsa
RUN chmod 600 /root/.ssh/id_rsa
RUN touch /root/.ssh/known_hosts
RUN ssh-keyscan gitlab.com >> /root/.ssh/id_rsa
RUN git config --global [email protected]:.insteadOf https://gitlab.com/
WORKDIR /build
COPY go.mod .
COPY go.sum .
RUN go mod download
COPY . .
RUN go build -o webserver
FROM alpine:3.12
WORKDIR /app
COPY --from=builder /build/webserver /app/
cmd ["./webserver"]
I run the service using the following docker-compose.yml file:
services:
webserver:
build:
context: ../webserver
dockerfile: Dockerfile
args:
SSH_PRIVATEKEY: ${SSH_PRIVATEKEY}
ports:
- "8000:1323"
The error when I run docker compose up --build
is like
=> ERROR [webserver builder 12/14] RUN go mod download
1.561 Host key verification failed.
1.561 fatal: Could not read from remote repository.
1.561
1.561 Please make sure you have the correct access rights
1.561 and the repository exists.
I have similar setup on MacOS and it works fine. However, when I try running it on Windows I got the problem. I already tried both via WSL and the Windows itself and the result still same.
Does anyone have suggestions for troubleshooting this issue or making it work on Windows?
Upvotes: 0
Views: 31