1

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/copier@v0.0.0-20190924061706-b57f9002281a

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/copier@v0.0.0-20190924061706-b57f9002281a: 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?

Doyyan
  • 125
  • 1
  • 9
  • 2
    `GOPATH` is expiclity replaced by Go modules; the two do not coexist. Are you sure you fully understand what you're doing? Are you sure you have read [this](https://blog.golang.org/using-go-modules)? – kostix Mar 23 '21 at 18:06

1 Answers1

0

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
HaiTH
  • 925
  • 9
  • 9