Golang compiling in a linux machine not connected to the internet

270 Views Asked by At

We have a CI/CD server that is not connected to the Internet due to company policy.

I want to run Unit Tests in this server.

I am allowed to WinScp files to it. To get it working, I thought I will FTP all the files from my source Windows machine where the compilation works, essentially copying over all the files from the GOPATH directory.

But I still get errors, for example I actually have this file /export/home/teamcity/go/src/github.com/jinzhu/[email protected]

Gopath set [17:40:40][Step 1/1] GOPATH="/export/home/teamcity/go"

However the CI/CD build gives this error

[Step 1/1] go: github.com/jinzhu/[email protected]: git fetch -f https://github.com/jinzhu/copier refs/heads/:refs/heads/ refs/tags/:refs/tags/ in /export/home/teamcity/go/pkg/mod/cache/vcs/556feec929544a421f03ed1922f1d1bfffe10a3eaaf694889bbdbe940ff02899: exit status 128: [17:40:41] [Step 1/1] fatal: unable to access 'https://github.com/jinzhu/copier/': Could not resolve host: github.com; Name or service not known

Has anyone has experience of Compiling Golang code in a server that has No Connection to the Internet?

1

There are 1 best solutions below

0
HaiTH On

You should take a look at the official document of go modules to understand how it work.

In your case, just download all dependencies first:

go mod download

Then copy all dependencies into your project:

go mod vendor

After that, shipping this vendor with your code. It includes all packages needed to build on your server.

go build -mod vendor