Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use downloaded Go modules in an offline environment

We are working in an air-gapped environment, and we need to be able to upload, download and use Go modules within our air-gapped environment. How should we setup our Artifactory repo? Do we need to use our GitLab instance to host our Go modules, and if so how should we configure it to be able to use it?

Current situation

We have an Artifactory server deployed locally as well as a hosted GitLab instance. Our development machines have network access to both via HTTPS.

What we tried

We downloaded modules on a machine with internet access using go get <module_name> command, and then uploaded the modules to a Go repo on Artifactory. Then, on our machines we set GOPROXY to the Artifactory URL as stated in the "Set me up" section of the Artifactory Go repo. Upon running go get <module_name>, we get a 404 error.

like image 658
quenting Avatar asked Dec 29 '25 09:12

quenting


1 Answers

I recommend using Athens

On the machine with internet connection set up Athens using docker.

https://docs.gomods.io/

The easiest option is to use the disk storage type (which you can later move to the air gaped machine)

by default Athens is configured to pull new modules that are not in its storage.

after setting up Athens

run go get like so:

export GOPROXY=http://localhost:3000 && go get github.com/gin-gonic/gin

the setup on the air gaped machine is almost identical

just make sure to set this env variable

ATHENS_NETWORK_MODE=offline

which tells Athens to only use modules in it storage

services:
  athens:
    volumes:
      - <local path>:/var/lib/athens
    environment:
      - ATHENS_DISK_STORAGE_ROOT=/var/lib/athens
      - ATHENS_STORAGE_TYPE=disk
      - ATHENS_NETWORK_MODE=offline
      - ATHENS_DOWNLOAD_MODE=none
    container_name: athens-proxy
    restart: always
    expose:
      - 3000:3000
    image: gomods/athens:latest

In your development machines edit the go config file and change GOPROXY to the the URL of your Athens instance.

like image 185
Yakir Oren Avatar answered Jan 01 '26 03:01

Yakir Oren



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!