If you want to build your go application in a cicd but do not have a connection to the internet on the build-server you need a way to include the depenencies into your git repository.
You can do so by changing your GOPATH
variable.
Go will always download the dependencies into your GOPATH
.
To include them into your git you first have to temporarily change your GOPATH
. To keep things organized I use a directory next to my main.go
file named dependencies
.
# Create new directory
[tux@client]$ mkdir dependencies
# Change your go path relative to your working directory
[tux@client]$ GOPATH=$(pwd)/dependencies
# Download dependencies into your gopath
[tux@client]$ go get .
After that we need to modify our Dockerfile as well.
FROM golang:latest
ENV GOPATH=/app/dependencies
WORKDIR /app
COPY . .
RUN go build
RUN chmod +x app
CMD /app/app
Now push all the files to your git and you should be able to build your Docker Image in an offline environment.
Just remember, if you add new dependencies, to download them into the project.